CH-J Server Managerserver management over SSH
Menu
All guides and articles →

How to grow a Linux server disk without losing data

After enlarging a virtual disk, extend the partition, LVM and the ext4 or XFS file system in the right order.

Before you change anything

Create and test a backup or a snapshot of the virtual machine first. Growing is a routine operation, but a mistake in a device name can damage data, and a backup of the partition table is not a backup of your data. Then enlarge the disk in your hypervisor or at your hosting provider, because the system can only use space the disk already has.

Find out how the disk is laid out

Each layer has to be extended separately, from the bottom up: disk, partition, LVM if it is used, and file system. These commands show the layers, the file system types and which space is mounted where. Device names in the following examples are illustrations; use the ones from your own server.

lsblk -f
df -hT
sudo pvs; sudo vgs; sudo lvs

Partition and ext4 or XFS

growpart, from the cloud-guest-utils package on Ubuntu and Debian, extends a partition into the free space behind it. Note that the disk and the partition number are separate arguments. Then grow the file system: resize2fs for ext4 takes the device, xfs_growfs takes the mount point. Both work while the file system is mounted.

sudo growpart /dev/sda 2

# ext4
sudo resize2fs /dev/sda2

# XFS
sudo xfs_growfs /

With LVM

When the partition holds an LVM physical volume, tell LVM about the new size and extend the logical volume. The -r option also grows the file system on it, so no separate resize command is needed.

sudo growpart /dev/sda 3
sudo pvresize /dev/sda3
sudo lvextend -r -l +100%FREE /dev/ubuntu-vg/ubuntu-lv

Check the result and know the limits

Run df -hT again to confirm the new size. Growpart can only use free space directly behind the partition, so a swap or another partition in the way has to be dealt with first. XFS cannot be shrunk at all, and shrinking other file systems is a much riskier operation than growing them, so size the expansion with care.

Disk Manager in CH-J Server Manager

Disk Manager for Linux servers shows the disk map with partitions, file systems and LVM and LUKS layers, and can propose automatic expansion after a disk was enlarged. Changes wait in a queue that you review as a plan; before running it, the application reads the server state again and stops if it no longer matches. It saves partition table metadata before a change, which does not replace a backup of your data. Windows servers are detected and refused as unsupported.

Detailed documentation

man: resize2fs →

man: xfs_growfs →

man: lvextend →

Biometric unlock and security →