Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

4 Answers

up vote 4 down vote accepted

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.

share|improve this answer
    
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. –  Cerin Oct 14 '12 at 16:58
    
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. –  Michael Kropat Oct 16 '12 at 12:34
    
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. –  Floyd Oct 16 '12 at 13:11
    
@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. –  Michael Kropat Oct 16 '12 at 16:47
1  
@Floyd, ext3/4 supports online GROWING, but not shrinking. –  psusi Oct 16 '12 at 19:24
show 1 more comment

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|improve this answer
1  
+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. –  Michael Kropat Apr 23 '12 at 15:14
add comment

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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.