The process of duplicating or compacting a VDI file is relatively straightforward (see older posts for details), once you figure out the tricks. While duplicating and compacting functionality is built in to VirtualBox, unfortunately, increasing the size of a VDI disk is a little more difficult.
Synopsis
0. Back up your original VDI and all data!
1. Create an empty vdi file with the space you need.
2. Make your new, empty vdi the primary slave of the virtual machine attached to the drive you wish to expand (which should be the primary master).
3. Attach a Linux LiveCD image (iso) and both vdi’s to a virtual machine and boot. I used Backtrack 4, but anything with gparted should work.
3. Open a terminal and manually copy small drive’s contents into the larger drive using the command “dd if=/dev/<sourcedisk> of=/dev/<destinationdisk>”
4. Once copying is completed (takes a while), use gparted to resize the new disk image.
5. Shutdown the virtual machine.
6. Set the new, larger drive as the VM’s primary master, and boot the virtual machine.
7. Cross fingers, and run chkdisk.
How to expand a VDI disk file
After backing everything up, begin by creating a new, empty VDI file with the space you need. In the VirtualBox GUI, go to File > Virtual Media Manager and click “New.” to launch the wizard.
Once the new disk has been created, attach it to a virtual machine along with the VDI you wish to expand.
If the VDI you wish to expand has the root filesystem or operating system on it, make sure it’s the primary master. If you’ve been booting your VM with the disk you need to grow, this setting will already be in place. Designate your new, empty VDI as the primary slave in the “Slot” dropdown menu.
Finally, attach your Linux LiveCD iso image to the machine. As long as the LiveCD has gparted, it should work. I used the Backtrack 4 iso, because I always keep it handy.
Finally, boot into your LiveCD environment.
If you’re using Backtrack 4, it spits you out at the command prompt. Disregard the fruity Chinese lettering and the decorative border. Backtrack is created by 31337 h4x0rs, so it has a lot of stupid branding (dramatic startup music, dragons, etc.). Type startx to boot into KDE (another thing I hate about Backtrack, but I digress…) Open a terminal and type the following command:
|
1 2 3 |
$ dd if=/dev/<master disk> of=/dev/<slave disk> |
In most cases (in my case, and with BT4 especially) you should type:
|
1 2 3 |
$ dd if=/dev/hda of=/dev/hdb |
Warning: this will do an “image copy” of the block device referenced by /dev/hda to /dev/hdb. Be sure you specify the right devices here!
In almost all cases with Backtrack4, you should specify hda and hdb. To be sure, you can always run gparted, fdisk -l, or another disk information command. Search around for more info. dd image copying usually takes a very long time, so be prepared for a wait here.
Once dd has completed, run gparted. In Backtrack4, it’s under the System Menu, listed as “Partition Editor.”
In gparted, select the disk you wish to expand from the menu in the upper right corner of the window (probably hdb, if you’ve been following this tutorial. Don’t mind that mine says hda, I messed with some stuff between screenshots). Right click the partition, and select “Resize/Move” and click and drag the partition to fill the entire disk.
Once you’ve finished resizing the partition, click the “Resize/Move” button, and click the green “Apply” check mark in the GParted toolbar to commit the changes. Once GParted has finished writing the changes, your new disk should be ready to boot.
Shutdown your LiveCD environment and go back to VirtualBox. In the Storage menu for your virtual machine, detach the original vdi from your VM and set your new disk as the IDE Primary master. Don’t forget to set the CD drive to “Empty,” or you will boot into your LiveCD again.
Now, boot your Virtual Machine. Windows should detect the changes we’ve made to the disk, so it will suggest you run chkdisk. Seems like a good idea.
Assuming everything went according to plan, the boot process should continue as usual after chkdisk completes, and you should find yourself in your old XP environment, on a larger disk. If not, at least you backed everything up, right?











