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 want to shrink my second (LVM) partition, in order to create a new partition in the newly freed space. I am using the Live CD to do so, because I know I can't resize/move this partition while it is in use. When I opened GParted in the Live CD, I realized that I could not resize the partition, because when I right-click it, the option "resize/move" is disabled.

I tried to unmount it, to "lazy" unmount it (umount -l /dev/sda2) but it didn't work.

A screenshot from GParted:

GParted screenshot

share|improve this question
add comment

3 Answers 3

There seems to be plenty of results on Google where people had similar problems. An example:

Back up all your important data before attempting this. Always assume that you can lose all your data when resizing partitions.

Shrink LVM without dataloss

This forum thread suggests the following procedure, in this example we shrink a partition from 10G to 9G:

First, we unmount.

# umount /dev/vg_blah/lv_blah

Check the file system.

# e2fsck -f /dev/vg_blah/lv_blah

Resize the file system.

# resize2fs -p /dev/vg_blah/lv_blah 9G

Reduce the size of the logical volume.

# lvreduce -L -1G /dev/vg_blah/lv_blah

Shrink the volume group if desired.

# vgreduce vg_blah /dev/sdxy

All credit goes to brianmcgee, author of the post who also points out:

It is crucial that you use the exact amount of space. If you reduce volume more than the filesytem you truncate the logical volume and you risk data loss!

Note: vgreduce will fail with "cannot resize to xxxxx extents as later ones are allocated" if you have another lv at the end of the disk - I had a swap lv, which I deleted. See 2 for help on that situation.

share|improve this answer
1  
e2fsck -f /dev/vg_blah/lv_blah returns: "e2fsck: Device or resource busy while trying to open /dev/sda2 Filesystem mounted or opened exclusively by another program?", the same with resize2fs... –  iiddaannyy Oct 8 '12 at 13:52
    
Is it unmounted? What did you type in your command specifically (I'm assuming you didn't type vg_blah) –  bigbadonk420 Oct 9 '12 at 8:39
    
Yes, it is unmounted. I typed e2fsck -f /dev/sda2. –  iiddaannyy Oct 9 '12 at 18:56
3  
The answer is missing how to resize the physical volume. Also, I highly recommend combining the two resizing steps into one with lvreduce -r. –  Flimm Nov 28 '12 at 17:02
2  
Also, you need to realise that 1G to lvreduce is 1000000000 bytes, whereas to resize2fs it is a gibibyte. If you want to pass 1 gibibyte to lvreduce, use 1g instead. –  Flimm Nov 28 '12 at 17:08
add comment

Only the latest version of Gparted (0.14) supports resizing LVM physical volumes. The version that ships with Ubuntu 12.10 or 13.04 does not support it.

Here's how to resize an LVM physical volume:

  1. If the volume group associated with the LVM physical volume does not have enough unallocated space, you'll need to make some by shrinking a logical volume. Look at bigbadonk420's answer for instructions on how to do that. You can also use GNOME Disks (included with Ubuntu) for some of the steps if you prefer a GUI.

  2. Burn the latest .iso image from GParted's website, and burn it on a CD or put it on a USB stick. Boot from the CD or the USB stick. Alternatively, you could compile the latest version of GParted from source.

  3. Use GParted to resize the LVM physical volume. GParted won't let you shrink the LVM physical volume to a size smaller than what the unallocated space allows.

share|improve this answer
    
Thanks Flimm. I was expecting 12.10 to have a recent enough version of gparted. Your answer pointed me in the right direction. –  Martijn Heemels Apr 9 '13 at 21:31
add comment

You can shrink/extend a logical volume very easily with a GUI tool: system-config-lvm. Because system-config-lvm is not come pre-installed, once booted from a live-cd, you have to install it:

$ sudo apt-get install system-config-lvm

Once it is installed, run the program, select the logical volume you want to change in the left panel, click 'Edit Properties'.

Main Logical Volume Management program GUI

Now change the parameters as you wish!

Edit Logical Volume window

One good thing about system-config-lvm is that it won't allow you to go ahead if the new partition size is smaller than all your existing data combined (I've just tried this and see for myself).

References:

  1. How-To Geek tutorial (this is the origin of the images).
  2. Red Hat's complete guide for the program.
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.