Resize MBR partitions and file systems (< 2 TB)

Last updated:2021-07-21 17:50:41

Scenarios

You have expanded the capacity of an EBS volume that uses MBR partitioning and has file systems. The capacity of the EBS volume after the expansion is less than 2 TB. You can resize the partitions and file systems on the EBS volume by using one of the following methods as needed:

Prerequisites

  1. You have created a snapshot to back up the data on the EBS volume. To prevent data loss caused by misoperations, we recommend that you create a snapshot to back up data before you expand the capacity of an EBS volume.
  2. You have expanded the capacity of the EBS volume in the EBS console. The maximum capacity of an EBS volume that uses MBR partitioning is 2 TB. Therefore, make sure that the capacity of the EBS volume after the expansion does not exceed 2 TB.
  3. You have made sure that the partition format of the EBS volume is MBR. For more information, see Overview.
  4. The type of the file system on the EBS volume is ext2, ext3, ext4, or xfs, and the file system contains no errors.

Scenario 1: Resize existing partitions

Allocate the expanded capacity to existing MBR partitions

Operating environment

Resource
Description
Operating system CentOS 6.5 64-bit
Data disk /dev/vdb: uses MBR partitioning and ext4 file systems. The capacity of the disk has been expanded from 50 GB to 200 GB.
/dev/vdc: uses MBR partitioning and xfs file systems. The capacity of the disk has been expanded from 50 GB to 300 GB.
  1. Run the lsblk command to view the information about the partitions and mount points on the data disks attached to your KEC instance. In this example, the data disks are /dev/vdb and /dev/vdc.
    lsblk
    

The following figure shows the output.
image.png
The following table describes the information extracted from the figure.

Data disk Partition Partition description
/dev/vdb is the data disk with a capacity of 200 GB. /dev/vdb1 The capacity of the partition is 50 GB. The mount point is /mnt/data_disk01.
/dev/vdc is the data disk with a capacity of 300 GB. /dev/vdc1 The capacity of the partition is 50 GB. The mount point is /mnt/data_disk02.
  1. Run the following command to view the information about the file systems on the data disks attached to your KEC instance:
    df -Th
    

The following figure shows the output.
image.png
The following table describes the information extracted from the figure.

Partition File system type Mount point
/dev/vda1 ext4 Mounted to /
/dev/vdb1 ext4 Mounted to /mnt/data_disk01
/dev/vdc1 xfs Mounted to /mnt/data_disk02
  1. Run the umount <Mount point> command to unmount partitions. In this example, unmount the /dev/vdb1 partition from the /mnt/data_disk01 mount point.

    umount /mnt/data_disk01
    

    Note: Before you proceed to the next step, make sure that you have unmounted all the partitions of the data disks for which you want to allocate the expanded capacity.

  2. Run the following command to use the growpart tool to resize partitions:

    growpart /dev/vdb 1
    

    In this example, resize the partitions /dev/vdb1 and /dev/vdc1 of the data disks. Separate /dev/vdb and 1, or /dev/vdc and 1, with a space in the command. If you need to resize other partitions, modify the command as needed.
    The following figure shows the output.
    image.png

  3. In the operating system of your KEC instance, resize a file system by running one of the following commands based on the type of the file system.

    • If the type of the file system is in the format of ext*, such as ext4, run the following commands:
      Check the status of the file system
      e2fsck -f /dev/vdb1
      
      Resize the file system of the /dev/vdb1 partition on the /dev/vdb data disk
      resize2fs /dev/vdb1
      
      The following figure shows the output.
      image.png

      Note: In the preceding commands, /dev/vdb1 is the partition name. You must change it based on your business requirements.

    • If the type of the file system is xfs, run the following commands:
      Mount the partition to a directory
      mount /dev/vdc1 /mnt/data_disk02
      
      Resize the file system of the /dev/vdc1 partition on the /dev/vdc data disk
      xfs_growfs /mnt/data_disk02
      
      The following figures show the output.
      image.png
      image.png

      Note: In the preceding commands, /mnt/data_disk02 is the mount point of the /dev/vdc1 partition. You must change it based on your business requirements.

  4. Run the mount <Partition name> <Mount point> command to manually mount the resized partitions. In this example, mount the /dev/vdb1 partition to the mnt/data_disk01 mount point.

    mount /dev/vdb1 /mnt/data_disk01
    
  5. Run the following command to check the resizing results:

    df -Th
    

    The following figure shows the output.
    image.png
    The figure shows that the resizing succeeded. When you check the results, compare the results with the original capacities.

    • If the resizing succeeded, the business programs on the KEC instance can continue to run as expected.
    • If the resizing failed, use the snapshot to roll back the data.

Scenario 2: Allocate the expanded capacity to new partitions

Allocate the expanded capacity to newly created and formatted MBR partitions

Operating environment

