How to expand (grow) a VirtualBox VDI file

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.


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.

Create a new vdi

VirtualBox's Virtual Media Manager GUI

Once the new disk has been created, attach it to a virtual machine along with the VDI you wish to expand.

Attach a VDI

Attach your new VDI to the machine's storage tree

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.

Set vdi attributes

Select your drive, and click "IDE Primary Slave" in the Slot 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.

VirtualBox attach CD

Attach a LiveCD image to your virtual machine

Finally, boot into your LiveCD environment.

Backtrack 4 Startup Screen

Boot your VM into your Live Linux 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:

In most cases (in my case, and with BT4 especially) you should type:

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.

dd image copy

Performing a raw dd "image" copy in backtrack (note: replace /dev/null with /dev/hdb)

Once dd has completed, run gparted. In Backtrack4, it’s under the System Menu, listed as “Partition Editor.”

Backtrack Partition Editor

Backtrack Partition Editor, under the System menu

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.

Resize partition in GParted

In the gparted resize window, click and drag your partition to fill the available disk space.

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.

GParted resize complete

After the changes have been commited, the new drive image is 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.

detach original vdi

Detach your original VDI from the machine and set the new VDI to Primary Master

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.


Windows will suggest you run chkdisk. You should probably let it...

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?

grow vdi successful

Same Windows environment, with more disk space :)

More information

GParted Manual

dd Manual

Incoming search terms:

Comments are closed.