没有不值得去解决的问题,也没有不值得去学习的技术!

How to Expand an Alibaba Cloud ECS Disk In Place

Format the disk, use the resize2fs command to expand the file system size, existing data will not be lost

1. After expanding the disk via the console and restarting the instance, check the cloud disk capacity in the console:

After expanding the disk via the console and restarting the instance, check the cloud disk capacity in the console
After expanding the disk via the console and restarting the instance, check the cloud disk capacity in the console

2. Check the disk space usage, including data disks that are not yet mounted, using the following commands:
df -h
fdisk -l
Friendly reminder: If you run the fdisk -l command and do not see /dev/xvdb, it means your cloud server has no data disk. In that case, you do not need to mount anything, and this tutorial does not apply to you.

3. From steps 1 and 2, we find:

/dev/xvdb: 21.5 GB

/dev/xvdb1      9.9G

/dev/xvdb1 needs to be changed to 20 GB to indicate a successful expansion.

/dev/xvdb1 needs to be changed to 20 GB to indicate a successful expansion
/dev/xvdb1 needs to be changed to 20 GB to indicate a successful expansion

4. If your disk was previously mounted on the server, unmount it first.

umount /dev/xvdb1

Note: umount /var/www should also work (Alibaba Cloud official documentation recommends using this command).

Error:

umount: /var/www: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))

umount: /var/www: device is busy.
umount: /var/www: device is busy.

5. This means a program is currently using the disk. You can run lsof /dev/xvdb1 or fuser -mv /dev/xvdb1 to see which process is occupying it, as shown in the figure below:

I found a bash process with PID 18786, a cosplash process with PID 1291, and a soffice.bin process with PID 1308 occupying it. You can then stop the corresponding services or kill the corresponding processes to successfully unmount the disk.

If there is only a single bash process, it usually means a user is logged in within this directory. Simply navigating out of this directory will resolve it.

Execute the following commands in sequence:
lsof /dev/xvdb1

fuser -mv /dev/xvdb1

lsof /dev/xvdb1

After one user logged out, the bash process was gone;

This means a program is currently using the disk. You can run lsof /dev/xvdb1 or fuser -mv /dev/xvdb1 to see which process is occupying it
This means a program is currently using the disk. You can run lsof /dev/xvdb1 or fuser -mv /dev/xvdb1 to see which process is occupying it

6. The results show that a process is currently occupying the mounted data disk, preventing it from being unmounted. You can forcefully terminate the process occupying the data disk with the following commands:

Execute in sequence:
kill -9 1291

kill -9 1308

Forcefully terminate the process occupying the data disk
Forcefully terminate the process occupying the data disk

7. Execute again:

umount /dev/xvdb1

Success;

7. Execute again: umount /dev/xvdb1 Success;
7. Execute again:
umount /dev/xvdb1
Success;

8. Delete the original partition and create a new one.
Execute:
fdisk /dev/xvdb
to partition the data disk;
Following the prompts, enter in sequence:

d
n
p
1
Press Enter twice
wq
The partitioning will begin and finish very quickly.

Delete the original partition and create a new one
Delete the original partition and create a new one

9. Check the new partition.
Use:
fdisk -l
You can see that the new partition xvdb1 has been successfully created.

10. Format the disk.

Use the resize2fs command to expand the file system size; existing data will not be lost.

e2fsck -f /dev/xvdb1
resize2fs /dev/xvdb1

Format the disk, use the resize2fs command to expand the file system size, existing data will not be lost
Format the disk, use the resize2fs command to expand the file system size, existing data will not be lost

11. Mount the disk.

Finally, we mount the expanded disk back to its original mount point.

mount /dev/xvdb1 /var/www

Mount the expanded disk back to its original mount point
Mount the expanded disk back to its original mount point

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系