Resize Linux Partition with LVM (via QEMU)
Grow three layers in order, the virtual disk, the partition under it, and the vgubuntu volume, without reinstalling the Ubuntu 20.04 guest
Overview
My QEMU guest ran out of disk space. I was trying out UTM ↗ as a lighter alternative to Parallels Desktop and learning QEMU’s tooling; the full disk became an excuse to work through the stack. Instead of reinstalling, I grew the disk through all three layers: the qcow2 virtual disk, the partition on it, and the LVM logical volume holding the filesystem. Done on an Ubuntu 20.04 mini install with the default LVM layout, following linuxtechi’s walkthrough ↗.
The order matters; each layer gates the next:
- Resize the virtual disk (QEMU only, optional)
- Resize the partition to claim the new space (GParted)
- Extend the logical volume and the filesystem (LVM)
Prerequisites
- An Ubuntu guest installed on LVM. My guest names its volume group
vgubuntuwith avgubuntu-rootlogical volume; other installs use different names (ubuntu-vg/ubuntu-lvon server installs), so check yours withvgdisplayand substitute throughout. - A GParted ↗ live image to move the partition boundaries offline.
- Root access inside the guest for the LVM steps.
Step 1: Resize the virtual disk (QEMU)
Skip this step if the disk is physical or already big enough; it only applies to a qcow2 backed by QEMU. From the host, while the guest is shut down:
# Read the drive filesystem
qemu-img info ubuntu-20.04-mini.qcow2
# Add 15G to the virtual size
# NOTE this is reflected in "virtual size"
qemu-img resize ubuntu-20.04-mini.qcow2 +15GshStep 2: Resize the partition (GParted)
Boot the guest from the GParted live image so the root filesystem is not mounted while it moves. Booting an entire live OS to drag one partition edge feels heavy-handed, but a mounted root filesystem cannot move under itself. This is the only step in the chain with real destructive potential.
- Open GParted and select the top-level physical device containing both root (
/) and boot (/boot), e.g./dev/sda. - Right-click the LVM partition, then resize, and drag over the unallocated space left by Step 1 so it joins the physical device.
Apply the operation. The partition now backs a larger LVM physical volume, but the volume group does not use the space yet.
Step 3: Extend the logical volume and filesystem
Back inside the guest, confirm the current usage and the volume group:
# Read the filesystem current size
# Alternatively, lsblk
df -h /home/
# Read the created Volume Group
# The name (here: vgubuntu) was chosen at installation
# NOTE this requires root
vgdisplay vgubuntushvgdisplay reports the free extent count, the budget lvextend can spend. The 15G added in Step 1 shows up here as free extents now that the partition claimed it. Grow the logical volume, then write the new size into the ext4 filesystem:
# Expand 20G for the specific Volume e.g. vgubuntu-root
lvextend -L +20G /dev/mapper/vgubuntu-root
# Apply and write new partitions to LVM
resize2fs /dev/mapper/vgubuntu-rootshresize2fs grows the mounted filesystem online; no reboot or unmount needed. Verify with df -h /home/ again.
Closing
The guest came back with its 15G and no reinstall. The layer handoffs are hard to learn from a Parallels-style slider that just makes the bar bigger.
Reference
- Extend LVM partitions ↗ on linuxtechi, the walkthrough these steps follow.