Hello everyone. I hope you have all been well.
I have a new blog entry on something I just noticed today.
So I typically don’t use LVM in my Linux Virtual Machines, mainly because I have had some issues in the past trying to migrate VM’s from one hypervisor type to another, for example, VMware to KVM or vice versa. I have found that if I use LVM, I have mapping issues and it takes some work to get the VM’s working again after converting the raw disk image from vmdk to qcow2 or vice versa.
However, since I don’t plan on doing that anymore (I’m sticking with KVM/Qemu for the time being) I have looked at using LVM again since I like how easy it is to grow the volume if I have to in the future. While growing a disk image is fairly easy, trying to grow a /dev/vda or /dev/sda is a little cumbersome, usually requiring me to boot my VM with a tool like PMagic or even the Ubuntu install media and using gparted to manipulate the size and then rebooting back into the VM after successfully growing it.
With LVM, this is much simpler. 3 commands and I’m done, and don’t need a reboot. Those commands:
pvdisplay
lvextend
resize2fs
Now, One thing I have noticed after a fresh install of Ubuntu Server 22.04.2, using LVM, I don’t get all my hard drive partition used. I noticed this after I installed, I ran df -h
and noticed that my / folder was at 32%. I built the VM with a 50G hard drive, yet df was only seeing 23GB. I then ran
sudo pvdisplay
Sure enough, the device was 46GB in size. I then ran
sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
This command extended my partition out to the remaining space. Next, I grew the file system to use the new space:
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
I then ran df -h
again, and low and behold, my / folder is now saying 46GB and 16% used instead of 32%.
I hope this helps anyone else!