Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have an Ubuntu virtual machine running in VirtualBox 2.2.4, and I created it on an 8gb virtual disk which is too small.

So, I am trying to increase the size of the disk. So far, I have done this:

  1. Created a new larger virtual disk
  2. Added the 2nd disk to the machine
  3. Used CloneZilla to clone the first disk onto the 2nd disk
  4. Removed the first disk
  5. Booted up off the 2nd (larger disk)

But now I'm still stuck with an 8gb partition on my new 100gb virtual disk.

Whats the easiest path from here to having a 100gb partition? :) I gather GPart can resize partitions, but it doesn't seem to support LVM2 partitions, which mine seems to be.

thx

  • Alex
share|improve this question
add comment

8 Answers

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 live 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.
share|improve this answer
    
Thanks, that looks promising, can you suggest a LiveCD I might use which has LVM tools on it? –  user12259 Jul 9 '09 at 19:35
    
Sysrescuecd is nice (sysresccd.org) –  Zoredache Jul 9 '09 at 19:44
4  
ext2/3/4 support live growing of your filesystem. You don't need to unmount or e2fsck your partitions. resize2fs is also clever enough to figure out the size of the partition (or logical volume) it's on. If you don't specify a size it will just grow to fill all available space. –  Kristof Provost Jul 9 '09 at 21:22
    
I tried "sudo resize2fs /dev/sda1" and it responded: "resize2fs: Device or resource busy while trying to pen /dev/sda1 Couldn't find valid filesystem superblock" –  user12259 Jul 9 '09 at 22:00
1  
lvresize doesn't change the physical volume size, so don't I need to do that first? –  user12259 Jul 9 '09 at 22:15
show 1 more comment

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!

share|improve this answer
add comment

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
share|improve this answer
    
When i do lvresize, i get an error "Failed to suspend root" –  user12259 Jul 9 '09 at 22:23
    
I tried: "sudo lvresize --verbose -L 40G /dev/ubuntu/root" –  user12259 Jul 9 '09 at 22:29
    
ok, I fixed that with "sudo modprobe dm-mod", now I can successfully lvresize –  user12259 Jul 9 '09 at 22:42
    
fdisk -l shows I have 54GB available, but after running pvresize /dev/sda2; lvresize -L 50G /dev/mapper/VolGroup-lv_root I get the error "Insufficient free space: 588 extents needed, but only 0 available". pvdisplay shows my physical volume wasn't resized. –  Cerin Sep 5 '12 at 19:02
    
You really should ask a new question. The comments of an old question isn't the best way to get help. –  Zoredache Sep 5 '12 at 21:32
add comment

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

share|improve this answer
add comment

I. If your virtual HDD has a fixed size, you cannot make it bigger. In this case you have to clone it first.

(1) Clone the HDD over the VB GUI: File -> Virtual Media Manager... -> [tab] Hard Drives -> select your HDD -> [button] Next -> [button] Next -> select "Dynamically allocated" on the step "Storage on physical hard drive"-> ...

or on the command line:

# VBoxManage clonehd "/path/to/the/HDD.vdi" "/path/to/the/HDD_NEW.vdi"

(2) Add the new HDD to the list of the known HDDs.

(3) In the VB machine settings remove the old HDD from the VDI list under the Controller and add the new on instead.

II. Resize the HDD

(1) Resize the new HDD.

# VBoxManage modifyhd 463c7bd4-9b9c-4cf8-bee4-e14e10c0d462 --resize 25600

You get the key with the VBoxManage list hdds command.

III. Add new allocated space.

(1) Add a GParted ISO as new medium under Machine Settings -> Storage -> [rightclick] Controller IDE -> Add CD / DVD Device -> ... and select the Live CD/DVD checkbox.

(2) Start the VM and add the not allocated free space to your work partition.

(3) Stop the VM.

(4) Detach the GParted ISO.

Enjoy! :)

share|improve this answer
add comment

Check out this other serverfault question's answer, How do you increase a KVM guest's disk space?. The technique used to increase the LVM partition in this KVM guest is similar to what you're trying to accomplish.

share|improve this answer
add comment

When resizing LV2 partition, this reference helped me a lot:

http://people.virginia.edu/~ll2bf/docs/quickref/lvm.html

Notice, that you don't need to use any live cd, you may do the resize on the mounted, live system, resizing on the fly.

share|improve this answer
add comment

Note that you don't actually need to use a clone tool like CloneZilla here, you can put a partition on the new virtual disk (optional) then initialize that (or the virtual disk itself) into LVM using the pvcreate command. Then use vgextend to add that to the volume group supporting your logical volume, then use vgreduce to remove the original virtual disk from the volume group. This will perform a migration, and it can be done live while the logical volume is in use, this is the beauty of storage virtualization. Once it's finished you just need to extend the logical volume as above, which could also be done live with more modern filesystems than ext3.

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.