arrow

Linux disk expansion experiment

1. Experiment

1.1 Knowledge points

This experiment demonstrates how to resize data disks for Alibaba Cloud ECS instances in the Ubuntu system.This is a common occurrence in the production environment. As a business grows, the capacity of the data disks on servers may be insufficient. In this case, you must resize the data disks.This experiment demonstrates how to resize a data disk on an ECS instance.

1.2 Experiment process

  • Log on to the ECS instance
  • Attach the data disk
  • Resize the data disk capacity
  • Online expansion system disk capacity

1.3 Cloud resources required

  • ECS

1.4 Prerequisites

  • If you’re using your own Alibaba Cloud account instead of the account provided by this lab to operate the experiment, please note that you’ll need to choose the same Ubuntu 16.04 operating system for your ECS in order to run the experiment smoothly.
  • Before starting the experiment, please confirm that the previous experiment has been closed normally and exited.

2. Start the experiment environment

Click Start Lab in the upper right corner of the page to start the experiment.

image desc.

After the experiment environment is successfully started, the system has deployed resources required by this experiment in the background, including the ECS instance, RDS instance, Server Load Balancer instance, and OSS bucket. An account consisting of the username and password for logging on to the Web console of Alibaba Cloud is also provided.

image desc

After the experiment environment is started and related resources are properly deployed, the experiment starts a countdown. You have two hours to perform experimental operations. After the countdown ends, the experiment stops, and related resources are released. During the experiment, pay attention to the remaining time and arrange your time wisely. Next, use the username and password provided by the system to log on to the Web console of Alibaba Cloud and view related resources:

openCole

Go to the logon page of Alibaba Cloud console.

image desc

Fill in the sub-user account and click Next.

image desc

Fill in the sub-user password and click Log on.

image desc

After you successfully log on to the console, the following page is displayed.

image desc

3. Log on to the ECS instance

Click Elastic Computer Service, as shown in the following picture.

image desc

We can see one running ECS instance in the US West 1 region. Click it to go to the ECS console as shown in the following picture.

image desc

Copy this ECS instance’s Internet IP address and remotely log in to this ECS (Ubuntu system) instance. For more information about remote login, see Logon.

image desc

The default account name and password of the ECS instance:

Account name: root

Password: nkYHG890..

4. Attach the data disk

Run the following command to view the disk partition table:

fdisk -l

image desc

As you can see, there are two disks. One is a 40 GB system disk that is already in use.

The other is a 20 GB data disk, which is not yet in use.

Run the following command to access the data disk and partition it:

fdisk /dev/vdb

image desc

Create a partition table as shown in the following figure. Then, save the table and exit.You can type “m” to learn about the functions of each command in the following figure.

image desc

Run the following command to view the disk partition table again. You will see that the data disk partition information is displayed.There is only one partition, which occupies the entire 20 GB of the data disk.

fdisk -l

image desc

Run the following command to create a file system on the new partition:

mkfs -t ext4 /dev/vdb1

image desc

Run the following command to create a mount directory:

mkdir -p /root/mns

image desc

Run the following command to mount the new partition to the directory you just created:

mount /dev/vdb1 /root/mns

image desc

Run the following command to view the mount information.As you can see, the new partition has been successfully mounted, and its size is 20 GB.This indicates that up to 20 GB of files can be stored in the /root/mns directory.

df -h

image desc

Run the “cd/root/mns” command to go to the mount directory.

Run the following command to create a file named “flag” with a size of 50 MB:

dd if=/dev/zero of=flag bs=10M count=5

image desc

5. Resize the data disk capacity

Refer to the figure below to reset the size of the data disk.

image desc

Check Resize Online (so that you don’t need to restart the instance to take effect), set it to 30 G, and click Confirm.

image desc

image desc

image desc

Go back to the command line interface and enter the following command to view the disk partition table again. It can be seen that the capacity of the data disk has increased to 30G, but the partition still shows only 20 G.

fdisk -l

image desc

Enter the following command to expand the partition.

growpart /dev/vdb 1

image desc

Enter the following command to expand the file system.

resize2fs /dev/vdb1

image desc

Enter the following command to view the mount status. You can see that the new partition has been successfully mounted and the size is 30 G. Indicates that the file can be stored in the /root/mns directory for up to 30 G. The data disk has been expanded.

df -h

image desc

Enter the following command and enter the mounted directory again. You can see that the previous data file is still there and will not be lost.

 cd /root/mns
 ls

image desc

6. Online expansion system disk capacity

Enter the following command to create a new file “labex.txt” to mark this system disk.

echo "this is a labex experiment" > /root/labex.txt

image desc

Then return to the Alibaba Cloud console and select the system disk.

image desc

Adjust the size to 60 G and click Confirm.

image desc

After the expansion is successful, go back to the ECS command line and enter the following command.

fdisk -l

df -h

image desc

image desc

As you can see, the system disk size has been expanded to 60 G, but currently only 40 G is valid on disk.

This is because partitions and file systems need to be extended on the system disk.

Enter the following command to expand the /dev/vda1 partition.

growpart /dev/vda 1

image desc

Enter the following command to expand the file system of the /dev/vda1 partition of the system disk.

resize2fs /dev/vda1

image desc

Enter the following command again and you can see that it has taken effect.

df -h

ls

image desc

You can see that the system disk has been expanded to 60 G.

Reminder:
Before you leave this lab, remember to log out your Alibaba RAM account before you click the ‘stop’ button of your lab. Otherwise you’ll encounter some issue when opening a new lab session in the same browser:

image descimage desc

7. Experiment summary

This experiment demonstrates how to resize a data disk on an ECS instance.Generally, data disks on servers must store more data as a business grows. In the past, you had to replace the physical data disks when you required more space. Now, Alibaba Cloud disks provide a quick and easy resizing function.