I use Linux LVM as the storage subsystem for Xen virtual machines, for backups volumes, and for organizing storage volumes on NFS servers. It provides great flexibility and performance and the command-line tools included are easy to use.
There is however one operation which I regularly perform that is not straight forward: expanding a logical volume (LV) which contains an ext3 filesystem. The issue here is that while expanding the LV its self is extremely simple, the filesystem contained on it is not automatically resized. So if you simply expand your LV and reboot your virtual machine, you won’t see the extra space on your filesystem.
The procedure for resizing an LV containing an ext3 filesystem is as follows. The commands below will resize the logical volume named ‘Chris’ on the volume group ‘Xen’ (see output from ‘vgdisplay’ and ‘lvs’ to see what volume groups and logical volumes are defined on your system). NB: make sure the filesystem is un-mounted and any virtual machine using it is powered off before running these commands!
# Resize the LV (eg. to 40GB) lvresize -L 40G /dev/Xen/Chris # Remove the journal from filesystem (we'll re-create it later) tune2fs -O^has_journal /dev/Xen/Chris # make sure it's clean (compulsory - resize2fs will tell you to do this if you forget) e2fsck -f /dev/Xen/Chris # resize the filesystem resize2fs /dev/Xen/Chris 40G # create a new journal tune2fs -j /dev/Xen/Chris
That’s it – boot up the VM and enjoy the extra space!
If you want to expand an LV containing a swap partition, the simplest thing to do is de-activate the swap (swapoff), resize the LV, then simply re-format the swap space, for example:
If you’re using another kind of filesystem and can’t figure out how to resize it, another option (if you have enough space), is to simply create a new LV of the desired size, format it, then copy over your existing data using cp or rsync.