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:
- Created a new larger virtual disk
- Added the 2nd disk to the machine
- Used CloneZilla to clone the first disk onto the 2nd disk
- Removed the first disk
- 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
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 runningmount -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 usepvresize
(much likelvresize
below) if necessary.This amounts to umounting, resizing the underlying LVM, then resizing the actual ext3 partition.
A few things to be careful of:
/
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/
.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!
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!
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
See a related answer here.
(excerpt)
Resizing physical volume:
Resizing logical volume:
And finally, resizing ext3 FS:
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 usevgextend
to add that to the volume group supporting your logical volume, then usevgreduce
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.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:
(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.
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 theLive 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! :)
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.
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.