Loading...
 

LVM


Table of contents



Extending a Physical Volume


This blurb is just to get some info on extending LVM physical volumes down on paper and doesn't really talk about syntax of the commands, that part of it is pretty straight forward so refer to the MAN pages if necessary. LVM makes thing pretty simple to resize an LVM volume on the fly, assuming of course that you have enough space available in your volume group to do so. But what if you don't. You could add an additional disk or LUN to your volume group(pvcreate then vgextend) to get more space. But that might not be the best option for you if you only needed to add a couple of gigs of space. If your LVM physical volume is a LUN it is probably just easier to extend the LUN from your storage array perspective to provide you with the needed space. Sounds simple enough right, grow the LUN, pvresize the physical volume, and lvextend your volume......NOT! There is a critical step missing that caused me a couple of hours worth of troubleshooting.......

Your partition table will need to be adjusted before you pvresize or the pvresize command won't work as expected. Without recreating your LVM partition when you attempt to pvresize it sayes it succeeds but the size doesn't change. You might be tempted to use the "--setphysicalvolumesize" parameter. This will forcibly extend the physical volume size to whatever you want but you will likely run into problems extending your LVM volume or creating new LVM volumes because calls to the underlying file system will fail. You are asking LVM to push your volume size past the partition boundary which creates all kinds of cryptic device mapper or ioctl error messages.

So how should you go about adjusting your partition table? You have a couple of options.

If the LUN that you have extended only has one LVM partition on it and that partition is the last partition in the partition table you can simply "fdisk /dev/sdX" and delete the LVM partition and immediately recreate it taking the defaults to extend it to the end of the LUN. The critical part here is to make sure that your LVM partition starts at the same block that it started at originally. This shouldn't be a problem as long as you chooose the same partition number that it was before. fdisk should just start the new partition right after the preceding one. The only caveat here is if your partitions were not contiguous for some reason. Just make sure that you look at the partition table closely before proceeding, or even better back it up.....Once this is done, you will probably need to reboot to re-read the partition table and then your pvresize will work as expected and you can continue creating/extending your LVM volumes as you normally would.

If the LUN that you have extened has more than one partition on it and the partition that you need to extend is not the last partition in the table your best option is just to create a new partition in the available free space and then add that device to your volume group as an additional physical volume. You could try creating new partitions and moving your physical volumes around but it will probably be more trouble than it is worth.

A rough procedure would be:

  • Extend your disk or LUN
  • Adjust your partition table to account for the new space
  • Use pvresize to make your new free space available to LVM
  • Use lvresize to resize your logical volume
  • Use resize2fs to resize the actual file system, should be able to do this online unless it is the root file system
Show php error messages