Ubuntu: Resize the root LVM(2?) partition

Solution 1:

In general, here's how to resize LVM volumes:

Let's say /mountpoint is on /dev/VolGroup00/mountpoint. You can find this out by checking out /etc/fstab or by running mount -l.

You may also need to resize the actual Physical Volume, depending on your setup. Use pvdisplay to find out if it's big enough, and use pvresize (much like lvresize below) if necessary.

umount /mountpoint
lvresize -L +<HOW MUCH BIGGER> /dev/VolGroup00/mountpoint
e2fsck -f /dev/VolGroup00/mountpoint
resize2fs /dev/VolGroup00/mountpoint <TOTAL SIZE>
mount /mountpoint

This amounts to umounting, resizing the underlying LVM, then resizing the actual ext3 partition.

A few things to be careful of:

  1. Obviously playing with / will be different from a data partition. You may need a boot disk such as Sysrescuecd instead of Doing It Live. Also see Kristof's comment below -- you may actually be able to do this without unmounting /.
  2. lvresize has a few different syntax options, and reducing a logical volume will probably harm the overlaying partition. Consult your local man pages for more information.

Solution 2:

There was one (and only one) way I found to do this and I tried a myriad.

First, clone the ubuntu guest VM in virtualbox by right-clicking it and going to "clone". Once the clone is finished then extend the cloned vdi by using (On the host OS)

VBoxManage modifyhd "name_of_cloned_vdi" --resize "size_of_new_root_partition_in_MB"

Then - follow the steps in this post to the letter (he refers to VMware as a platform but ignore that)

http://blog.campodoro.org/?p=36

This will create another lvm exactly equivalent in size to the extra space you have added and tack it onto the end of the existing one.

Once you have checked all is good, then you can delete the original VM and promote your clone!

No need to mess about with fdisk and worry about deleting or screwing up the wrong partition.

I must have broken about 4 cloned OS's until I found this solution!

Solution 3:

I just did this and had the same question you had, but instead of creating a new LVM and adding it to the volume group, the OCD side of me wanted to resize my current LVM and thus keeping a single partition in the name of simplicity. Note: I don't believe this is possible if the free space does not immediately follow the partition you are resizing!

In order to do so you'll need a tool that can delete and create partition tables. Since I use GPT this meant I needed gdisk. You will also need to do this with the partition unmounted, so you may want to boot to an Ubuntu LiveCD and run this from there.

The following steps in bold are for an example LVM /dev/mms/root on device /dev/sda, where I wanted to expand partition /dev/sda3 to occupy my newfound free space.

NOTE: These are potentially very destructive, so make sure your inputs are correct!

  1. gdisk /dev/sda (make sure to enter the correct device! ) This brings you into gdisk where you can then perform the following steps in order
    1. p -- prints out your current partition information (for reference)
    2. d -- for deleting a partition table
    3. 3 -- the device number representing the partition table you wish to delete (important!)
    4. n -- for creating a partition table
    5. 3 -- the device number representing the partition table you wish to create (you'll probably want to use the same as you deleted in step 3)
    6. p -- prints out your current partition info (again for reference, compare it to what you started with!)
    7. w -- saves your changes to disk (are you sure?!)
  2. pvresize /dev/sda3 -- you may have to reboot prior to doing this so your OS recognizes the new partition size
  3. pvdisplay -- prints out your current info (it should show that it's using the full space now!)
  4. lvresize -l +100%FREE /dev/mms/root -- resizes my LVM to occupy 100% of my newfound space
  5. e2fsck -f /dev/mms/root -- performs an integrity check
  6. resize2fs -p /dev/mms/root -- resizes the file system to occupy your full LVM

After doing the above and restarting into the resized OS, everything worked as expected and I had all of my additional freespace at my disposal!

Additional references which I used to figure this all out:

http://www.jethrocarr.com/2012/08/10/gdisk-oh-glorious-gdisk/ http://people.virginia.edu/~ll2bf/docs/quickref/lvm.html

Solution 4:

See a related answer here.

(excerpt)

Resizing physical volume:

pvresize --verbose --test /dev/md0

Resizing logical volume:

lvresize --verbose -L <SIZE> --test /dev/VG1/LV1

And finally, resizing ext3 FS:

resize2fs /dev/VG1/LV1