zoukankan      html  css  js  c++  java
  • 磁盘分区格式化检验挂载

    .磁盘分区:fdisk

     

    fdisk 【-l】 设备名称

    -l:输出后面接的设备的所有的分区内容。若仅由fdisl -l时,则系统会把整个系统能够找到的设备的分区均列出来

     

    例:

    [root@server3 mnt]# df       *先通过df找出可用磁盘名

    Filesystem     1K-blocks    Used Available Use% Mounted on

    /dev/vda3       20243456 3307500  16935956  17% /

     

     

    [root@server3 mnt]# fdisk  /dev/vda

    Welcome to fdisk (util-linux 2.23.2).

     

    Changes will remain in memory only, until you decide to write them.

    Be careful before using the write command.

     

     

    Command (m for help):            *等待输入

     

    Command (m for help): m          *输入m后,会有下面这些命令介绍

    Command action

       a   toggle a bootable flag

       b   edit bsd disklabel

       c   toggle the dos compatibility flag

       d   delete a partition    *删除一个分区

       g   create a new empty GPT partition table

       G   create an IRIX (SGI) partition table

       l   list known partition types

       m   print this menu

       n   add a new partition       *新增一个分区

       o   create a new empty DOS partition table

       p   print the partition table *显示分区表

       q   quit without saving changes   *不存储,直接离开fdisk程序

       s   create a new empty Sun disklabel

       t   change a partition's system id

       u   change display/entry units

       v   verify the partition table

       w   write table to disk and exit  *将之前的操作写入分区表

       x   extra functionality (experts only)

     

     

    Command (m for help): p          *查看目前磁盘状态

     

    Disk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 sectors  *磁盘文件名与容量

    Units = sectors of 1 * 512 = 512 bytes   *每个柱面的大小

    Sector size (logical/physical): 512 bytes / 512 bytes

    I/O size (minimum/optimal): 512 bytes / 512 bytes

    Disk label type: dos

    Disk identifier: 0x000cce79

     

       Device Boot      Start         End      Blocks   Id  System

    /dev/vda1   *        2048      411647      204800   83  Linux

    /dev/vda2          411648     1435647      512000   82  Linux swap / Solaris

    /dev/vda3         1435648    41943039    20253696   83  Linux

     

    Command (m for help): q          *如果不想保存,按q即可离开

     

     

    介绍一下分区表主要列出的每个分区的信息项目

        a.Device:设备文件名,依据不同的磁盘接口/分区位置而改变

        b.Boot:表示是否为开机引导模块

        c.Start,End:表示这个分区在那个柱面号码之间,可以决定此分区的大小

        d.Blocks:就是以1k为单位的容量。

        e.Id  System:代表这个分区内的文件系统时什么

     

     

    .增加磁盘分区

    例:

    a,增加主分区1,2,3

    [root@server3 mnt]# fdisk /dev/vdb

    Welcome to fdisk (util-linux 2.23.2).

     

    Changes will remain in memory only, until you decide to write them.

    Be careful before using the write command.

     

     

    Command (m for help): n         

    Partition type:

       p   primary (0 primary, 0 extended, 4 free)

       e   extended

    Select (default p): p            *选择primary分区,即主分区

    Partition number (1-4, default 1):    *默认为1号,可自己改变

    First sector (2048-41943039, default 2048):   *直接安Enter决定

    Using default value 2048     *起始柱面

    Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +500M

    ###此处可直接输入柱面号码,但需要你自己计算分区大小

    ###也可直接用+..M(如上),让系统自己分配柱面号码

     

    Partition 1 of type Linux and of size 500 MiB is set

     

    Command (m for help): n     

    Partition type:

       p   primary (1 primary, 0 extended, 3 free)

       e   extended

    Select (default p): p

    Partition number (2-4, default 2):

    First sector (1026048-41943039, default 1026048):

    Using default value 1026048

    Last sector, +sectors or +size{K,M,G} (1026048-41943039, default 41943039): +500M

    Partition 2 of type Linux and of size 500 MiB is set

     

    Command (m for help): n

    Partition type:

       p   primary (2 primary, 0 extended, 2 free)

       e   extended

    Select (default p): p

    Partition number (3,4, default 3):

    First sector (2050048-41943039, default 2050048):

    Using default value 2050048

    Last sector, +sectors or +size{K,M,G} (2050048-41943039, default 41943039): +500M

    Partition 3 of type Linux and of size 500 MiB is set

     

    b.增加扩展分区

    Command (m for help): n

    Partition type:

       p   primary (3 primary, 0 extended, 1 free)

       e   extended

    Select (default e):      *因前三个分区都为主分区,第四个默认为扩展分区

    Using default response e

    Selected partition 4

    First sector (3074048-41943039, default 3074048):

    Using default value 3074048

    Last sector, +sectors or +size{K,M,G} (3074048-41943039, default 41943039):

    ###直接Enter,将剩下的所有分区都分给扩展分区

    Using default value 41943039

    Partition 4 of type Extended and of size 18.5 GiB is set

     

    Command (m for help): p          *查看分区信息

     

    Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 sectors

    Units = sectors of 1 * 512 = 512 bytes

    Sector size (logical/physical): 512 bytes / 512 bytes

    I/O size (minimum/optimal): 512 bytes / 512 bytes

    Disk label type: dos

    Disk identifier: 0x7afa732b

     

       Device Boot      Start         End      Blocks   Id  System

    /dev/vdb1            2048     1026047      512000   83  Linux

    /dev/vdb2         1026048     2050047      512000   83  Linux

    /dev/vdb3         2050048     3074047      512000   83  Linux

    /dev/vdb4         3074048    41943039    19434496    5  Extended

     

    c.增加逻辑分区

    Command (m for help): n

    All primary partitions are in use

    Adding logical partition 5

    First sector (3076096-41943039, default 3076096):

    Using default value 3076096

    Last sector, +sectors or +size{K,M,G} (3076096-41943039, default 41943039): +1024M

    Partition 5 of type Linux and of size 1 GiB is set

     

    Command (m for help): p

     

    Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 sectors

    Units = sectors of 1 * 512 = 512 bytes

    Sector size (logical/physical): 512 bytes / 512 bytes

    I/O size (minimum/optimal): 512 bytes / 512 bytes

    Disk label type: dos

    Disk identifier: 0x7afa732b

     

       Device Boot      Start         End      Blocks   Id  System

    /dev/vdb1            2048     1026047      512000   83  Linux

    /dev/vdb2         1026048     2050047      512000   83  Linux

    /dev/vdb3         2050048     3074047      512000   83  Linux

    /dev/vdb4         3074048    41943039    19434496    5  Extended

    /dev/vdb5         3076096     5173247     1048576   83  Linux

     

        此时/dev/vdb5,便是逻辑分区

     

     

        之后,可以按q(不保存)离开此界面,注意,不要保存,否则会损坏系统。(自己添加的虚拟磁盘请任性)

     

     

    一般来说,新建分区形式会有下面几种情况:

        *1-4号尚有剩余,且系统未由扩展分区:

            此时会让你选择primary/extended的选项,且你可以指定1-4号码

        *1-4号尚有剩余,且系统由扩展分区:

            此时会让你选择primary/logical的选项;若选择p则你还需要指定1-4之间的号码;若选择l(L)则不需要设置号码,因为系统会自动指定逻辑分区的文件名号码。

        *1-4没有剩余,且系统由扩展分区;

            此时不会让你挑选分区类型,直接进入logical的分区形式

     

     

    .删除磁盘分区

    例:

    [root@server3 mnt]# fdisk -l

    Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 sectors

    Units = sectors of 1 * 512 = 512 bytes

    Sector size (logical/physical): 512 bytes / 512 bytes

    I/O size (minimum/optimal): 512 bytes / 512 bytes

    Disk label type: dos

    Disk identifier: 0x7afa732b

     

       Device Boot      Start         End      Blocks   Id  System

    /dev/vdb1            2048     1026047      512000   83  Linux

    /dev/vdb2         1026048     2050047      512000   83  Linux

    /dev/vdb3         2050048     3074047      512000   83  Linux

    /dev/vdb4         3074048    41943039    19434496    5  Extended

    /dev/vdb5         3076096     5173247     1048576   83  Linux

    [root@server3 mnt]# fdisk /dev/vdb

    Welcome to fdisk (util-linux 2.23.2).

     

    Changes will remain in memory only, until you decide to write them.

    Be careful before using the write command.

     

     

    Command (m for help): d

    Partition number (1-5, default 5): 5

    Partition 5 is deleted

     

    Command (m for help): d

    Partition number (1-4, default 4): 4

    Partition 4 is deleted

     

    Command (m for help): d

    Partition number (1-3, default 3): 3

    Partition 3 is deleted

     

    Command (m for help): d

    Partition number (1,2, default 2): 2

    Partition 2 is deleted

     

    Command (m for help): d

    Selected partition 1

    Partition 1 is deleted

     

    Command (m for help): p                  

     

    Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 sectors

    Units = sectors of 1 * 512 = 512 bytes

    Sector size (logical/physical): 512 bytes / 512 bytes

    I/O size (minimum/optimal): 512 bytes / 512 bytes

    Disk label type: dos

    Disk identifier: 0x7afa732b

     

       Device Boot      Start         End      Blocks   Id  System

     

     

     

     

     

    .磁盘格式化

    mkfs

    格式: mkfs 【-t 文件系统格式】 设备文件名

    -t :可接文件系统格式

    例:

    [root@server3 mnt]# mkfs 【Tab】【Tab】

    mkfs         mkfs.cramfs  mkfs.ext3    mkfs.fat     mkfs.msdos   mkfs.xfs

    mkfs.btrfs   mkfs.ext2    mkfs.ext4    mkfs.minix   mkfs.vfat   

     

    [root@server3 mnt]# mkfs.ext4 /dev/vdb2

    mke2fs 1.42.9 (28-Dec-2013)

    Filesystem label=           *指分区的名称

    OS type: Linux

    Block size=1024 (log=0)         *block的大小设置为1K

    Fragment size=1024 (log=0)

    Stride=0 blocks, Stripe width=0 blocks   *由此设置决定的inode/block数量

    128016 inodes, 512000 blocks

    25600 blocks (5.00%) reserved for the super user

    First data block=1

    Maximum filesystem blocks=34078720

    63 block groups

    8192 blocks per group, 8192 fragments per group

    2032 inodes per group

    Superblock backups stored on blocks:

        8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

     

    Allocating group tables: done                           

    Writing inode tables: done                           

    Creating journal (8192 blocks): done 有日志记录

    Writing superblocks and filesystem accounting information: done

     

    至此,ext4格式化完成

     

     

    mke2fs:

    mke2fs 【-b block 大小】 【-i block 大小】【-L 卷标】 【-cj】设备

    -b:可以设置每个block的大小,目前支持1024,2048,4096bytes三种

    -i:多少容量给予一个inode呢

    -c:检查磁盘错误,仅下达一次-c时会进行快速读取测试;如果下达两次-c -c的话,会测试读写

    -L:后面可以接卷标名称

    -j:本来mke2fs时ext2,加上-j后,会主动加入journal而成为ext3

     

     

    .磁盘检验:fsck,badblocks

     

    fsck

    格式:fsck [-t 文件系统] [-ACay] 设备名称

    -t:指定文件系统,不过现在的linux会自动通过super block去分辨文件系统,因此通常时不需要这个参数的

    -A:依据/etc/fstab的内容,将需要的设备扫描一次

    -a:自动修复检查到的有问题的扇区,不需要一直按y

    -y:与-a类似,但是某些文件仅支持-y这个参数

    -C:可以在检测的过程中使用一个直方图来显示目前的进度

     

    badblocks

    格式:badblocks -【svw】 设备名称

    -s:在屏幕上列出进度

    -v:可以在屏幕上看到进度

    -w:使用写入的方式来测试,建议不要使用此参数,尤其是待检查的设备已有文件时

     

     

    .磁盘的挂载与卸载

     

        在挂载前,先确定几件事:

        *单一文件系统不应该被重复挂载在不同的挂载点(目录)中

        *单一目录不应该重复挂载多个文件系统

        *作为挂载点的目录理论上应该都是空目录才是

     

    挂载命令:mount

    格式:

    mount -a

    mount 【-l(L的小写)】

    mount 【-t 文件系统】 【-L Label名】 【-o 额外选项】 【-n】 设备文件名 挂载点

    参数:

    -a:依照配置文件/etc/fstab的数据将所有未挂载的磁盘都挂载上来

    -l:单纯输入mount会显示目前的挂载信息,加上-l可增列Labekl名称

    -t:可以加上文件系统的种类来指定欲挂载的类型。

    -n:在默认情况下,系统会将实际挂载的情况写入/etc/fstab中,以利其他程序的运行。但在某些某些情况下为了避免问题,会刻意不写入,此时就要使用-n这个参数了

    -L:系统除了利用设备文件名之外,还可以利用文件系统的卷标名称进行挂载。

    -o:后面可以接一些挂载时额外加上的参数,例如帐号。密码读取权限等:

        *ro,rw:挂载文件系统为只读(ro)或可读写(rw)

        *async,sync:此文件系统是否使用同步写入(sync)或异步(async)的内存机制,默认为async

        *auto,noauto:允许此分区被mount -a自动挂载

        *dev,nodev:是否允许此分区上可创建设备文件。dev为允许

        *suid,nosuid:是否允许此分区含有suid/sgid的文件格式

        *exec,noexec:是否允许此分区上拥有可执行的binary文件

        *user,nouser:是否允许此分区让任何用户执行mount。一般来说,mount只有root可以执行,但使用user参数,册可以让一般用户也能够对此分区执行mount

        *defaults:默认值为rw,suid,dev,exec,auto,nouser,async

        *remount:重新挂载,这在系统出错,或重新更改参数时,很有用

     

     

    umount(将设备文件卸载)

    格式:umount 【-fn】 设备文件名或挂载点

    -f:迁至卸载,可以用在网络文件系统(NFS)无法读取到的情况下

    -n:不更新/etc/mtab的情况下卸载

     

    注:只有挂载的设备文件卸载了,才可以退出光盘,U盘等设备。

     

    .设置开机挂载:/etc/fstab

        在开机的时候就将我们需要的文件系统挂载好,这就是fstab文件的作用,在说这个文件之前,首先说一下系统挂载的限制:

        *根目录时必须挂载的,而且一定要先于其它的挂载点被挂载起来

        *其他挂载点必须为已新建的目录,可以人以指定,但一定要遵守必须的系统目录架构规则

        *所有挂载点在同一时间内,只能挂载一次

        *所有分区在同一时间内,只能挂载一次

        *如若进行卸载,你必须先将工作目录移到到挂载点(及其子目录)之外

     

        接下来日那个我们看一下fstab这个文件的内容:

    [root@server3 ~]# cat /etc/fstab

     

    #

    # /etc/fstab

    # Created by anaconda on Tue Oct 23 20:41:40 2018

    #

    # Accessible filesystems, by reference, are maintained under '/dev/disk'

    # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

    #

    UUID=02014ad0-eefa-419a-b5a2-69fe78f17e48 /                       xfs     defaults        0 0

    UUID=f87158fa-2d5a-4509-8a2e-98f193d1c1bf /boot                   xfs     defaults        0 0

    UUID=49de3e9a-8594-40df-8182-da3a2b2164eb swap                    swap    defaults        0 0

     

     

     

    *第一列:磁盘设备文件名或该设备的Label

    *第二列:挂载点

    *第三列:挂载分区的文件系统

    *第四列:文件系统参数,参考mount -o后面的参数

    *第五列:能否被dump备份命令作用,0代表不备份,1代表备份

    *第六列:是否以fsck检验扇区,0时不检验,1是检验

     

  • 相关阅读:
    抓鱼社区
    DotNetTextBox V3.0 所见即所得编辑器控件Ver3.3.3 Free(免费版)
    Pet Shop 4.0系统
    北大青鸟PPT/ Net学习课件/asp.net,AJAX,ADO.net视频教程
    [开源]ASP.NET通用权限管理系统(FrameWork) 1.0.1 Release
    sql isnull函数
    几种常见算法的介绍及复杂度分析(转)
    ajaxpro配置与使用
    C#对图片的几种简单处理
    [你必须知道的.NET] 开篇有益
  • 原文地址:https://www.cnblogs.com/zhengyipengyou/p/10246707.html
Copyright © 2011-2022 走看看