preface

Recently I used Aliyun K8S to use ECS as its Node server, and cloud disk was 20G. Later, I released more and more services and found that the disk was not enough, so I expanded cloud disk to record and share it with everyone.

operation

There are two options for cloud disk expansion:

  • Buy a new cloud disk
  • We have cloud disk for capacity expansion

Next, I will explain the specific operation of the two ways.

Buy new cloud disks to expand space

First let’s explain how to buy a new cloud disk to expand disk space. The expansion method [Ali official]() has been given, let’s do it.

  1. Buy a new cloud disk
  2. Mount the new cloud disk to the ECS server
  3. Format cloud disk

1. Buy a new cloud disk

Just create it directly, as shown in the figure:

2. Mount the new cloud disk to the ECS server



If the state of the cloud disk is in use, the mount is successful.

3. Format cloud disk

Step 1: Create the MBR partition for the data disk

First: look at the data disk information on the instance,

fdisk -lu

Run the following commands in turn to create a partition. Run the following command to partition the data disk.

fdisk -u /dev/vdb

Type p to see the partitioning of the data disk.

In this example, the data disk has no partition.

Type n to create a new partition.

Type p to select the partition type primary partition.

Creating a single partition data disk can create only the primary partition. If you want to create more than four partitions, you should select E (Extended) at least once to create at least one extended partition.

Enter the partition number and press Enter.

In this example, just create a partition and press Enter directly, using the default value of 1.

Enter the first available sector number and press Enter.

In this example, press the Enter key directly, using the default value of 2048.

Enter the last sector number and press Enter.

In this example, just create a partition and press Enter directly, using the default values.

Enter P to view the planned partition of the data disk.

Enter w to start partitioning and exit when partitioning is complete.

The results are shown below.

Step 2: Create the file system for the partition

Create a file system on the new partition. Run any of the following commands according to your requirements to create the file system.

To create an ext4 file system, run the following command.

mkfs -t ext4 /dev/vdb1

Step 3: Configure the /etc/fstab file and mount the partition

Write the new partition information in /etc/fstab to start the boot auto-mount partition.

  1. Back up the etc/fstab file and run the following command:

    cp /etc/fstab /etc/fstab.bak
  2. Write the new partition in /etc/fstab. The root user can directly modify the /etc/fstab file by running the following command.

    echo `blkid /dev/vdb1 | awk '{print $2}' | sed 's/\"//g'` /mnt ext4 defaults 0 0 >> /etc/fstab
  3. Check /etc/fstab for new partition information. Run the following command:

    cat /etc/fstab

    The results are shown below.

  4. Mount the partition. Run the following command:

    mount /dev/vdb1 /mnt
  5. Check the mount results. Run the following command:

    df -Th

    The results are shown below. If the message of creating a new file system appears, the file system is successfully mounted.

There is room for cloud disk expansion

To expand the existing cloud disk, first go to the console and select the corresponding cloud disk for capacity purchase. After purchase, perform the following operations:

  1. Purchase existing cloud disk capacity
  2. Expanded Zoning (MBR)
  3. Expanded file system (ext4)

1. Purchase existing cloud disk capacity

Simply click on the existing cloud disk to enlarge the capacity.

2, expanded partition (MBR)

View the cloud disk status of the instance

fdisk -lu

To view the partitioned file system:

df -Th

We can see that /dev/vda1 is 80G in size and 20G in size, so we are going to scale partitions and filesystems.

  1. Install the GrowPart tool.

    yum install -y cloud-utils-growpart
    
  2. Run the following command to expand the partition.

    growpart /dev/vda 1

3. Expansion file system (ext4)

  1. Expand the file system with ext* (for example, ext4) : Run the following command to expand the file system. Expansion system disk /dev/vda1 file system.

    resize2fs /dev/vda1    
  2. Run the following command to check the results after capacity expansion.

    fdisk -lu
    df -Th

Question:

1. If you find that you have purchased cloud disk and run fdisk-lu without the following display, it means that your cloud disk has not been formatted successfully, and you need to execute the above command to expand the partition and file system.

conclusion

1. It is much more convenient to expand the existing cloud disk operation than to create a new cloud disk operation.

Linux is a MBR partition, and System is a GPT partition

Commands to view partitions and disks

fdisk -lu
df -Th

reference

Online expansion cloud disk mount data disk format data disk