How to Shrink an LVM Volume Safely on Linux


Logical volume management which named lvm allows you to decrease or increase the size of the logical volume and also filesystem. I 'll try to explain how to decrease logical volume size and also Filesystem size on this  KB.

Which command we will use;

  • resize2fs
  • lvreduce
  • vgchange
  • vgdisplay
  • lvdisplay

Step 1: First take  a  full backup  of  your filesystem

As is always the firsts case before start operation take a full backup of your filesystem whenever you perform a shrink or extend on filesystem logical volume etc.If you will perform this operation on a mounted filesystem like "/app"  which is separated from root vg or another mount point you should just umount filesystem and continue operation.

On the other hand, if you will shrink root filesystem you should open your system on Boot CD. Almost all versions of the Linux bring-up volume group on boot automatically but if not you should use "vgchange" command.

#vgchange -a  y vgname

This command set will activate the volume group.

Step 2:Start and  force  a filesystem check

This option is recommended. You should check if your filesystem is clear.

#e2fsck -f /dev/vgroot/lvroot

Step 3:Resize  your  filesystem before resize your Logical  Volume

*This step is too critical. You should resize your filesystem then shrink the logical volume.

Set the new size of the filesystem. But be careful when you set new filesystem size. You should give  new size bigger than file system usage. For example, if your filesystem size is  250  GB and usage is 170GB. So you should shrink new volume  180Gb. This value musn't be less than usage! And also if your logical volume will be set  200GB  it's recommended to set filesystem size 180GB.

#resize2fs /dev/vgroot/lvroot 180G

Step 4: Reduce  LVM size

After resizing filesystem now start the same operation for LVM. But set LVM size bigger than Filesystem size. In my case  it'll be 200GB.

#lvreduce -L 200G /dev/vgroot/lvroot

Step 5: Re-run resize2fs 

#resize2fs /dev/vgroot/lvroot

 

I'm a IT Infrastructure and Operations Architect with extensive experience and administration skills and works for Turk Telekom. I provide hardware and software support for the IT Infrastructure and Operations tasks.

205 Total Posts
Follow Me