Resize GPT partitions and file systems (≥ 2 TB)

Last updated:2021-07-21 17:49:19

Scenarios

You have expanded the capacity of an EBS volume that uses GPT partitioning and has file systems. The capacity of the EBS volume after the expansion is greater than or equal to 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.
  3. You have made sure that the partition format of the EBS volume is GPT. 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 GPT partitions

Operating environment

Resource
Description
Operating system CentOS 6.5 64-bit
Data disk /dev/vdb: uses GPT partitioning and ext4 file systems. The capacity of the disk has been expanded from 200 GB to 2,200 GB.
/dev/vdc: uses GPT partitioning and xfs file systems. The capacity of the disk has been expanded from 2,400 GB to 3,000 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 2,200 GB. /dev/vdb1 The capacity of the partition is 200 GB. The mount point is /mnt/data_disk01.
/dev/vdc is the data disk with a capacity of 3,000 GB. /dev/vdc1 The capacity of the partition is 2.4 TB. 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 parted <Data disk name> print command to view the information about the GPT partitions on a data disk. Record the partition number and start sector value of each existing partition. In this example, view the information about the GPT partitions on the /dev/vdb/ data disk.

    parted /dev/vdb print
    

    If the Fix/Ignore/Cancel and Fix/Ignore messages appear, as shown in the following figure, enter Fix.
    The following figure shows the output.
    In this example, the capacity of the existing partition is 200 GB. The partition number is 1. The start sector value is 1049kB.
    image.png

    Note: You must record the start sector value of the existing partition. After you delete the existing partition, you must use the same start sector value to create a partition. Otherwise, data loss occurs.

  3. Run the parted <Data disk name> command to partition a data disk by using the parted partition utility. In this example, allocate the expanded capacity of the /dev/vdb data disk, which is 2,000 GB, to the existing GPT partition on the data disk.

    parted /dev/vdb
    

    Perform the following steps:
    a. Run the rm <Partition number> command to delete the existing partition. In this example, the /dev/vdb data disk has only one partition and the partition number is 1. Therefore, run the following command:

    rm 1
    

    b. Run the print command to make sure that the partition is deleted.

    Note: If you accidentally delete a partition, run the rescue command and enter the start and end values as prompted to recover the partition.

    c. Run the mkpart primary <Start sector value of the existing partition> 100% command to create a primary partition.
    In this example, the start sector value of the existing partition on the /dev/vdb data disk is 1049kB. 100% indicates that this partition ends at the end of the data disk. To allocate all the expanded capacity of the data disk to this partition, run the following command:

    mkpart primary 1049kB 100%
    

    d. Run the print command to check whether the partition is created.
    e. Run the quit command to exit the parted utility.
    The following figure shows the output.
    image.png

  4. 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 figure shows the output.
      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.

  5. 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
    
  6. 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 GPT partitions

Operating environment

Resource
Description
Operating system CentOS 6.5 64-bit
Data disk /dev/vdb: uses GPT partitioning and ext4 file systems. Keep the capacity of Partition 1, which is 200 GB, unchanged and create Partition 2 with a capacity of 2,000 GB.
/dev/vdc: uses GPT partitioning and xfs file systems. Keep the capacity of Partition 1, which is 2,400 GB, unchanged and create Partition 2 with a capacity of 600 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 2,200 GB. /dev/vdb1 The capacity of the partition is 200 GB. The mount point is /mnt/data_disk01.
/dev/vdc is the data disk with a capacity of 3,000 GB. /dev/vdc1 The capacity of the partition is 2.4 TB. 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 parted <Data disk name> print command to view the information about the GPT partitions on a data disk. Record the partition number and end sector value of each existing partition. In this example, view the information about the GPT partitions on the /dev/vdb/ data disk.

    parted /dev/vdb print
    

    If the Fix/Ignore/Cancel and Fix/Ignore messages appear, as shown in the following figure, enter Fix.
    The following figure shows the output.
    In this example, the capacity of the existing partition is 200 GB. The partition number is 1. The end sector value is 215GB.
    image.png

    Note: You must record the end sector value of the existing partition. The value is used as the start offset of the partition to be created.

  3. Run the parted <Data disk name> command to partition a data disk by using the parted partition utility. In this example, allocate the expanded capacity of the /dev/vdb data disk, which is 2,000 GB, to a newly created and formatted GPT partition.

    parted /dev/vdb
    

    Perform the following steps:
    a. Run the print command to view the partition number and end sector value of the existing partition.
    b. Run the mkpart <Partition name> <Start sector value> 100% command to create a primary partition. This partition starts from the end of the existing partition and is allocated all the expanded capacity of the data disk.
    In this example, the name of the new /dev/vdb2 partition is primary````. The start sector value of this partition is equal to the end sector value of the existing partition, which is215GB```. To allocate all the expanded capacity of the data disk to the new partition, run the following command:

    mkpart primary 215GB 100%
    

    c. Run the print command to check whether the partition is created.
    d. Run the quit command to exit the parted utility.
    The following figure shows the output.
    image.png

  4. 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 5.
    image.png

  5. 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.

  6. 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
    
  7. 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
    
  8. 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.

问题反馈