Linux  ·  medium  ·  Storage, filesystems & NFS

A disk was enlarged but the filesystem is still the old size

Enlarging a virtual disk changes the block device. The partition, the LVM layers and the filesystem each have to be grown separately, in order.

What you see

The hypervisor shows a 200GB disk and df still shows 50GB. Nothing appears to have happened.

What is actually wrong

Four layers — disk, partition, physical volume, logical volume, filesystem — and each must be told about the new size in sequence.

Codes and articles

resize2fsxfs_growfsgrowpartpartprobeno space left after resize

Fixes (2)

Grow every layer in order
Root shell25 minutesmedium risknot reversible

LVM. Each command below only does one layer, which is why partial attempts appear to fail.

  1. Confirm the kernel has seen the new size. If it has not, nothing else will work.

    Shell
    lsblksudo dmesg -T | tail -5
  2. Rescan the device if the new size is not visible, which avoids a reboot.

    Shell
    echo 1 | sudo tee /sys/class/block/sda/device/rescan
  3. Grow the partition. growpart handles the alignment and the GPT backup header correctly.

    Shell
    sudo growpart /dev/sda 3sudo partprobe /dev/sda

    Doing this by hand in fdisk means deleting and recreating the partition at the same start sector. It works, and one mistyped start sector destroys the filesystem. growpart is the safe equivalent.

  4. Grow the physical volume.

    Shell
    sudo pvresize /dev/sda3sudo pvs
  5. Grow the logical volume and the filesystem together.

    Shell
    sudo lvextend -r -l +100%FREE /dev/vg0/root

    The -r flag resizes the filesystem in the same command, choosing resize2fs or xfs_growfs as appropriate. It removes the most commonly forgotten step.

  6. Confirm.

    Shell
    df -h /sudo lvs
Confirm it workeddf shows the new size and the filesystem is still mounted read-write.
Shell
df -h; lsblk
If you need to undo itGrowing is not reversible. Snapshot the virtual machine before starting.
Grow a partition and filesystem with no LVM
Root shell25 minuteshigh risknot reversible

No LVM — common on cloud images.

  1. Snapshot the machine first. There is no undo below this line.

  2. Check the layout and which partition needs growing.

    Shell
    lsblksudo parted /dev/sda print free
  3. Grow the partition.

    Shell
    sudo growpart /dev/sda 1sudo partprobe /dev/sda
  4. Grow the filesystem. ext4 and XFS use different tools, and XFS can only grow while mounted.

    Shell
    sudo resize2fs /dev/sda1        # ext4sudo xfs_growfs /               # xfs, by mountpoint

    xfs_growfs takes a mount point, not a device, and refuses to work on an unmounted filesystem — the opposite of what most people expect from a resize tool.

  5. If growpart is unavailable, install cloud-guest-utils rather than editing the partition table by hand.

    Shell
    sudo apt install cloud-guest-utils || sudo dnf install cloud-utils-growpart
Confirm it workeddf shows the new size.
Shell
df -h
If you need to undo itRestore the snapshot taken beforehand.

Where this stops. This write-up was written and checked by hand. It says what each step changes, how to confirm it worked and how to reverse it, and anything destructive is flagged before you reach it. If it does not match what your machine is doing, search the Support Centre for the exact code or message — and when something needs a person, get in touch.