Extend a disk or volume
The step-by-step for the most common disk task: the VM disk got bigger, now make / or /data use the space.
Which case are you?
Run lsblk -f and sudo vgs and pick the case:
| Situation | Go to |
|---|---|
vgs shows free space (VFree greater than 0) | Case A: just extend the LV |
| You enlarged the virtual disk in the hypervisor | Case B: disk, partition, PV, LV |
| You added a new, second disk | Case C: add it to the pool |
| No LVM, plain partition | Case D |
Remember the rule from the concepts page: grow bottom-up, the file system last. Everything here works online, no reboot or unmount needed.
Case A: free space in the volume group
Very common after a default Ubuntu install, which leaves part of the disk unused.
sudo lvextend -r -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
df -h /
-r grows the file system too. Use -L +20G instead of -l +100%FREE to add a fixed amount.
Case B: the virtual disk got bigger
Example: sda was 50 GB, you made it 80 GB in VMware/Proxmox/Hyper-V. LVM PV is sda3.
# 1. let the kernel see the new size (or reboot)
echo 1 | sudo tee /sys/class/block/sda/device/rescan
# 2. grow the partition into the new space (note the space before 3)
sudo growpart /dev/sda 3
# 3. tell LVM the PV got bigger
sudo pvresize /dev/sda3
# 4. grow the volume and the file system
sudo lvextend -r -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
df -h /
growpart is in the cloud-guest-utils package (installed on Ubuntu Server by default). For NVMe disks: sudo growpart /dev/nvme0n1 3, PV /dev/nvme0n1p3.
Note:
growpartonly works if the partition is the last one on the disk. Otherwise use Case C with a new disk.
Case C: a new disk
sudo pvcreate /dev/sdb # whole disk as PV
sudo vgextend ubuntu-vg /dev/sdb # add to the pool
sudo lvextend -r -l +100%FREE /dev/ubuntu-vg/ubuntu-lv # grow
Case D: no LVM, plain partition
echo 1 | sudo tee /sys/class/block/sdb/device/rescan
sudo growpart /dev/sdb 1
sudo resize2fs /dev/sdb1 # ext4
# or: sudo xfs_growfs /data # XFS takes the mount point
Grow only the file system
If you resized the LV without -r and df still shows the old size:
| File system | Command |
|---|---|
| ext4 | sudo resize2fs /dev/ubuntu-vg/ubuntu-lv |
| XFS | sudo xfs_growfs / (mount point) |
| Btrfs | sudo btrfs filesystem resize max / |
Check
lsblk # disk, partition and LV sizes
sudo vgs # VFree should now be 0
df -h # the file system size you actually get