This help guide explains how to expand the disk capacity of a Linux cloud server. When we upgrade the cloud server's disk to a larger capacity, the system does not automatically expand the disk size. These steps are required to complete the expansion. This guide is applicable to operating systems like CentOS, Ubuntu, Debian, etc.
First, remotely log in to the Linux cloud server and use the fdisk command to view the disk partition status. As shown in the following figure, you can see that this cloud server has three disks: /dev/vda, /dev/vdb, and /dev/vdc, each with a size of 21.5G. The system disk /dev/vda has already created the /dev/vda1 partition, while the other two data disks have not yet created partitions.
fdisk -l
1.Install the growpart Tool
Some cloud server images come with growpart pre-installed. For others, follow these steps to install it.
yum install -y epel-release
yum install -y cloud-utils
apt-get install cloud-initramfs-growroot
2.Expand the Partition Table
Execute the following command to expand the partition table of the system disk /dev/vda. For CentOS 6 and Debian 8 operating systems, you may encounter a kernel that does not support hot-reloading of the partition table. In this case, after expanding the partition table, a restart of the operating system is required.
LANG=en_US.UTF-8
growpart /dev/vda 1
3.Expand the File System
For xfs file system (default in CentOS 7)
xfs_growfs /
For ext4 file system (default in CentOS 6)
resize2fs /dev/vda1
4.Confirm Completion of Expansion
Use the df command to check if the Avail column for the /dev/vda1 partition has expanded to the new capacity.
df -lh
If there were no data disks before changing configurations, and data disks were created after, follow these steps to create and mount the data disks. Assume the data disk is mounted to the /data directory.
mkfs.xfs /dev/vdb
mount -t xfs /dev/vdb /data
Edit /etc/fstab and add the following content.
/dev/vdb /data xfs defaults,noatime 0 0
mkfs -t ext4 /dev/vdb
mount /dev/vdb /data/
Edit /etc/fstab and add the following content.
/dev/vdb /data ext4 defaults,noatime 0 0
If the data disk already existed before changing configurations and has been upgraded, follow these steps to expand the data disk. Assume the data disk is mounted to the /data directory.
First, use the df command to check the file system type of the data disk, and execute the corresponding expansion command based on the file system type.
df -ihT
For xfs file system (default in CentOS 7)
xfs_repair /dev/vdb
xfs_growfs /data
For ext4 file system (default in CentOS 6)
e2fsck -f /dev/vdb
resize2fs /dev/vdb
23-02-2024 02:02:07
22-02-2024 03:19:32
22-02-2024 03:16:03
22-02-2024 03:14:03
22-02-2024 03:11:58