
Upgrading a cloud server to a larger plan increases the virtual disk size, but existing partitions may not resize automatically. This article explains how to resize the file system on a Linux cloud server and expand the root partition to utilize the full disk space.
This article uses a Ubuntu 24.04 instance but the included instructions apply to any Linux distribution with the fdisk and resize2fs tools installed. The example server has a 55 GB virtual disk after upgrade with the following partitions:
vda: The virtual disk with 55 GB.
vda1: The first partition (EFI) with 512 MB.
vda2: The second partition (root file system) with 24.5 GB.
The vda2 partition is 100% utilized with no free space based on the following df -h command output:
You will expand the second partition (vda2) to fill the virtual disk while preserving data on the partition. Use this example as a general guide depending on your particular situation.
Before you begin, ensure to:
Do not run the commands in this article directly in your active server session. Instead, boot the instance using a rescue ISO and apply the changes while the virtual disk is unmounted and not in use.
You may lose data if you make a mistake while following the instructions in this article. Ensure to take a snapshot of your instance to create a backup you can use to recover the server in case of any failures. In addition, avoid making any changes to the vda1 EFI boot partition.
Run the following fdisk -l command to inspect all disks and partitions on your server.
Note the start and end sectors of your target /dev/vda virtual disk partitions similar to the following output.
Follow the steps below to remove the vda2 partition without losing any existing data.
Run the following fdisk command to manage the /dev/vda virtual disk partitions.
Output:
Enter i to view information about a specific partition on the /dev/vda disk.
Enter 2 to view information about the second partition (vda2) you want to delete.
Note the start and end sectors in your output similar to the one below.
1050624 is the start sector, and 52428766 is the end sector for the vda2 partition, based on the output above.
Enter d to delete a partition.
Enter 2 to delete the second partition (vda2).
Output:
Follow the steps below to create a new partition and preserve data using the same start sector while keeping the existing ext4 signature.
Enter n to create a new partition.
Enter 2 to create the second partition.
Verify that the default first sector value matches your original vda2 partition value and press Enter. If the default value is different, enter your original vda2 start sector value instead.
Press Enter to use the suggested last sector value that fills the entire available disk space.
Output:
Enter n when prompted to remove the existing ext4 signature and press Enter.
Follow the steps below to write and apply the partition changes you performed in the previous steps to your virtual disk.
Enter w to write the partition changes to the disk.
Output:
Use the lsblk command to view the modified partition table of the disk.
Output:
Follow the steps below to test the file system of the second partition (vda2) and resize it to fill the new partition.
Check the vda2 partition for errors and corrupted nodes.
Enter y when prompted to fix any blocks on the partition similar to the output below.
Run the following resize2fs command to expand the file system and use the full size of the new vda2 partition.
Output:
Access your instance's management page, remove the rescue ISO, and reboot the instance. Then, follow the steps below to test the changes made to your server's disk partitions.
Run the following lsblk command in your server's terminal session to verify the new partition table.
Output:
Use the df -h command to view the disk usage information and verify that the vda2 partition is resized.
Your output should be similar to the below.
The vda2 partition usage is 47% as compared to 100% before resizing based on the above output.
You have resized your server's file system and preserved all existing data. If you added or removed partitions, adjust the mount points in the /etc/fstab file. For more information and disk resizing options, please visit the following documentation resources.
0 Comments
Be the first to comment and share your perspective with the community.