Resource
Description
Operating system CentOS 6.5 64-bit
Data disk /dev/vdb: uses MBR partitioning and ext4 file systems. Keep the capacity of Partition 1, which is 50 GB, unchanged and create Partition 2 with a capacity of 150 GB.
/dev/vdc: uses MBR partitioning and xfs file systems. Keep the capacity of Partition 1, which is 50 GB, unchanged and create Partition 2 with a capacity of 250 GB.
  1. Run the lsblk command to view the information about the partitions and mount points on the data disks attached to your KEC instance. In this example, the data disks are /dev/vdb and /dev/vdc.
    lsblk
    

The following figure shows the output.
image.png
The following table describes the information extracted from the figure.

Data disk Partition Partition description
/dev/vdb, data disk is the with a capacity of 200 GB. /dev/vdb1 The capacity of the partition is 50 GB. The mount point is /mnt/data_disk01.
/dev/vdc, data disk is the with a capacity of 300 GB. /dev/vdc1 The capacity of the partition is 50 GB. The mount point is /mnt/data_disk02.
  1. Run the following command to view the information about the file systems on the data disks attached to your KEC instance:
    df -Th
    

The following figure shows the output.
image.png
The following table describes the information extracted from the figure.

Partition File system type Mount point
/dev/vda1 ext4 Mounted to /
/dev/vdb1 ext4 Mounted to /mnt/data_disk01
/dev/vdc1 xfs Mounted to /mnt/data_disk02
  1. Run the umount <Mount point> command to unmount partitions. In this example, unmount the /dev/vdb1 partition from the /mnt/data_disk01 mount point.

    umount /mnt/data_disk01
    

    Note: Before you proceed to the next step, make sure that you have unmounted all the partitions of the data disks for which you want to allocate the expanded capacity.

  2. Run the fdisk <Data disk name> command to create a partition. In this example, create a partition with a capacity of 150 GB on the /dev/vdb data disk.

    fdisk /dev/vdb
    

    Perform the following steps as prompted:
    a. Enter p: View the information about the existing partitions. In this example, the existing partition is /dev/vdb1.
    b. Enter n: Create a partition.
    c. Enter p: Create a primary partition.
    d. Enter 2: Create another primary partition.
    e. Press the Enter key twice: Use the default size for the partition to be created.
    f. Enter w to Save the partition table and start partitioning.
    The following figure shows the output.
    image.png

    Note: In this example, only one partition is created. You can create multiple partitions as needed.

  3. Run the following command to view the new partition:

    lsblk
    

    The following figure shows the output. In this example, a partition is also created for the /dev/vdc data disk by following Step 4.
    image.png

  4. Run the mkfs.<fstype> <Partition name> command to format the new partitions and create file systems.

    • To create an ext* file system, for example, ext4, run the following command:

      Create an ext4 file system for the /dev/vdb2 partition on the /dev/vdb2 data disk

      mkfs.ext4 /dev/vdb2
      

      The following figure shows the output.
      image.png

      Note: In the preceding command, /dev/vdb2 is the partition name. You must change it based on your business requirements.

    • To create an xfs file system, run the following command:
      Create an xfs file system for the /dev/vdc2 partition on the /dev/vdc data disk

      mkfs.xfs -f /dev/vdc2
      

      The following figure shows the output.
      image.png

      Note: In the preceding command, /dev/vdc2 is the partition name. You must change it based on your business requirements.
      If the message -bash: mkfs.xfs: command not found appears, run the yum -y install xfsprogs command to install the RPM package of xfsprogs.

  5. Run the mkdir <New mount point> command to create a mount point for each new partition. In this example, create the /mnt/data_disk03 mount point.

    mkdir /mnt/data_disk03
    
  6. Run the mount <Partition name> <Mount point> command to manually mount the new partitions. In this example, mount the /dev/vdb2 partition to the /mnt/data_disk03 mount point.

    mount /dev/vdb2 /mnt/data_disk03
    
  7. Run the following command to view the information about the new partitions:

    df -Th
    

    The following figure shows the output.
    image.png
    The figure shows that the resizing succeeded. When you check the results, compare the results with the original capacities.

    • If the resizing succeeded, the business programs on the KEC instance can continue to run as expected.
    • If the resizing failed, use the snapshot to roll back the data.

Description of optional actions
If you want the new partitions of the data disks to be automatically mounted to the KEC instance when the KEC instance starts or restarts, perform the following steps to add the information about the new partitions to the /etc/fstab file.

  1. Add the auto-mount configuration to the etc/fstab file. In this example, add the configuration to automatically mount the /dev/vdb2 partition to the /mnt/data_disk03 mount point.
    echo '/dev/vdb2 /mnt/data_disk03 ext4 defaults 0 0' >> /etc/fstab
    
  2. Run the cat /etc/fstab command to view the auto-mount configuration.
    cat /etc/fstab
    
    The following figure shows the output.
    image.png

Did you find the above information helpful?

Unhelpful
Mostly Unhelpful
A little helpful
Helpful
Very helpful

What might be the problems?

Insufficient
Outdated
Unclear or awkward
Redundant or clumsy
Lack of context for the complex system or functionality

More suggestions

0/200

Please give us your feedback.

Submitted

Thank you for your feedback.

问题反馈