MaiDeveloper

How to shrink logical volume (LVM) using SystemRescueCD?

Shrinking logical volume (LVM) must go through several steps. Unlike standard partition (ext4 file system). In order to shrink root logical volume, we must boot into a live CD like SystemRescueCD. And then shrink the volume from there.

Let's get started. We have two disk; the root partition is in /dev/sda2. LVM partition is in /dev/sdb1. We are going to move LVM partition from /dev/sdb1 to /dev/sda3.

Boot into SystemRescueCD

Switch to root.

su - root

Pick up LVM volumes

vgchange -a y

Find out the root logical volume

lvdisplay

lvdisplay-1

In this case, /dev/vg/root is the root logical volume.

File system check

e2fsck -fy /dev/vg/root

Shrink file system

The command below will shrink the file system so taht it is only 900G in size total.

resize2fs /dev/vg/root 900G

Once the file system has been reduced, we can shrink the size of the logical volume with the lvreduce command. Reduce this to the size that you want the volume to be, as specified by the -L flag. Instead if you want to reduce by a specified size, simply put a – in front of the size. Both are shown below for completeness, however you only need to run one.

To reduce to 900G

lvreduce -L 5G /dev/vg/root

To reduce by 10G

lvreduce -L -10G /dev/vg/root

Once you execute the lvreduce command you will get a warning advising the size you have chosen to reduce to so use this as a chance to confirm you’re shrinking the logical volume to a size that is NOT smaller than the size you previously shrunk the file system to. Once you have confirmed it’s fine to proceed enter ‘y’ and press enter.

After the logical volume has been lowered to the required size, run resize2fs on the volume as this will extend the file system to use all available space within the logical volume. This makes use of all remaining free space so that none is wasted from when we previously shrunk the file system to a lower size than the logical volume.

resize2fs /dev/vg/root

Resize the disk using gparted

VNC into the server, ip_address:5901

gparted


Mike Mai
Mike Mai   Brooklyn, New York
I am a full-stack web developer. I love to learn cutting-edge technology and solve problems. I also like photography and graphic designs.