Reducing or extending a Logical Volume (lvm)

Posted by: Robert  :  Category: Administration

Logical Volumes are one of the cool technologies that finally made it to Linux.  LVMs present your filesystems with a virtual (or logical) drive to use that may reside on one or more physical volumes.  Once you start working with LVMs you’ll never want to go back. How about the ability to extend or reduce their size? Or my personal favorite, the ability to snapshot a filesystem, which is like taking a picture (a snapshot) of how it looked at a point in time.  This is done through some “trickery” with a snapshot volume that holds the real writes to the snapshotted volume on a separate LVM.  You can then backup the snapshotted LVM without worrying about if changes are being made to the filesystem. When you un-snapshot the LVM, all the writes are committed to the real LVM. As far as the applications thinks, the filesystem is business as usual. And unlike splitting mirrors, you 1) keep your redundancy intact 2) its MUCH faster and 3) you only need space to hold the writes.

But there are times you need to modify a filesystem.  For example, you may need to reduce or extend a Logical Volume on a system…  Say we have a /vz filesystem and we want to reduce it to 500GB to open some unused space for something else.

  1. Backup your data – this is ALWAYS step 1.
  2. umount /vz
  3. e2fsck -f /dev/Volgroup##/LogVol##    … where the #’s are the logical volume group and volume numbers for /vz
  4. resize2fs /dev/VolGroup##/LogVol##   500GB  … same ##’s as above
  5. lvreduce -L 500GB /dev/VolGroup/LogVol##  … do I need to say it?
  6. e2fsck -f /dev/VolGroup/LogVol##    …. just for good measure
  7. mount /vz   … or mount -a
About: Robert:
Robert Porter holds MCSE, A+, Net+, Security+, and multiple CIW certifications. He has been in the hosting industry for more than a decade and is founder of Lagniappe Internet L.L.C., a privately owned, completely debt free, hosting company based out of New Orleans. Robert's background includes 25+ years in programming, databases, networking and systems administration.

Leave a Reply