Re-sizing a VirtualBox Virtual Disk Image File

In my previous post I extolled the virtues of Sun’s desktop virtualisation software, VirtualBox. One thing niggled me though - I couldn’t easily expand a Virtual Disk Image (VDI) and was regularly reaching the space limits of the modest 20Gb disks I was creating; I needed an easy way of expanding disks before I could use it as my main virtualisation platform and felt comfortable in recommending it to my readers.

Given that there is very little information out there on how to perform this task - apart from a single obscure forum post - here is my attempt to walk you through the process of expanding a virtual disk image. This guide assumes that you are trying to expand a disk configured with Windows, however the procedure should be pretty much the same for a Linux/OpenSolaris etc. based disk.

Getting Started

  • Download System Rescue CD a Gentoo (Linux) based ISO to manage disk images (approx 230Mb).
  • While the System Rescue CD is downloading, create a new Virtual Disk in the VirtualBox console that is the size of the larger disk you need.
  • Attach the new disk to your virtual machine that needs its disk expanding as the slave disk.
  • Once the System Rescue CD download has completed, mount the ISO on the virtual machine CD drive.

Starting the Disk Image Utility

  • Boot the virtual machine from the mounted ISO - during the boot process, you will be prompted to enter your keyboard locale so you get the correct keyboard layout.
  • Once at the command prompt (there is no need to log into the environment), type startx to start X Windows. Once X is fully started, a terminal will be displayed on the screen, type gparted to start the Gnome Partition Editor.
  • Once gparted starts, you will be presented with a graphical representation of your disks - left-click the left-to-right bar named /dev/sda1 (your primary hard disk that is to be expanded) and then click on the Copy icon.
  • Select the drop-down-box to the right of the tool-bar and select the second (currently empty) disk - /dev/sdb, the graphical representation of your disks will change to show you the second disk. Click on the Paste icon. gparted will will prompt you for the size of the new disk, drag the slider to the right to select the maximum size of the new partition on this new disk (I’d just drag it so the partition consumes the whole disk).
  • Click the Apply icon, you’ll be presented with something along the lines of the screenshot below as the contents of the source disk are copied to the new, larger, disk:

  • Once the copy has completed (approx. 35 mins to create a 30Gb disk from an original 20Gb disk), you will need to mark the new disk as bootable (if this is to be a bootable partition - if not, simply skip the next step).
  • To mark the partition as bootable, right-click the graphical representation of the new disk and left-click Manage Flags. In the dialog that appears, select Boot and click Ok to close.
  • Close gparted and in the terminal window, type halt to shutdown the system.

Completing the Re-Sizing

  • Once the virtual machine has powered off, re-configure the hard disks to use the newly created/copied disk as the primary and remove the old primary disk from the system; finally, unmount the System Rescue ISO from the CD-ROM.
  • Power on your new VM and you should be presented with the the usual Windows boot sequence; if you are just presented with a black screen with a flashing cursor at the top left-hand corner of the screen, there isn’t a boot sector on the disk, so restart gparted and add the boot flag as directed above.
  • Hopefully, your virtual machine will start without issue; once logged-in, open Windows Explorer and confirm that the newly created drive is the new larger size.

The procedure described above has been tested on Windows Server 2003 and works without issue (although the first time around I forgot to apply the boot flags…), so it should work seamlessly on Windows XP, Vista and Windows Server 2008.

I appreciate that this procedure does involve running a flavour of Linux to acheive the desired results, however its very straightforward and shouldn’t be off putting to a Linux novice.

Enhanced by Zemanta

9 Responses to “Re-sizing a VirtualBox Virtual Disk Image File”


  1. 1 Tomas Restrepo

    Nice post, Nick! VBox is a pretty nice virtualization platform (I use it for linux guests, but been a bit reluctant to move my existing vpc images over to it).

    BTW, if the guest OS is vista or WinServer2k8, you should be able to resize the partition using Disk Manager directly from the OS without having to go through the system rescue cd.

  2. 2 Nick Heppleston

    Tomas,
    Thanks for the pointer, I’ll try Disk Manager later today on a 2008 Server. One question though: how can Disk Manager increase the size of a partition if the virtual disk is already at its size limit?

  3. 3 Briefe Schreiben

    Hey! Your Post “ng a VirtualBox Virtual Disk Image File at Nick Heppleston’s BizTalk Blog” is very interesting for me. Unfortunately my written English is not so good so I write in German: Dir, meinem liebsten, geh

  4. 4 Be_Mons

    Nice!!!!Thanks a lot!!!!quick and easy way to do it!!!!

  5. 5 Jules

    Clear, concise instructions — many thanks.

    Can these same steps be used to copy a fixed-size disk to a dynamically expanding one? I can’t see any reason why not, but after trying it, I get a “A disk read error occurred” error when I try to boot from the new disk…

  6. 6 Nick Heppleston

    Jules,
    I don’t know whether a dynamically expanding disk needs some ’special’ configuration within the disk itself, so maybe it isn’t possible…. Out of interest, are you sure that you marked the partition as bootable before you tried to use it?

    Nick.

  7. 7 Chris

    Great steps! Thanks for figuring this out and passing it along!

  8. 8 Chris

    Let me add a bit to the end of the process - I did this with an XP image, and though everything appears to work fine, I did see one issue. During the boot process, Chkdsk ran, didn’t find anything and booting continued. Once XP got to the login screen, VirtualBox reported a fatal error and was “stuck”. VB locked up good at that point so I killed it and restarted. 2nd time was the charm. The VM came right up, and once logged in, the Add Hardware process picked up the new disk.

  1. 1 When Windows Won’t Load | Job Searching Blog

Leave a Reply