Extending Partitions and Files Systems (Linux)

Last updated: 2021-02-08 15:02:25

    Overview

    A cloud disk is an expandable storage device on cloud. After a cloud disk is created, you can expand its capacity at any time to increase its storage capacity without losing any data in it.
    After expanding a cloud disk, you need to either assign its expanded capacity to an existing partition, or format it into an independent new partition.

    Prerequisites

    Note:

    Extending the file system may affect the existing data. We strongly recommend you to manually create a snapshot to back up your data before the operation.
    To protect your existing data, you can choose to use the umount command to unmount existing partitions and use the fsck command to check file systems during the operation.

    Directions

    Confirming the expansion method

    1. Run the following command as the root user to view the partition format of the cloud disk.
      fdisk -l
      • If the result indicates that the device has no partition (for example, it only shows /dev/vdb), see Extending the file system.
      • If the result is as shown in the following two figures (which may vary according to the operating system), the GPT partition format is used.

      • If the result is as shown in the following figure (which may vary according to the operating system), the MBR partition format is used.

        Note:

        MBR partition supports disk with a maximum capacity of 2 TB. When you partition disk with a capacity greater than 2 TB, we recommend that you create and mount a new data disk and use the GPT partition format to copy data. When the GPT partition is used on a Linux CVM, you have to use the parted partition tool, because fdisk will become unavailable.

    2. Follow Step 1 to view the cloud disk partition format, and select the corresponding operations guide.
      Partition format Operations guide Notes
      - Extend the file system Applicable to scenarios where a file system is created directly on a bare device and no partition is created.
      GPT Assign the expanded capacity to an existing partition (GPT) Also applicable to scenarios of direct formatting when no partition is created.
      Format the expanded capacity into an independent new partition (GPT) The original partition can be retained without changes.
      MBR Assign the expanded capacity to an existing partition (MBR) Also applicable to scenarios of direct formatting when no partition is created.
      Format the expanded capacity into an independent new partition (MBR) The original partition can be retained without changes.

    Extending the file system

    1. Run the following command based on the operating system to extend the file system.
      • For an EXT file system, run the resize2fs command to extend the file system.
        Taking /dev/vdb as an example, run the following command to extend an EXT file system:
        resize2fs /dev/vdb
      • For an XFS file system, run the xfs_growfs command to extend the file system.
        Taking /dev/vdb as an example, run the following command to extend an XFS file system:
        xfs_growfs /dev/vdb
    2. Run the following command to view the new partition:
      df -h

    Assigning the expanded capacity to an existing partition (GPT)

    1. Run the following command as the root user to confirm changes in cloud disk capacity.

      parted <Disk path> print

      Taking the disk path /dev/vdb as an example, run the following command:

       parted /dev/vdb print

      If a message as shown in the following figure appears in the process, enter Fix.

      As shown in the following figure, the cloud disk space is 107 GB after expansion and the existing partition capacity is 10.7 GB.

    2. Run the following command to check whether the cloud disk has partitions mounted:

      mount | grep '<Disk path>' 

      Taking the disk path /dev/vdb as an example, run the following command:

      mount | grep '/dev/vdb'

      As shown in the following figure, the cloud disk has one partition (vdb1) mounted to /data.

    3. Run the following command to unmount the data disk:

      umount <Mount point>

      Taking the mount point /data as an example, run the following command:

      umount /data

      Note:

      Unmount the file systems from all partitions on the cloud disk, and perform the operations in Step 4 again. You can run the following command again to confirm that the unmounting is successful:

      mount | grep '/dev/vdb'

      The file systems are unmounted from all partitions on the cloud disk, as shown in the following figure.

    4. Run the following command to access the parted tool.

      parted '<Disk path>'

      Taking the disk path /dev/vdb as an example, run the following command:

      parted '/dev/vdb'
    5. Run the following command to change the unit from the default “GB” to “sector” for display and operation:

      unit s
    6. Run the following command to view partitions and record their Start values:

      Note:

      After a partition is deleted and a new one is created, the Start value must remain unchanged. Otherwise, data may be lost.

      print

      This document uses the Start value 2048s as an example.

    7. Run the following command to delete the existing partition.

      rm <Partition Number>

      For example, run the following command to delete the partition “1” from the cloud disk.

      rm 1

      The following figure shows the command output.

    8. Run the following command to create a new primary partition:

      mkpart primary <Start sector of the original partition> 100%

      The 100% in the command indicates this partition goes to the end of the disk.
      Assume that the primary partition starts from sector 2048 (it must be the same as that of the previously deleted partition, that is, the Start value must be 2048s), run the following command:

      mkpart primary 2048s 100%

      If a status as shown in the following figure appears, enter Ignore.

    9. Run the following command to check whether the new partition has been created successfully:

      print

      If the result as shown in the following figure is returned, the new partition has been created successfully.

    10. Run the following command to exit the parted tool:

      quit
    11. Run the following command to check the extended partition:

      e2fsck -f <Partition path>

      Taking the new partition “1” (its partition path is /dev/vdb1) as an example, run the following command:

      e2fsck -f /dev/vdb1

      The following figure shows the command output.

      Extend your file system as follows:

      • For an EXT file system:

        1. Run the following command to extend the EXT file system in the new partition:
          resize2fs <Partition path>
          Taking the partition path /dev/vdb1 as an example, run the following command:
          plaintext resize2fs /dev/vdb1 ​
          If the result as shown in the following figure is returned, the expansion is successful.
        2. Run the following command to manually mount the new partition:
          mount <Partition path> <Mount point>
          Taking the partition path /dev/vdb1 and the mount point /data as an example, run the following command:
          mount /dev/vdb1 /data
      • For an XFS file system

        1. Run the following command to manually mount the partition:
          mount <Partition path> <Mount point>
          Taking the partition path /dev/vdb1 and the mount point /data as an example, run the following command:
          mount /dev/vdb1 /data
        2. Run the following command to extend the XFS file system in the new partition:
          xfs_growfs <Partition path>
          Taking the partition path /dev/vdb1 as an example, run the following command:
          xfs_growfs /dev/vdb1
    12. Run the following command to view the new partition:

      df -h

      If the result as shown in the following figure is returned, the mounting is successful, and you can see the data disk.

    Formatting the expanded capacity into an independent new partition (GPT)

    1. Run the following command as the root user to confirm changes in cloud disk capacity:

      parted <Disk path> print

      Taking the disk path /dev/vdb as an example, run the following command:

      parted /dev/vdb print

      If a message as shown in the following figure appears in the process, enter Fix.

      As shown in the following figure, the cloud disk space is 107 GB after expansion and the existing partition capacity is 10.7 GB.

    2. Run the following command to check whether the cloud disk has partitions mounted:

      mount | grep '<Disk path>' 

      Taking the disk path /dev/vdb as an example, run the following command:

      mount | grep '/dev/vdb'

      As shown in the following figure, the cloud disk has one partition (vdb1) mounted to /data.

    3. Run the following command to unmount the data disk:

      umount <Mount point>

      Taking the mount point /data as an example, run the following command:

      umount /data

      Note:

      Unmount the file systems from all partitions on the cloud disk, and perform the operations in Step 4 again. You can run the following command again to confirm that the unmounting operation is successful.

      mount | grep '/dev/vdb'

      The file systems are unmounted from all partitions on the cloud disk, as shown in the following figure.

    4. Run the following command to access the parted partition tool:

      parted '<Disk path>'

      Taking the disk path /dev/vdb as an example, run the following command:

      parted '/dev/vdb'
    5. Run the following command to view partitions and record their End values, which will be used as the start offset of the next partition:

      print

    6. Run the following command to create a primary partition. This partition starts at the end of existing partitions, and covers all the new space on the disk.

      mkpart primary start end

      Taking the End value 10.7 GB as an example, run the following command:

      mkpart primary 10.7GB 100%
    7. Run the following command to check whether the new partition has been created successfully:

      print

    8. Run the following command to exit the parted tool:

      quit
    9. Run the following command to format this new partition:

      mkfs.<fstype> <Partition path> 

      You can select a file system format such as EXT2 or EXT3.
      If you use an EXT3 file system, run the following command:

      mkfs.ext3 /dev/vdb2

    Assigning the expanded capacity to an existing partition (MBR)

    You can use automatic expansion tools including fdisk, e2fsck and resize2fs to add the expanded cloud disk capacity to the existing file system on a Linux CVM. To ensure a successful expansion, the following four requirements must be met:

    • The file system is EXT2, EXT3, EXT4, or XFS.
    • The current file system does not have any error.
    • The disk size after expansion does not exceed 2 TB.
    • These tools are only compatible with Python version 2, but not Python version 3.
    1. Run the following command as the root user to unmount the partition:

      umount <Mount point>

      Taking the mount point /data as an example, run the following command:

      umount /data

    2. Run the following command to download an expansion tool.
      This tool is recommended in the Chinese mainland:

      wget -O /tmp/devresize.py https://tencentcloud.coding.net/p/tencentcloud/d/tencentcloud-cbs-tools/git/raw/master/devresize/devresize.py

      This tool is recommended in regions outside the Chinese mainland:

      wget -O /tmp/devresize.py https://raw.githubusercontent.com/tencentyun/tencentcloud-cbs-tools/master/devresize/devresize.py
    3. Run the following command to use the tool for expansion:

      python /tmp/devresize.py <Disk path>

      Taking the disk path /dev/vdb and the file system vdb1 as an example, run the following command:

      python /tmp/devresize.py /dev/vdb

      • If "The filesystem on /dev/vdb1 is now XXXXX blocks long." is output, the expansion is successful. Then, perform Step 4.
      • If the output is "[ERROR] - e2fsck failed!!", perform the following steps:
        a. Run the following command to fix the partition where the file system resides.
        fsck -a <Partition path>
        Taking the disk path /dev/vdb and the file system vdb1 as an example, run the following command:
        fsck -a /dev/vdb1
        b. After the partition is fixed, run the following command again to use the tool for expansion.
        python /tmp/devresize.py /dev/vdb
    4. Run the following command to manually mount the extended partition:

      mount <Partition path> <Mount point>

      This document uses the mount point /data as an example.

      • If a partition at the partition path /dev/vdb1 exists before the expansion, run the following command:
        mount /dev/vdb1 /data
      • If no partition exists before expansion, run the following command:
        mount /dev/vdb /data
    5. Run the following command to view the partition capacity after expansion:

      df -h

      If the result similar to the following figure is returned, the mount is successful, and you can see the data disk.

    6. Run the following command to view the original partition data after expansion and check whether the file system is added with expanded storage space.

      ll /data

    Formatting the expanded capacity into an independent new partition (MBR)

    1. Run the following command as a root user to view the partition information of the mounted data disk:
      df -h
    2. Run the following command to view the information of the data disk without partitions after expansion:
      fdisk -l
    3. Run the following command to unmount all mounted partitions:
      umount <Mount point>
      Taking the mount point /data as an example, run the following command:
      umount /data

      Note:

      Unmount the file systems from all partitions on the cloud disk, and perform the operations in Step 4 again. You can run the following command again to confirm that the unmounting is successful:

      mount | grep '<Disk path>'
      If the return is null, then all file systems have been unmounted from partitions on the cloud disk.
    4. Run the following command to create a partition.
      fdisk <Disk path>
      Taking the disk path /dev/xvdc as an example, run the following command:
      fdisk /dev/xvdc
      When prompted, sequentially enter p (to check existing partitions), n (to create a partition), p (to create a primary partition), 2 (to create the second primary partition), press Enter twice (to use the default configuration), enter w (to save the partition table), and start the partition, as shown in the following figure:

    Note:

    This document takes creating one partition as an example. You can also create multiple partitions as needed.
    5. Run the following command to view the new partition:

    fdisk -l

    The following figure shows that the new partition xvdc2 has been created.

    1. Run the following command to format the new partition and create a file system:
      mkfs.<fstype> <Partition path> 
      You can select a file system format such as EXT2 or EXT3.
      If you use an EXT3 file system, run the following command:
    mkfs.ext3 /dev/xvdc2


    7. Run the following command to create a mount point:

    mkdir <New mounting point>

    Taking the new mount point /data1 as an example, run the following command:

    mkdir /data1
    1. Run the following command to manually mount the new partition:
      mount <New partition path> <New mount point>
      Taking the new partition path /dev/xvdc2 and the new mount point /data1 as an example, run the following command:
      mount /dev/xvdc2 /data1
    2. Run the following command to view the new partition:
      df -h
      If the result as shown in the following figure is returned, the mounting is successful, and you can see the data disk.

    Note:

    To allow the CVM to automatically mount a data disk upon restart or start, perform Step 10 and Step 11 to add the new partition to /etc/fstab.
    10. Run the following command to add the partition:

    echo '/dev/xvdc2 /data1 ext3 defaults 0 0' >> /etc/fstab
    1. Run the following command to view the partition:
      cat /etc/fstab
      If the result as shown in the following figure is returned, the partition has been successfully added.

    Relevant Operations

    Extending Partitions and File Systems (Windows)

    FAQs

    If you encounter a problem when using Tencent Cloud CBS, refer to the following documents for troubleshooting as needed:

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help