Preface

Recently, the use of Alibaba Cloud K8S requires ECS as its Node server, and the cloud disk is 20G. Later, more and more services released have found that the disk is not enough, so expand the cloud disk and record it and share it with everyone.

operating

There are two options for expanding cloud disks:

  • Buy a new cloud disk
  • Expand existing cloud disk

Below I will explain the specific operations of the two methods respectively.

Purchase a new cloud disk to expand the space

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

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

1. Purchase a new cloud disk

Just create it directly, as shown in the figure:

image.png

2. Mount the new cloud disk to the ECS server

image.png
image.png

If the state of the cloud disk becomes use , represents mount successfully.

3. Format cloud disk

Step 1: Create MBR partition for the data disk

First: check the data disk information on the instance,

fdisk -lu

image.png

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

fdisk -u /dev/vdb

Enter p to view the partition status of the data disk.
In this example, the data disk is not partitioned.
Enter n to create a new partition.
Enter p to select the partition type as the primary partition.
Note that when you create a single-partition data disk, you can only create 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, only one partition is created, press the Enter key directly, and the default value is 1.
Enter the first available sector number and press Enter.
In this example, directly press the Enter key and use the default value of 2048.
Enter the last sector number and press Enter.
In this example, only one partition is created, press the Enter key directly, and the default value is adopted.
Enter p to view the planned partition of the data disk.
Enter w to start partitioning, and exit after finishing partitioning.
The result of the operation is shown below.
image.png

Step 2: Create a file system for the partition

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

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

mkfs -t ext4 /dev/vdb1

image.png

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

Write the new partition information in /etc/fstab, and start to automatically mount the partition at boot.

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

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

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

    cat /etc/fstab

    The result of the operation is shown below.
    image.png

  4. Mount the partition.
    Run the following command:

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

    df -Th

    The result of the operation is as follows. If the message of creating a new file system appears, it means that the file system is mounted successfully.
    image.png

Existing cloud disk expansion space

If you want to expand an existing cloud disk, first go to the console to select the corresponding cloud disk for capacity purchase, and then perform the following operations after purchase:

  1. Purchase existing cloud disk capacity
  2. Expansion Partition (MBR)
  3. Expand the file system (ext4)

1. Purchase existing cloud disk capacity

Just click Expansion directly on the existing cloud disk.

image.png

2. Expansion Partition (MBR)

View the cloud disk status of the instance

fdisk -lu

image.png

View the partition file system:

df -Th

image.png

From the figure, we find that the size of /dev/vda1 is 80G and actually 20G, so we will expand the partition and expand the file system next.

  1. Install the growpart tool.

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

    growpart /dev/vda 1

    image.png

3. Expansion file system (ext4)

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

    resize2fs /dev/vda1    
  2. Run the following command to check the expansion result.

    fdisk -lu
    df -Th

    image.png

image.png

problem:

1. If you find that you have purchased a 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 commands to expand the partition and expand the file system.

image.png

to sum up

1. Expanding an existing cloud disk is much more convenient than creating a new cloud disk for expansion.

2. The value of System Linux is expressed as MBR partition, and the value of System GPT is expressed as GPT partition.

image.png

3. Commands to view partitions and disks

fdisk -lu
df -Th

Quote

Online expansion of cloud disk
mount data disk
Format data disk


Awbeci
3.1k 声望212 粉丝

Awbeci