Running ESXi 4.1 in freebie mode, I accidentally created an XP virtual machine with an 8GB hard disk (instead of the intended 80GB). Inevitably, I failed to notice this until after I’d spent the best part of a day upgrading the thing to Kingdom Come and configuring large amounts of software. Starting from scratch with a new VM and a correctly-sized disk was, then, out of the question. But how, then, do you increase the size of an existing virtual hard disk?
With great difficulty, in a nutshell!
If you Google around a bit, you’ll see various people suggesting you can get yourself into the host machine’s “Tech Support Console” and run the command vmkfstools -X 80G ./name-of-disk-file.vmdk. However, when I tried this, I was told that the relevant file was not a valid virtual disk file… so, end of experiment with that technique. (I believe you can get this error message if the virtual machine has snapshots. Also if the file is corrupt!)
Anyway, here’s what I ended up doing instead to resolve the issue (and it’s not exactly pretty!)
First, shut down the virtual machine if it’s not already. Then right-click and Edit Settings. Add a second hard drive, this time sized correctly. Once that’s added, reboot the virtual machine.
Next, from within the virtual machine, visit http://www.miray.de/download/sat.hdclone.html and download the zero-cost HD Clone utility for Windows (the .exe is fine, no need for the .zip). Run that and install the software. If necessary, reboot once more.
Third, run the HD Clone utility. Select the Cloning option, and allow it to detect the two hard disks. Follow the prompts to clone the small original disk to the larger new one. Let it do its stuff (it took about 7 minutes to clone an 8GB drive). When prompted, allow it to automatically resize the finished clone, and do whatever else it feels needs to be automatically adjusted.
When the clone is complete, shut down the virtual machine. Go back to the right-click-edit-settings option and assign the first hard drive (the original boot disk) to IDE controller 1:1 (it started off on 0:0, which is what made it the first -and boot- hard disk). This frees up the 0:0 location for the second, larger hard disk you’ve just created, so now you click that and assign it to the just-freed-up 0:0 IDE interface (making it the new boot disk). Lastly, you click the original hard disk and click the Remove button (if you’re not feeling brave, select the option to remove the disk from the virtual machine without deleting the files off the physical host!).
This little game of deckchair shuffling means the new, larger hard disk ends up occupying the same position in the IDE chain of command as the original, smaller, one did. So when you now power on the virtual machine, it should correctly boot from the new hard disk. Windows XP certainly did, first time of asking -and then promptly went into that ‘new hardware has been detected, you must reboot for it to work properly’ routine. One further reboot later, therefore, and I finally ended up with an XP machine running on an 80GB virtual hard disk rather than an 8GB one.
I have read that you might need to jiggle the boot flags on the new hard disk, but I didn’t have to. If you do, you’ll have to alter the VM so that its CD/DVD Drive is pointing to an ISO of Gparted. That will let you set the new hard disk to be bootable, and then you should be good to go. Happily for me, HD Clone seems to take care of this by itself, so as I say, I never had to do this further bit of fiddling.
If all has gone well, you can use the ESXi Browse Datastore option to remove the physical file associated with the original virtual hard disk if you weren’t brave enough to physically delete it originally. You can also uninstall HD Clone from within the virtual machine, since you won’t (presumably) be needing it again. HD Clone works fine in Windows 7, by the way, so the same basic technique should apply to any vaguely-recent version of Windows, not just XP.