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

84,429

Solution 1

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.

Solution 2

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

Solution 3

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!

Share:
84,429

Related videos on Youtube

Donesa Rucci
Author by

Donesa Rucci

Projects I've published that may interest you: BetterWin32Errors — a better interface to winerror.h dapper-invoice — hours invoice featuring style over substance Is Shell Command ______ Portable? — reference website jumpapp — run-or-raise application switcher for X11 desktops MlkPwgen — secure password generator (.NET + PowerShell) secure-random-password — password generator (JavaScript) sh-realpath — a portable, pure shell implementation of realpath SSLfie — generate self-signed x.509 certificates for SSL/TLS

Updated on September 18, 2022

Comments

  • Donesa Rucci
    Donesa Rucci almost 2 years

    I don’t need to actually shrink the MBR partition, just the logical volume that contains the root “/” filesystem. It’s ~200GB now, and I need to shrink it to ~150GB to make room for a new logical volume. How do I go about this?

  • Donesa Rucci
    Donesa Rucci about 12 years
    +1 Thanks for your help. I looked up the answer to my question after I asked it. The LVM tools now have the --resizefs option which seems to work and lets you skip a step.
  • Cerin
    Cerin over 11 years
    These instructions do not work. lvs shows the correct new size, but GParted still shows the LVM with the original size. All your doing is explaining how to shrink the filesystem, not the partition. The partition is still taking up the original amount of disk space.
  • Donesa Rucci
    Donesa Rucci over 11 years
    Are you perchance trying to shrink the VG and/or MBR partition in addition to the LV? These instructions are only for shrinking the LV. I will update the question since (I see upon re-reading) it is not very clear.
  • AmazeCPK
    AmazeCPK over 11 years
    your assumption is not correct. Online resizing (while partition is mounted and used) of ext3/ext4 partitions has been around for a long time. I use this a lot, and have never had a single problem with it. And yes, I have current backups all the time.
  • Donesa Rucci
    Donesa Rucci over 11 years
    @Floyd: do you happen to have a cite for that? I was aware that online resizing is possible when extending, but not when shrinking. If online shrinking is now possible, that would be cool news.
  • Donesa Rucci
    Donesa Rucci over 11 years
    @Floyd I just updated the answer to clarify my assumptions about online resizing.
  • psusi
    psusi over 11 years
    @Floyd, ext3/4 supports online GROWING, but not shrinking.
  • WesternGun
    WesternGun over 6 years
    In my CentOS 7 it is vgchange --activate y <some-vg>. Check VGs with vgs.