How to resize a VirtualBox disk

Dec 27, 2010 • alan


I primarily run Linux, but occasionally need to run something in Windows.  So I use the open source VirtualBox program to run Windows XP in a box (where it belongs).

Most of the time, I create a new VM for a specific task.  For example, around tax time, I might create a VM that has nothing in it except WIndows XP and Turbo Tax or Tax Cut — or better yet — Tax Act.  To make this a little easier, I create a VM that has a fresh copy of Windows XP on a 10GB hard disk, and then I made a compressed copy of the disk image file.  It compresses nicely down to 700MB, just about right to fit on a CD.  So step one of doing my taxes is to copy this disk image file, uncompress it, and create a new VM that uses that disk.

That is, I treat the Windows OS as disposable — create a VM, use it, save my files somewhere else and then throw the VM away.

Every once in a while, though, I need more than the 10GB that I originally allocated to the VM.  For example, iTunes usually needs a lot more storage than that.  So I need to resize the Windows C: drive.  It turns out that this is very easy to do with the open source tool “gparted“.  This comes included in Ubuntu Live CD’s, so I just boot the VM into an Ubuntu Live CD session and prepare the new, larger disk.

Here’s the step-by-step, gleefully stolen from the VirtualBox support forums.

  • Make sure you have an Ubuntu Live CD, or a “System Rescue D“.
  • Create a new hard disk image (*.vdi file) using Virtual Disk Manager.  In VirtualBox, go to File / Virtual Disk Manager.
  • Set your current VM to use the new disk image as it’s second hard disk and the Ubuntu Live CD (or System Rescue CD) ISO file as it’s CDROM device.
  • Boot the VM from the CDROM.
  • If you’re using the System Rescue CD, start a graphical “X-windows” session by typing startx at the command prompt.
  • When your X-windows starts up, open up a terminal and type gparted.
  • You’ll need to create a partition on the new disk.  So in gparted, select the new disk and the Device / Create Partition Table.
  • Then select the windows partition and choose copy.
  • Select the second hard disk, right click on the representation of the disk and click paste.
  • Gparted will prompt you for the size of the disk, drag the slider to the max size.
  • Click apply and wait…
  • Important – when it is done, right click on the disk and choose Manage Flags, and select Boot.
  • Exit gparted and power off the VM.
  • Change the VM settings to only have one disk (the new bigger disk) and un-select the ISO as the CDROM.
  • Boot the VM into your windows install on it’s new bigger disk!  The first time it boots up, Windows may do a disk check and reboot.

Once you’re happy with the new larger disk, you might want to delete the old, smaller one.

This method should work the same, regardless of whether the host OS is Linux, Windows or Mac OS.

Keep that Ubuntu Live CD around — it really comes in handy!