Update 17th April 2009: This post has been updated to include the latest suggestions posted to the comments, including using the gparted Live CD instead of the Gentoo Linux System Rescue CD.
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.
- Ensure that the Virtual Machine that uses the disk you want to re-size is shutdown.
- Remove any snapshots you may have – VirtualBox can go a bit wonky when re-sizing a VDI with snapshots attached (thank to Darren for pointing this one out).
- Take a backup of your VDI that you want to resize (by copying and pasting the .vdi file in Windows Explorer) – if we mess our resize up we can recover back to this backup.
- While the VDI file is copying, download the latest stable release of the gparted Live CD ISO from Sourceforge (approx 95Mb).
- While the ISO is downloading, create a new empty 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 – you may need to reconfigure your VM to ensure that you boot from the CD-ROM drive before the HDD, so change the VM settings as shown below or hit F12 at boot and change there (given that VirtualBox is currently under development, the screenshot below will always be out of date, but I’m sure you get the idea ;-):
- During the boot process the gparted Live CD will prompt you to select the correct keymap – if you are using a QWERTY keyboard, simple select the ‘Don’t Touch Kepmap’ option; next, you will be prompted for the language settings to be used – select the appropriate language code, in my case ’02’ for British English; finally, you will be prompted for the X-Windows mode – select ‘0’ to automagically start gparted in an X-Windows session.
- 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 (possibly /dev/hdb in your environment), the graphical representation of your disks will change to show you the second slave disk which is currently empty. Click on the Paste icon.
- gparted will will prompt you that all data on the new partition will be erased and if you’re happy, subsequently prompt you on how the disk should be formatted. For a Windows environment, select MSDOS (this will give you an NTFS partition, trust me!).
- gparted will finally present you with a slider dialog indicating the desired 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), as shown in the screenshot below:
- 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. gparted will apply the necessary flag and re-scan your disks.
- Close gparted and click the Exit icon 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. Windows may perform a check of the disk during boot. 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.
Related articles by Zemanta
- Gizmo Drive Mounts ISO, BIN, and VHD Disk Images (lifehacker.com)