Resizing a Virtual Machine in VirtualBox
No easy way, I'm afraid. I had to do the same thing last week and this is the only help that I got to:
http://crookedspoke.wordpress.com/2008/03/15/resize-disk-image/
This is what you've got to do:
- Download the GParted Live CD (the gparted-live-*.iso).
- Create a new virtual hard disk with the desired size (50GB in your case).
- In your virtual machine, add the newly created virtual drive as a IDE Primary Slave.
- Run the machine.
- Boot from the GParted iso image:
- From the VM's menu select: Devices > Mount CD/DVD-ROM > CD/DVD-ROM Image...
- In the Virtual Media Manager click on Add button.
- Open the gparted-live-*.iso image.
- Press Select.
- Restart the virtual machine.
- Press F12 when you see the Sun VirtualBox boot screen.
- Select the CD-ROM option.
- Open Terminal application.
-
Type:
fdisk -l
- Check that it shows you two partitions: /dev/hda and /dev/hdb. The first is the old disk, the second is the new one and it should not be partitioned.
-
Type:
dd if=/dev/hda of=/dev/hdb
(this will probably take a long time) - Run the GParted tool and resize the /dev/hdb to occupy all free space.
- Turn off the virtual machine.
- In Hard Disks settings for the VM, remove the old hard disk and set the new for IDE Primary Master.
You want (at least wanted year and a half ago) to resize virtual disk used by your virtual machine. You're using VirtualBox, so it's most likely a VDI file. VDI files can be fixed or dynamic. Fixed one has all blocks (units of data in VDI files, each one has 1MB by default) allocated from the beginning, so 10GB image's size is 10GB (a bit more actually, because you have some metadata, but it would be presumably even less than 50KB in your case). Dynamic file grows as you write to it, at the beginning having 0 preallocated blocks (VDI consists only of metadata).
Preface
I describe only expanding of the image. It's up to you what you'll do with a new space. Your partitions with file systems can be resized after expanding or you can create new partitions. It's a separate problem, but Tomas Sedovic pointed you to GParted Live CD, which can help you in performing such tasks. Personally I prefer Parted Magic, because it has other useful tools on ISO.
Expanding fixed VDI
If you have fixed VDI, then you can use my little tool called vidma - Virtual Disks Manipulator. There is ready to use exe
file for Windows (2000 and above) users. For POSIX systems (like Linux) users there is a source code that you can simply compile using make
.
Vidma supports resizing in-place, i.e. it can resize your image without creating new file. In your case it would mean that you need only 40GB and a few MBs of free space to expand your image from 10GB to 50GB. It's very useful (and the main reason I wrote this tool), but if anything goes wrong (Murphy's laws are merciless) and you don't have copy of your image, then you have a real problem. That's why it's not recommended, especially for inexperienced users.
To continue you must have 50 GB and a few MBs of free space.
vidma image.vdi 51200 newimage.vdi
Before deleting old image, you should carefully check whether newimage.vdi works without problems. vidma
does not change UUID of the image, so you have to remove old one from VirtualBox Virtual Media Manager before you can add resized one. You can also change UUID of new image to avoid removing the old one.
VBoxManage internalcommands sethduuid newimage.vdi
Expanding dynamic VDI
Since VirtualBox 4 you can resize dynamic VDI using VBoxManage
:
VBoxManage modifyhd image.vdi --resize 51200
This command expand VDI file to 51200MB, i.e. 50GB. It will be done in-place and number of allocated blocks won't be increased, so you don't really need additional 40GB, but it's obviously required to be able to fully utilize resized image.
EDITvidma
since version 0.0.3 also supports resizing dynamic VDI files.
To get a better grasp of vidma
, beside checking linked before GitHub repository, you can go to thread at VB forum. Reading vidma(1) manual page is recommended.