Resize LVM PV Partition in Debian/Ubuntu
Tue, 11 Jun 2013, by Syrsly
I may expand on this later if I ever have a reason to, but I wanted to share a few woes I recently had to deal with when trying to fix a LVM or Logical Volume Manager partition on one of my VirtualBox-powered server projects. By the way, let it be known that I am an absolute newbie when it comes to raid configurations and related tasks. The closest I ever got to setting up a server cloud was hooking up a LAN party to play 16-on-16. That said, I think this information should be easier to find than it currently is, so i am sharing it in an easy-to-understand fashion. I hope it helps you.Okay, so you made or received a backup of an operating system for use in a virtual environment. The partitions list something like "ext2, extended, lvm pv" and the lvm pv partition is way too small for your package updates or whatever other data you need to work with. (In my case, I needed extra space for MySQL.) What you want to do is resize the partition, but chances are you tried that already and are now looking for answers as to why.
There is a rather complex workaround solution that relies on the lvm2 package. You may be required to install that package before continuing. Use "sudo apt-get install lvm2".
Assuming you already resized the partition to the desired size (I recommend GParted 0.16), get into your system as root. (If you don't know how, try "sudo su".) Type "lvdisplay" to find the LVM LV or logical volume information. You should see something like "--- Logical volume ---" followed by "LV Name /dev/ubuntu/root" and a few lines later "LV Size". Type "sudo lvresize -L +2G /dev/ubuntu/root" where the /dev/ubuntu/root is replaced by whatever the LV name is of the LV you want to resize. The "+2G" adds 2 gigs to the LV size. You can change it to a lower or higher size if you want. The trick is to make sure you are only increasing the size to fill the remaining space, minus a few MiB of padding. To see if it worked, test with "lvdisplay" again.
Type "pvdisplay" to find out the LVM PV or physical volume information. You should see something like "PV Name /dev/sda5" and some information about the size and PE size. First, realize that PV size is the total allocated space for that volume, like a partition. Then, the PE size, from what I understand so far, is like a section of that total size that gets fragmented into segments. I assume that the segments have a purpose, but so far, I have no idea what that purpose is. You will have to find that information elsewhere. Moving on...
Type "sudo pvresize --setphysicalvolumesize XG /dev/sda5" where /dev/sda5 is replaced by whatever your PV name is and XG is replaced by whatever size you want the PV to be. This may seem to do nothing or it may throw a weird error about blocks or extents. If it seems to do nothing, it probably worked, so check it with "pvdisplay".
This information was picked up after hours of searching and experimentation in my own time. Use these methods at your own risk. Always backup your data before any major edits. LVM resize is a major edit in my opinion. it is risky. Risky. Backup first. Again, it is risky. VERY RISKY! Be careful.
This post not yet tagged.