How do I shrink the root logical volume (LV) on LVM?

BEFORE YOU CHANGE ANYTHING MAKE SURE YOU HAVE A CURRENT BACKUP. This all worked for me, but it might not work for you. If it blows up for some reason, you don’t want to lose anything that you can’t recover. Continuing on…

It is not possible (to my knowledge) to shrink a filesystem while it is mounted, so we need to do the actual resizing from a Live CD. All the following instructions assume you have booted off of the 11.10 Desktop Install CD.

After the Live CD boots up to the desktop, open up the Terminal.

The LVM tool are not built-in to the Live CD, so first we must install them:

sudo apt-get install lvm2

Find the name of the Volume Group (henceforth “somevg”) that contains the root Logical Volume:

sudo lvs

(If it’s not showing up, try running sudo lvmdiskscan and sudo pvscan then try again.)

If you run ls /dev/mapper/ you may see that the Logical Volumes is not showing up. If it’s not there, you need to run the following command to make the kernel aware of the logical volumes:

sudo vgchange --available y <somevg>

Since we haven’t mounted the root filesystem, it should be safe to resize. Proceed to perform the actual resizing of the Logical Volume. Note that this command (--size -50G) shrinks the volume by 50GB — read the lvreduce(8) man page to learn how to specify a different size.

sudo lvreduce --resizefs --size -50G /dev/<somevg>/root

(My Logical Volume is called “root”, but yours may be named something different.)

This command will first shrink the filesystem, then shrink the Logical Volume that contains it, which is the only safe way to do it.

You can now restart the system and boot into your now-resized root filesystem.


Both lvresize and lvreduce now support re-sizing the filesystem prior to shrinking the logical volume.

This is a snippet from a man page on CentOS 6.5

-r, --resizefs
       Resize underlying filesystem together with the logical volume using fsadm

Any partition and LV resizing should be done on unmounted partitions, so you have to boot from Ubuntu installation disk or USB stick, run it as live CD, connect to Internet, install lvm2

sudo apt-get install lvm2

...or you can use any Linux rescue CD which already has lvm2 available. Then make sure, that your root LV is not installed, by

mount 

and unmount it when necessary, then do filesystem check

e2fsck -f /dev/yourVG/yourLV 

on this LV. Then shrink filesystem

resize2fs /dev/yourVG/yourLV 150G

and reduce LV

lvreduce -L -50G /dev/yourVG/yourLV

Reboot to your system, enjoy!

Tags:

Resize

Lvm

11.10