This guide explains how to expand the file system on a Vultr cloud server instance. If you have upgraded your cloud server to a plan with a larger disk or need to expand a partition while preserving data, follow these steps. A cloud server instance is sometimes called a Virtual Private Server or VPS.
This guide uses Ubuntu 20.04 as an example but applies to any Linux distribution with the fdisk and resize2fs tools. The example server has a 10 GB virtual disk with two partitions:
The virtual disk vda is 10 GB.
The first partition vda1 is 6 GB.
The second partition vda2 is 4 GB.
# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 252:0 0 10G 0 disk ├─vda1 252:1 0 6G 0 part / └─vda2 252:2 0 4G 0 part
As an example, this guide will remove the second partition (vda2), then expand the first partition (vda1) to fill the virtual disk. This will preserve all data on vda1 and delete all data on vda2.
Use this example as a general guide for your particular situation.
1. Make a Backup
⚠ NOTE: These operations make destructive changes to the cloud server’s file system. You can lose data if you make a mistake following these directions. Make a snapshot of the server before performing any of these steps. If your data is critical, please test the snapshot before proceeding. Deploy a new test instance with the snapshot, then verify the test instance boots and has the correct data.
2. Use a Bootable Rescue ISO
Boot your server with one of our rescue ISOs so you can work on your server while the partitions are dismounted. Do not attempt these steps while your server is running normally. See our guide “Troubleshoot your VPS with Bootable ISOs” for more details.
3. Inspect the Partition Table
Use fdisk -l to view the partition table. Make a note of the partition start and end sectors.
# fdisk -l Disk /dev/vda: 10 GiB, 10737418240 bytes, 20971520 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0xce0993d2 Device Boot Start End Sectors Size Id Type /dev/vda1 2048 12584959 12582912 6G 83 Linux /dev/vda2 12584960 20971519 8386560 4G 83 Linux
4. Remove the Second Partition
Launch fdisk using virtual disk /dev/vda:
# fdisk /dev/vda Welcome to fdisk (util-linux 2.34). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help):
Enter i to get information about the second partition.
Command (m for help): i
Enter 2 to view the second partition. Make sure this is the partition you want to delete.
Partition number (1,2, default 2): 2 Device: /dev/vda2 Start: 12584960 End: 20971519 Sectors: 8386560 Cylinders: 8321 Size: 4G Id: 83 Type: Linux Start-C/H/S: 819/2/1 End-C/H/S: 614/3/5
Enter d to delete a partition.
Command (m for help): d
Enter 2 to delete the second partition.
Partition number (1,2, default 2): 2 Partition 2 has been deleted.
5. Delete the First Partition
Enter p to print the partition table. Make a note of the start sector, and the partition information is as expected.
Command (m for help): p Disk /dev/vda: 10 GiB, 10737418240 bytes, 20971520 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0xce0993d2 Device Boot Start End Sectors Size Id Type /dev/vda1 2048 12584959 12582912 6G 83 Linux
Enter d to delete /dev/vda1. This command removes the partition but doesn’t overwrite the data.
Command (m for help): d Selected partition 1 Partition 1 has been deleted.
6. Create a New Partition
Follow these steps to create a new partition, which preserves the data if you use the same start sector and don’t remove the existing ext4 signature.
Enter n to create a partition.
Command (m for help): n
Enter p to create a primary partition.
Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p
Enter 1 to create partition 1.
Partition number (1-4, default 1): 1
Enter the same first sector. Use the same value as the old vda1 partition, which is 2048 in this example.
First sector (2048-20971519, default 2048): 2048
Enter the last sector. The default value fills the entire available space. Type Enter unless you need to enter a smaller value. Use a value at least as large as the old vda1 partition.
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-20971519, default 20971519): 20971519 Created a new partition 1 of type 'Linux' and of size 10 GiB.
Don’t remove the ext4 signature. Enter n and Enter.
Partition #1 contains a ext4 signature. Do you want to remove the signature? [Y]es/[N]o:
7. Write the Changes to Disk
Enter w to write the partition table to disk.
Command (m for help): w The partition table has been altered. Syncing disks.
Refresh the partition table with partprobe.
# partprobe
Check your work with lsblk.
# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 1024M 0 rom vda 252:0 0 10G 0 disk └─vda1 252:1 0 10G 0 part /
8. Resize the File System
Use resize2fs to expand the file system size to fill the new partition.
# resize2fs /dev/vda1 resize2fs 1.45.5 (07-Jan-2020) Filesystem at /dev/vda1 is mounted on /; on-line resizing required old_desc_blocks = 2, new_desc_blocks = 2 The filesystem on /dev/vda1 is now 2621184 (4k) blocks long.
Check the size of the file system with human-readable values.
# df -h / Filesystem Size Used Avail Use% Mounted on /dev/vda1 9.4G 2.6G 6.3G 30% /
Next Steps
Reboot the server, and verify the data is preserved. If you added or removed partitions, you may need to adjust the mount points in /etc/fstab. Refer to the Ubuntu fstab documentation or the documentation specific to your distribution.
Reference