Extending MBR Partitions and File Systems (Smaller than 2 TB)

Last updated: 2021-06-24 16:42:31

    Overview

    If your cloud disk has a MBR partition that contains the file system, with a disk size of less than 2 TB after expansion, you can use either of the following methods to extend partitions and file systems:

    Prerequisites

    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 requirements must be met:

    • The way to expand and partition has been confirmed. For more information, see Determining the Expansion Method.
    • 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.
    • Only use Python version 2 because of compatibility with expansion tools in this document.

    Directions

    Assigning the expanded capacity to an existing MBR partition

    Run the following command as the root user to query partitions of the cloud disk.

    lsblk
    
    • The following output indicates there is only one partition. In this case, you can perform the automatic expansion using tools.
    • The following output indicates there are two partitions: vdb1 and vdb2. In this case, you need to choose a partition to be extended as instructed in manual expansion.

    Note

    This method is only applicable to the scenario where there is only one partition. If you have two or more partitions, choose [manual expansion](#ManualExpansion).

    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.
      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 as follows, the expansion is successful. Then, perform step 4.
      • If [ERROR] - e2fsck failed!! is output, 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. This document uses the mount point /data as an example.
      mount <Partition path> <Mount point>
      
    • If a partition at the partition path /dev/vdb1 exists before expansion, run the following command:
      mount /dev/vdb1 /data
      
    1. Run the following command to view the partition capacity after expansion.
      df -h
      

      If the result similar to the following figure is returned, the mounting is successful, and you can see the data disk.
    2. Run the following command to view the data information of the original partition after expansion and check whether the new storage space has been added to the file system.
      ll /data
      

    Formatting the expanded capacity into an independent new MBR partition

    1. Run the following command as the root user to view the mounted partition of the data disk.
      df -h
      
      As shown in the following figure, the mounted partition of the data disk is 20 GB.
    2. Run the following command to view the data disk that has no partition after expansion:
      fdisk -l
      
      As shown in the following figure, the data disk has been expanded to 30 GB.

    1. 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:

      After all partitions are unmounted from the cloud disk, perform step 4 again.

    2. Run the following command to create a partition.

      fdisk <Disk path>
      

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

      fdisk /dev/vdb
      

      Perform the following steps in sequence when prompted.

      1. Enter p to check existing partitions, such as /dev/vdb1 in this document.
      2. Enter n to create a partition.
      3. Enter p to create a primary partition.
      4. Enter 2 to create the second primary partition.
      5. Press Enter twice to use the default partition size.
      6. Enter w to save the partition table and start partitioning.
        See the figure below:

    Note:

    This document takes creating one partition as an example. You can also create multiple partitions to meet your needs.

    1. Run the following command to view the new partition.

      fdisk -l
      

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

    2. Run the following command to format the new partition and create a file system in a desired format, such as EXT2 or EXT3.

      mkfs.<fstype> <Partition path> 
      

      Taking EXT4 as an example, run the following command:

      mkfs.ext4 /dev/vdb2
      

      The following figure shows the successful creation of the EXT file system.

    3. Run the following command to create a mount point.

      mkdir <New mount point>
      

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

      mkdir /data1
      
    4. Run the following command to manually mount the new partition.

      mount <New partition path> <New mount point>
      

      Taking the new partition path /dev/vdb2 and the new mount point /data1 as an example, run the following command:

      mount /dev/vdb1 /data2
      
    5. 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 startup, perform step 10 and step 11 to add the new partition to /etc/fstab.

    6. Run the following command to add the partition.

      echo '/dev/vdb2 /data1 ext4 defaults 0 0' >> /etc/fstab
      
    7. 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.

    Documentation

    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: