Packet Disarray

Despatches from longb4

Extending LVM Volume Size

I use LVM to manage virtual disks on my Xen hypervisor. It’s mostly “set it and forget it”, but occasionally, the virtual disks get close to filling up. (Monitoring this with Nagios gives me plenty of warning!) When I’d rather not go through the filesystems and choose what to delete, or when I’ve already done that and they’re still too full, it’s really convenient to be able to just extend the disk. For this reason, I try to keep at least 1 TB of space unallocated on my hypervisor’s main LVM volume group.


Let’s say I want to extend a 500 GB LV, which shows up as /dev/xvda5 on a virtual machine called guest. This LV is called storage on a hypervisor called host, and storage lives on a VG called hard-disk. I want to extend storage’s size to 750 GB.

First, I check that there’s enough free space on the VG (at least 250 GB, in this case):

host$ sudo vgdisplay hard-disk
--- Volume group ---
VG Name               hard-disk
System ID             
Format                lvm2
Metadata Areas        1
Metadata Sequence No  6
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                5
Open LV               5
Max PV                0
Cur PV                1
Act PV                1
VG Size               2.73 TiB
PE Size               4.00 MiB
Total PE              715396
Alloc PE / Size       460800 / 1.76 TiB
Free  PE / Size       254596 / 994.52 GiB

For safety, I shut down guest. (If guest were running FreeBSD rather than Debian, I would have used the -p flag rather than -h.)

guest$ sudo shutdown -h now

Once guest has been shut down, I extend storage’s LV size:

host$ sudo lvextend -L750G /dev/hard-disk/storage

The LV storage is just a block device. The filesystem on top of it (ext4) needs to be resized as well. But before that, I need to check the filesystem for errors:

host$ sudo e2fsck -f /dev/hard-disk/storage

Now I can extend the filesystem to cover the entire LV. If I skipped this step, the filesystem size wouldn’t be any different after starting guest back up again, despite the LV being larger.

host$ sudo resize2fs /dev/hard-disk/storage

Finally, I start up guest, which involves this in my case:

host$ sudo xm create /etc/xen/guest.cfg

Once guest is up, I can verify that storage and the filesystem were extended with df -h /dev/xvda5. On host, I can verify that the LV was extended with sudo lvdisplay /dev/hard-disk/storage.