How to Expand a Linux VPS Disk After Increasing Its Size
When you upgrade the storage capacity of a Linux VPS, the additional disk space may not immediately become available to the operating system.
Although the virtual disk has been expanded at the hypervisor level, Linux may still use the original partition and filesystem sizes.
This guide explains how to expand a Linux VPS disk after increasing its storage capacity, including how to resize the root partition, extend ext4 and XFS filesystems, and manage Linux swap.
The first procedure covers the partition layout commonly used by Owned Networks KVM VPS servers.
A second section provides instructions for other Linux configurations, including LVM, SCSI disks, NVMe devices, and alternative partition layouts.
Before You Begin
You will need:
- A Linux VPS with root or sudo access.
- A virtual disk that has already been expanded through the hosting provider or hypervisor.
- SSH or console access to the virtual machine.
- A verified backup or recoverable VM snapshot.
- Basic familiarity with Linux commands.
Important: Modifying partition tables carries a risk of data loss. Verify the disk layout and create a recoverable backup before proceeding.
Although many Linux filesystems support online expansion, certain partition-table changes may require a reboot.
Part 1: Expand an Owned Networks KVM VPS Disk
This section covers the disk layout commonly found on Owned Networks KVM VPS installations.
These virtual machines typically use a VirtIO block device named /dev/vda, with a standard ext4 root filesystem and a small swap partition.
1. Identify the Current Disk Layout
Connect to your VPS through SSH as root or using an account with sudo privileges.
Display the disk layout:
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS
A typical Owned Networks KVM VPS may display:
NAME SIZE TYPE FSTYPE MOUNTPOINTS
vda 30G disk
├─vda1 1M part
├─vda2 29.9G part ext4 /
└─vda3 128M part swap [SWAP]
The partitions have the following purposes:
| Device | Purpose |
|---|---|
/dev/vda |
Primary virtual disk |
/dev/vda1 |
BIOS boot partition |
/dev/vda2 |
Root filesystem (ext4) |
/dev/vda3 |
Linux swap partition |
Check the detailed partition table:
fdisk -l /dev/vda
Pay particular attention to the Start sector of the root partition.
For example:
Device Start End Sectors Size Type
/dev/vda1 2048 4095 2048 1M BIOS boot
/dev/vda2 4096 62649855 62645760 29.9G Linux filesystem
/dev/vda3 62649856 62911999 262144 128M Linux swap
In this example, /dev/vda2 begins at sector 4096.
Critical: When recreating the root partition, its starting sector must remain exactly the same. Your server may use a different starting sector, so always record the actual value.
2. Verify That Linux Recognizes the Expanded Disk
Check the total disk capacity:
lsblk -d -o NAME,SIZE,TYPE
Alternatively:
fdisk -l /dev/vda
The complete disk should report the new capacity assigned by your hosting provider.
For example, if your disk was upgraded from 30 GB to 50 GB, /dev/vda should now report approximately 50 GB.
The root filesystem may still report its previous size.
This is expected until the partition and filesystem are expanded.
Important: If the complete disk still reports its original capacity, do not continue with partition modifications.
Verify that the storage expansion has been applied successfully at the hypervisor level.
VirtIO block devices commonly used by KVM virtual machines may detect disk capacity changes automatically when the hypervisor applies the expansion.
Not all VirtIO block devices provide a writable sysfs rescan interface.
For example, the following path may not exist:
/sys/class/block/vda/device/rescan
This is normal for some virtio_blk configurations and does not necessarily indicate a problem.
3. Understand Why the Swap Partition Must Be Removed
In the typical partition layout, the swap partition is located immediately after the root partition.
/dev/vda
│
├── /dev/vda1 BIOS boot
├── /dev/vda2 Root filesystem
├── /dev/vda3 Swap
└── Unallocated space
Because the swap partition is located after the root partition, the root partition cannot expand directly into the additional disk space.
The simplest approach for this specific layout is to:
- Disable the existing swap partition.
- Remove the swap partition from the partition table.
- Recreate the root partition using its original starting sector.
- Extend the root partition to occupy the available disk space.
- Grow the ext4 filesystem.
- Create a new swap file.
This eliminates the need to move the swap partition.
4. Back Up the Partition Table
Before modifying the disk, save the current partition table.
mkdir -p /root/disk-resize-backup
sfdisk -d /dev/vda \
> /root/disk-resize-backup/vda-before.sfdisk
Back up the filesystem mount configuration:
cp -a /etc/fstab \
/root/disk-resize-backup/fstab.before
For GPT disks, you can also save the GPT metadata using:
sgdisk --backup=/root/disk-resize-backup/vda-before.gpt /dev/vda
The sgdisk command is provided by the gdisk package.
These backups preserve partition metadata and configuration information.
Important: They do not replace a full VM backup or recoverable snapshot.
5. Check Swap and Boot Configuration
Before disabling swap, inspect the current configuration:
swapon --show
cat /etc/fstab
cat /proc/cmdline
blkid /dev/vda2
blkid /dev/vda3
Check whether the system references the swap partition by UUID, device name, or partition UUID.
Also verify that the system does not depend on the swap partition for hibernation or resume functionality.
Most standard VPS installations do not use hibernation, but this should be verified before removing the partition.
If the root filesystem is referenced by PARTUUID, record that value because recreating a GPT partition may change its partition UUID.
6. Disable the Existing Swap Partition
Disable active swap:
swapoff -a
Verify:
swapon --show
The command should return no active swap devices.
Important: Disabling swap requires sufficient available RAM to accommodate any swapped-out memory.
Check memory availability before running swapoff:
free -h
If the system is under memory pressure, perform this operation during a maintenance window.
7. Recreate the Root Partition with fdisk
Open the partition editor:
fdisk /dev/vda
We will remove the existing swap partition and recreate the root partition while preserving its original starting sector.
Warning: The following procedure assumes the partition layout described above. Do not use these partition numbers on a server with a different layout.
Step A: Delete the Swap Partition
Inside fdisk, enter:
d
3
This removes partition 3 from the pending partition-table changes.
If fdisk automatically selects partition 3, it may not ask for the partition number.
Step B: Delete the Existing Root Partition Entry
Enter:
d
2
This removes the existing root partition entry from the pending partition table.
Important: At this stage, the filesystem data has not been erased. However, writing an incorrect replacement partition table can make the filesystem inaccessible.
Step C: Recreate the Root Partition
Create a new partition:
n
Select partition number:
2
Enter the original starting sector.
For the example layout:
4096
Critical: Use the original starting sector recorded from your own disk. Do not assume every Linux VPS uses sector 4096.
When prompted for the last sector, press Enter to accept the default maximum available sector.
This extends the partition to occupy the remaining usable disk space.
Step D: Preserve the Existing ext4 Filesystem
If fdisk detects an existing filesystem signature, it may display a message similar to:
Partition #2 contains an ext4 signature.
Do you want to remove the signature? [Y]es/[N]o:
Answer:
N
Never remove the existing ext4 signature when resizing a partition containing data you intend to preserve.
Step E: Verify the Partition Table Before Saving
Display the pending partition layout:
p
Confirm that:
/dev/vda1remains unchanged./dev/vda2uses the original starting sector./dev/vda2extends to the end of the available disk./dev/vda3no longer exists.- The root partition has the appropriate Linux filesystem partition type.
If anything is incorrect, enter:
q
This exits without saving the pending changes.
If the layout is correct, save it:
w
Important: Recreating a GPT partition can generate a new PARTUUID. If your boot configuration uses the original PARTUUID, restore the original partition GUID or update the relevant boot references before rebooting.
8. Verify That the Kernel Recognizes the New Partition Size
After saving the partition table, check the partition sizes:
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS
Check the root partition size directly:
blockdev --getsize64 /dev/vda2
If the root partition reports its expanded capacity, continue to the filesystem expansion step.
If the kernel still reports the old partition size, try updating the kernel's partition information:
partx -u -n 2 /dev/vda
Verify again:
lsblk
Important: If the kernel cannot adopt the updated partition boundaries, stop.
Do not run filesystem expansion against stale partition geometry.
A reboot may be required before the new partition boundaries become active.
9. Expand the ext4 Root Filesystem
Once Linux recognizes the expanded root partition, grow the ext4 filesystem:
resize2fs /dev/vda2
Modern ext4 filesystems support online expansion while mounted.
Verify the new filesystem capacity:
df -hT /
The root filesystem should now reflect the additional storage.
For example:
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda2 ext4 49G 8.0G 39G 18% /
The exact usable capacity depends on the virtual disk size and filesystem metadata.
10. Create a Replacement Swap File
Because the original swap partition was removed, create a swap file on the expanded root filesystem.
For a small VPS, a 512 MiB swap file may be an appropriate starting point, depending on available RAM and workload.
Create the file:
fallocate -l 512M /swapfile
Restrict access:
chmod 600 /swapfile
Initialize the swap area:
mkswap /swapfile
Enable swap:
swapon /swapfile
Verify:
swapon --show
free -h
The output should show the new swap file.
Note: This example assumes the root filesystem is ext4. Swap files on other filesystems, particularly Btrfs, may require additional configuration.
11. Make the Swap File Persistent
Open the filesystem mount configuration:
nano /etc/fstab
Locate the entry referencing the previous swap partition.
For example:
UUID=old-swap-uuid none swap sw 0 0
Comment it out:
# UUID=old-swap-uuid none swap sw 0 0
Add the new swap file:
/swapfile none swap sw 0 0
Save the file.
Verify the configuration:
findmnt --verify
swapon --show
Check for stale swap or resume references:
cat /proc/cmdline
grep -R 'resume=' /etc/default/grub /etc/initramfs-tools/conf.d/ 2>/dev/null
If the system previously used the deleted swap partition as a resume device, update the relevant configuration before rebooting.
12. Verify the Final Disk Layout
Run:
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS
The expected partition layout is:
NAME SIZE TYPE FSTYPE MOUNTPOINTS
vda 50G disk
├─vda1 1M part
└─vda2 50G part ext4 /
Check the root filesystem:
df -hT /
Verify swap:
swapon --show
Expected:
NAME TYPE SIZE
/swapfile file 512M
Verify the mount configuration:
findmnt --verify
The root filesystem should now use the expanded disk capacity, with swap provided by a file rather than a dedicated partition.
13. Important Considerations Before Rebooting
Before restarting the VM, confirm that:
- The root filesystem is mounted and functioning normally.
- The root partition retains its original starting sector.
- The ext4 filesystem was expanded successfully.
- The new swap file is active.
- The old swap partition entry has been removed or disabled in
/etc/fstab. - Boot configuration references remain valid.
- No stale resume configuration references the deleted swap partition.
- A recoverable backup remains available.
Keep the backup or snapshot until the VM has successfully rebooted and its storage configuration has been verified.
Part 2: Expanding Disks on Other Linux Configurations
Not every Linux VPS uses the partition layout described above.
Depending on the distribution, installation method, and virtualization platform, your server may use standard partitions without swap, LVM, XFS, NVMe storage, or SCSI disks.
The following procedures cover these alternative configurations.
14. Identify Your Disk and Filesystem
Start by examining the disk layout:
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS
Identify the root filesystem:
findmnt -no SOURCE,FSTYPE,TARGET /
Common disk naming conventions include:
| Disk Type | Disk Device | Partition Example |
|---|---|---|
| VirtIO Block | /dev/vda |
/dev/vda2 |
| SCSI / SATA | /dev/sda |
/dev/sda2 |
| NVMe | /dev/nvme0n1 |
/dev/nvme0n1p2 |
Always substitute the correct disk and partition names for your system.
15. Rescan a SCSI Disk Without Rebooting
If the hypervisor has expanded the disk but Linux still reports the previous capacity, a disk rescan may be necessary.
For a SCSI disk such as /dev/sda:
echo 1 > /sys/class/block/sda/device/rescan
Verify the new capacity:
lsblk -d -o NAME,SIZE,TYPE
Important: This method is intended for devices exposing the appropriate SCSI rescan interface.
It does not universally apply to VirtIO block devices such as /dev/vda.
For VirtIO block devices, the hypervisor may notify the guest automatically when the disk capacity changes.
If the disk still reports its original size, verify that the expansion was applied to the correct virtual disk at the hypervisor level.
16. Expand a Standard Partition Without Trailing Swap
If your root partition is followed directly by unallocated space, the expansion process is simpler.
Example:
/dev/vda
├── /dev/vda1 /boot
├── /dev/vda2 /
└── Unallocated space
Install growpart.
Ubuntu or Debian:
apt update
apt install -y cloud-guest-utils
AlmaLinux or Rocky Linux:
dnf install -y cloud-utils-growpart
Preview the expansion:
growpart -N /dev/vda 2
If the proposed boundaries are correct:
growpart /dev/vda 2
Verify that the kernel recognizes the new partition size:
lsblk
For ext4:
resize2fs /dev/vda2
For XFS mounted at /:
xfs_growfs /
Verify:
df -hT /
17. Expand a Partition on /dev/sda
For a SCSI or SATA disk, the procedure is similar.
For example, if the root filesystem is located on /dev/sda2:
growpart -N /dev/sda 2
After reviewing the proposed change:
growpart /dev/sda 2
For ext4:
resize2fs /dev/sda2
For XFS:
xfs_growfs /
These commands assume that contiguous unallocated space exists after the target partition.
18. Expand an NVMe Partition
NVMe disks use a different device naming convention.
For example:
/dev/nvme0n1
└── /dev/nvme0n1p2
Preview the partition expansion:
growpart -N /dev/nvme0n1 2
Apply the change:
growpart /dev/nvme0n1 2
For ext4:
resize2fs /dev/nvme0n1p2
For XFS mounted at /:
xfs_growfs /
Verify:
df -hT /
19. Expand a Linux Disk Using LVM
Some Linux distributions use Logical Volume Manager (LVM) for the root filesystem.
A typical layout may look like:
/dev/vda
├── /dev/vda1 /boot
└── /dev/vda2 LVM
└── Volume Group
└── Logical Volume
└── Root Filesystem
Identify the LVM configuration:
pvs
vgs
lvs
lsblk -f
If the LVM physical volume is located on /dev/vda2, expand the partition first:
growpart -N /dev/vda 2
After verifying the proposed change:
growpart /dev/vda 2
Resize the physical volume:
pvresize /dev/vda2
Check the volume group:
vgs
Extend the appropriate logical volume using the available free space:
lvextend -r -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
Replace the example logical volume path with the actual path from your system.
The -r option attempts to resize the filesystem automatically.
Important: The +100%FREE option allocates all currently available free space in the volume group to the selected logical volume.
Verify:
pvs
vgs
lvs
df -hT /
20. Expand LVM When the Physical Volume Uses the Entire Disk
Some LVM configurations use the complete disk directly, without a partition table.
For example:
/dev/vda
└── LVM Physical Volume
└── Volume Group
└── Logical Volume
In this configuration, partition expansion is unnecessary.
After the operating system recognizes the expanded disk:
pvresize /dev/vda
Then extend the logical volume:
lvextend -r -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
Verify:
df -hT /
21. Expand an XFS Filesystem
XFS filesystems support online growth.
After expanding the underlying partition or logical volume, identify the filesystem mount point:
findmnt -no SOURCE,FSTYPE,TARGET /
For an XFS root filesystem:
xfs_growfs /
Verify:
df -hT /
Important: XFS filesystems cannot be shrunk using standard XFS utilities.
22. Repair GPT Backup Header Location After Disk Expansion
After expanding a GPT-formatted virtual disk, Linux may report:
GPT PMBR size mismatch
Or:
The backup GPT table is not on the end of the device.
This can occur because the backup GPT metadata still references the disk's previous capacity.
Install GPT utilities if necessary:
apt install -y gdisk
Verify the partition table:
sgdisk -v /dev/vda
If the only relevant issue is the backup GPT header location, and you have a recoverable backup, relocate it:
sgdisk -e /dev/vda
Verify again:
sgdisk -v /dev/vda
Important: This command modifies GPT metadata. Do not use it as a general repair command for unrelated partition-table errors.
23. Troubleshooting Common Disk Expansion Problems
Linux Still Reports the Old Disk Capacity
Check:
lsblk -d -o NAME,SIZE,TYPE
fdisk -l /dev/vda
Verify that the hypervisor has applied the expansion to the correct virtual disk.
For supported SCSI devices, use the appropriate rescan interface.
For VirtIO block devices, confirm that the hypervisor has delivered the updated capacity to the guest.
The Partition Is Larger but the Filesystem Is Not
Check:
lsblk
df -hT /
If the partition has expanded but the ext4 filesystem has not:
resize2fs /dev/vda2
For XFS:
xfs_growfs /
growpart Reports NOCHANGE
This usually indicates that the partition cannot grow using the currently available contiguous space.
Inspect:
parted /dev/vda unit s print free
Check for another partition blocking the expansion.
The Kernel Cannot Reread the Partition Table
Some partition changes cannot be applied immediately while the root filesystem is mounted.
Verify the kernel's current partition size:
blockdev --getsize64 /dev/vda2
If the kernel still reports the old partition size, do not proceed with filesystem expansion.
A reboot may be required before the new partition boundaries become active.
Swap Is Missing After Resizing
Check:
swapon --show
cat /etc/fstab
Verify that the swap file exists, has appropriate permissions, and is configured correctly.
For an ext4-based VPS:
ls -lh /swapfile
stat -c '%a %n' /swapfile
Swap file permissions should normally be restricted to root.
24. Verify the Final Storage Configuration
After completing the expansion, run:
echo "=== DISKS ==="
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS
echo
echo "=== ROOT FILESYSTEM ==="
df -hT /
echo
echo "=== SWAP ==="
swapon --show
echo
echo "=== FILESYSTEM CONFIGURATION ==="
findmnt --verify
For LVM installations, also verify:
pvs
vgs
lvs
Confirm that the operating system now recognizes the expanded filesystem capacity.
25. Backup and Recovery Considerations
Before changing a production partition table, maintain a recoverable backup or snapshot.
For partition modifications, record:
- The original disk capacity.
- The original partition starting sectors.
- The original filesystem UUIDs and partition UUIDs.
- The original
/etc/fstabconfiguration. - The original boot configuration.
- The expected final disk capacity.
Keep the recovery point until the VM has successfully rebooted and all storage and swap configurations have been verified.
Important: Partition expansion is not generally reversible through a simple command.
Do not attempt to shrink a live root filesystem as a rollback procedure.
If a serious problem occurs, restore the verified VM backup or snapshot using the hosting platform's recovery procedure.
Related Linux VPS Tutorials
- How to Set Up and Secure a New Ubuntu VPS
- How to Set Up Automatic Backups on an Ubuntu VPS Using Restic
- How to Monitor CPU, RAM, Disk, and Network Usage on a Linux VPS
- How to Configure UFW Firewall on an Ubuntu VPS
Need More Storage for Your Linux VPS?
As websites, applications, databases, and backups grow, additional storage may become necessary.
Owned Networks KVM VPS hosting provides flexible virtual server resources and full root access, allowing you to configure your Linux environment according to your workload.
After increasing your virtual disk capacity, follow the appropriate partition and filesystem expansion procedure to make the additional space available inside Linux.
Explore Owned Networks VPS Hosting and discover scalable Linux hosting solutions.