Shrink an LVM volume

Technical, Technology

First, boot your machine up using a SystemRescueCD.  Then follow the command sequence below.

# Make any logical volume available to Linux
vgchange -a y
# Force a filesystem check for the target volume
e2fsck -f /dev/mapper/vg_server1-lv_root
# Resize the filesystem (a safer measure is to resize it to 10% less than your target size)
resize2fs /dev/mapper/vg_server1-lv_root 90G
# Reduce the LV size (to your target size)
lvreduce -L 100G /dev/mapper/vg_server1-lv_root
# Resize the inner filesystem to fit the LV
resize2fs /dev/mapper/vg_server1-lv_root
# If you have a few LVs and you do the above for all, chances are you are left with a PV having a few fragmented LVs
# The command below sees how the LVs are arranged
pvs -v --segments /dev/sda2
# Move the fragmented LVs back to the front
pvmove --alloc anywhere /dev/sda2:<src-from>-<src-to> /dev/sda2:<dest-from>-<dest-to>
# Shrink the PV
pvresize --setphysicalvolumesize 64G /dev/sda2
# Then use GPartEd in X-windows to resize the partition

References: [1] [2]


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s