Resizing my LVM based virtual disk

So I needed to upgrade my mail server but realized I only had 5GB of space left on the /opt partition and the upgrade complained about needing more than 5GB. Not sure why I didn’t size the whole virtual disk a little bigger in the first place. Also not sure why I didn’t set Zabbix to warn me when the disk space got that low. Hindsight and all of that. So following other’s recipes this is how I resized my LVM based virtual disk, and then subsequently resized the partitions within the VM.

OK, first task – logon to the KVM host and resize the LV that sits on my iSCSI share. Let’s see how much space/extents we have:

Excellent! Looks like we’ve got a boatload of free space. In theory you should be able to resize the guest’s LV while it’s still running, but in my case I shutdown the guest VMs (still working through issues of migrating guests to my other KVM host). Not taking any chances with my mail server. With the guest VM shutdown it’s just a matter of resizing the LV on the KVM host box:

root@vmsvr-2:~# lvresize -L +30GB /dev/VGnas-1/lv-guestvm

OK, that did the trick. We now have another 30GB to work with. Time to reboot the VM and resize the LVs within the guest. That of course was a little more involved, but still easy enough and can be done while the host is up and running!

The next step was to create a new LVM partition on the virtual disk. From everything I’ve read so far, it seems this is the safest way to do it rather than resizing the existing PV partition. In my case, I currently had the following allocated on the VM:

“0 free” says it all – nothin’, nada. So I then fired up “cfdisk /dev/vda” and created a new third partition of type 8E using the empty space from the previous resize of the underlying LV. The next step is to tell the running OS that there is another partition in town:

root@mailserver:~# partprobe -s

which if all goes well should give you some output about the partitions it found and their types (e.g. msdos, etc.). And another “fdisk -l” shows that our new partition is there and waiting:

Now if we issue a “vgdisplay” we should see that we have plenty of extra space/extents to now increase the size of the LVs. So let’s go ahead and resize our LV where we have the /opt partition mounted:

root@mailserver:~# lvresize -L +15GB /dev/VGlocal/opt

In this case I only increased it by 15GB so that I’ll have another 15GB to play with if I need to increase the root or swap partitions. Almost there. Now we have to resize the filesystem that sits atop of the resized LV:

root@mailserver:~# resize2fs /dev/VGlocal/optresize2fs 1.42 (29-Nov-2011)Filesystem at /dev/VGlocal/opt is mounted on /opt; on-line resizing requiredResizing the filesystem on /dev/VGlocal/opt to 8814592 blocks.The filesystem on /dev/VGlocal/opt is now 8814592 blocks long.