文档首页> 云硬盘 EVS> 用户指南> 附录> 分区和文件系统扩展前准备(Linux)
更新时间:2024-03-12 GMT+08:00

分区和文件系统扩展前准备(Linux)

扩展磁盘分区和文件系统前,请先检查磁盘的分区形式和文件系统,并根据磁盘的分区形式选择对应的操作指导。

  1. 检查磁盘分区形式,请参见:

方法一:使用fdisk命令查看分区形式和文件系统

  1. 执行以下命令,查看弹性云服务器挂载的所有磁盘情况。

    lsblk

    回显类似如下信息:
    [root@ecs-test-0001 ~]# lsblk
    NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    vda    253:0    0   40G  0 disk
    └─vda1 253:1    0   40G  0 part /
    vdb    253:16   0  150G  0 disk
    └─vdb1 253:17   0  100G  0 part /mnt/sdc

    本示例中数据盘“/dev/vdb”扩容前已有分区“/dev/vdb1”,将数据盘扩容50GiB后,新增的容量还未划分磁盘分区,因此“/dev/vdb”显示150GiB,“/dev/vdb1”显示100GiB。

  2. 执行以下命令,查看当前磁盘分区的分区形式。

    fdisk -l

    回显类似如下信息:
    [root@ecs-test-0001 ~]# fdisk -l
    
    Disk /dev/vda: 42.9 GiB, 42949672960 bytes, 83886080 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: 0x000bcb4e
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *        2048    83886079    41942016   83  Linux
    
    Disk /dev/vdb: 161.1 GiB, 161061273600 bytes, 314572800 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: 0x38717fc1
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vdb1            2048   209715199   104856576   83  Linux

    “system”为“Linux”表示分区形式为MBR。“system”为“GPT”表示分区形式为GPT。

    • 如果回显中没有列出所有的磁盘分区,和1中的信息不符合。可能原因是:磁盘已有分区为GPT,并且扩容后存在未分配分区的空间,此时使用fdisk -l无法查看所有分区的信息,请参考方法二:使用parted命令查看分区形式和文件系统重新确认磁盘分区形式和文件系统。
    • 如果回显中列出了所有的磁盘分区,和1中的信息符合,则继续执行以下操作。

  3. 执行以下命令,查看磁盘分区的文件系统格式。

    blkid 磁盘分区

    命令示例:

    blkid /dev/vdb1

    [root@ecs-test-0001 ~]# blkid /dev/vdb1
    /dev/vdb1: UUID="0b3040e2-1367-4abb-841d-ddb0b92693df" TYPE="ext4"

    “TYPE”为“ext4”:表示为/dev/vdb1的文件系统是ext4。

  4. 执行以下命令,确认文件系统的状态。

    ext*:e2fsck -n 磁盘分区

    xfs:xfs_repair -n 磁盘分区

    以“ext4” 为例:

    e2fsck -n /dev/vdb1

    回显类似如下信息:
    [root@ecs-test-0001 ~]# e2fsck -n /dev/vdb1
    e2fsck 1.42.9 (28-Dec-2013)
    Warning!  /dev/vdb1 is mounted.
    Warning: skipping journal recovery because doing a read-only filesystem check.
    /dev/vdb1: clean, 11/6553600 files, 459544/26214144 blocks

    文件系统状态为clean表示状态正常,如果不是clean,请先修复问题后执行扩容操作。

方法二:使用parted命令查看分区形式和文件系统

  1. 执行以下命令,查看弹性云服务器挂载的所有磁盘情况。

    lsblk

    回显类似如下信息:
    [root@ecs-test-0001 ~]# lsblk
    NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    vda    253:0    0   40G  0 disk
    └─vda1 253:1    0   40G  0 part /
    vdb    253:16   0  150G  0 disk
    └─vdb1 253:17   0  100G  0 part /mnt/sdc

    本示例中数据盘“/dev/vdb”扩容前已有分区“/dev/vdb1”,将数据盘扩容50GiB后,新增的容量还未划分磁盘分区,因此“/dev/vdb”显示150GiB,“/dev/vdb1”显示100GiB。

  2. 执行以下命令,指定一块磁盘,然后输入“p”,查看磁盘的分区形式。

    parted 磁盘

    以查看“/dev/vdb”的分区形式为例:

    parted /dev/vdb

    回显类似如下信息:
    [root@ecs-test-0001 ~]# parted /dev/vdb
    GNU Parted 3.1
    Using /dev/vdb
    Welcome to GNU Parted! Type 'help' to view a list of commands.
    (parted) p
    Error: The backup GPT table is not at the end of the disk, as it should be.  This might mean that another operating system believes the
    disk is smaller.  Fix, by moving the backup to the end (and removing the old backup)?
    Fix/Ignore/Cancel? Fix
    Warning: Not all of the space available to /dev/vdb appears to be used, you can fix the GPT to use all of the space (an extra 104857600
    blocks) or continue with the current setting?
    Fix/Ignore? Fix
    Model: Virtio Block Device (virtblk)
    Disk /dev/vdb: 161GiB
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    Disk Flags:
    
    Number  Start   End    Size   File system  Name  Flags
     1      1049kB  107GiB  107GiB  ext4         test
    
    (parted) 
    “Partition Table”表示当前磁盘的分区形式,“Partition Table:msdos”表示磁盘分区形式为MBR,“Partition Table:gpt”表示磁盘分区形式为GPT,“Partition Table:loop”表示磁盘分区形式为整盘分区。
    • 如果系统出现以下Error,请输入“Fix”。
      Error: The backup GPT table is not at the end of the disk, as it should be.  This might mean that another operating system believes the
      disk is smaller.  Fix, by moving the backup to the end (and removing the old backup)?

      GPT分区表信息存储在磁盘开头,为了减少分区表损坏的风险,同时在磁盘末尾会备份一份。当磁盘容量扩大后,末尾位置也会随之变化,因此需要根据系统提示输入“Fix”,将分区表信息的备份文件挪到新的磁盘末尾位置。

    • 如果系统出现以下Warning,请输入“Fix”。
      Warning: Not all of the space available to /dev/vdb appears to be used, you can fix the GPT to use all of the space (an extra 104857600
      blocks) or continue with the current setting?
      Fix/Ignore? Fix

      根据系统提示输入“Fix”,系统会自动将磁盘扩容部分的容量设置为GPT。

  3. 查看完成后,输入“q”,退出parted模式。