Expand LVM ext4 root filesystem
Sat, Aug 15, 2020 · 2 minute readlinuxlvm
On a basic Ubuntu Server install, an Oops moment:
# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv 7.9G 7.5G 21M 100% /
Fortunately there is free space in the volume group:
# vgs
VG #PV #LV #SN Attr VSize VFree
ubuntu-vg 1 7 0 wz--n- <1.72t <62.81g
Extend the logical volume by 10G
# lvextend -L +10G /dev/mapper/ubuntu--vg-ubuntu--lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from 8.00 GiB (2048 extents) to 18.00 GiB (4608 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
Update - LVM needs a small amount of free space to expand a LV. If there really is no free space then you might see this error:
# lvextend -L +10G /dev/ubuntu-vg/ubuntu-lv
/etc/lvm/archive/.lvm_srv05_21685_822342773: write error failed: No space left on device
In this case the simplest approach is to delete a few files to free up a very small amount of space,
e.g. remove old syslog files.
# rm /var/log/syslog.*gz
Resize the LVM path - on XFS we would grow the filesystem mount point.
# resize2fs /dev/ubuntu-vg/ubuntu-lv
resize2fs 1.44.6 (5-Mar-2019)
Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 3
The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 4718592 (4k) blocks long.
Check for errors.
# dmesg | grep EXT4
[12312064.327744] EXT4-fs (dm-0): resizing filesystem from 2097152 to 4718592 blocks
[12312064.755646] EXT4-fs (dm-0): resized filesystem to 4718592
Check filesystem size.
# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv 18G 7.4G 9.6G 44% /