This is my success story on enlarging my VirtualBox disk with Windows XP installed, without re-installing anything.
If you want to follow the instructions given here, you will have to get a copy of Ubuntu 7.10 Desktop Edition, because we are going to take advantage of some great pieces of software contained in it.
The whole procedure takes a couple of hours to complete, but the result will be rewarding! So, here we go!
Step 1. Create your new virtual disk
Start VirtualBox and go to File → Virtual Disk Manager. Create a new virtual disk. Make it big enough to meet your needs. At the end, this virtual disk will replace your old one.
Step 2. Attach the new disk to your virtual machine
Go to your virtual machine’s Settings and then go to Hard Disks. Tick the Primary Slave checkbox and select your new virtual disk to be used as primary slave.
Step 3. Mount the Ubuntu 7.10 LiveCD
Go to your virtual machine’s Settings and the go to CD/DVD-ROM. Tick the Mount CD/DVD Drive checkbox. Select to mount the CD either from your computer’s CD/DVD Drive, or from an .iso image file.
Step 4. Start Ubuntu
Make sure that your virtual machine will try first to boot from CDROM. Go to Settings → General → Advanced → Boot Order. Make sure that CD/DVD-ROM is checked.
With the Ubuntu CD mounted start your virtual machine. When the boot menu appears choose the first option, Start or install Ubuntu.
Step 5. Create a clone of your partition on the new virtual disk
When the system comes up, open a terminal window. Go to Application → Accessories → Terminal. When the terminal opens run this command:
sudo fdisk /dev/sda
On the fdisk prompt, type “p” to take a look in the existing partitions of your old virtual disk. Normally you should only be able to see only one. From all the displayed info, we will only keep the End sector of your partition:
Write it down because we will need it very soon. Type “q” to exit fdisk.
You will now create a partition with the same size in your new disk. Type this command:
sudo fdisk /dev/sdb
Type “n” to create a new partition. When prompted, choose “p” to make it a primary partition, and select 1 as the partition number. Enter 1 (default) as your First cylinder and the number you previously wrote down as the Last cylinder:
Then you should set the partition type to be NTFS (that would be the most likely for a Windows XP partition). Type “t” at the fdisk’s prompt. When prompted for the Hex code, enter 7 (HPFS/NTFS):
Now, type “w” to write all changes to the disk and exit:
Now you have a new partition in your new virtual disk with the exact same size. Now it’s time to make a verbatim copy of all the data in your old partition to the new one. Run this command:
sudo dd if=/dev/sda1 of=/dev/sdb1
It will take some time. In fact it will take a lot of time. For my 20GB partition it took almost one hour and a half. So, be patient!
Step 6. Enlarge your new NTFS partition
Now we are going to use GNOME partition editor to enlarge the NTFS partition in the new virtual disk. Go to System → Administration → Partition Editor. Wait until the program scans your devices. Then go to GParted → Devices → /dev/sdb. You should be able to see your newly created NTFS partition and lots of unallocated space following it:
Right-click on the partition and choose Resize/Move:
Grab the right-arrow of the partition with your mouse, and drag it to the right so it occupies the full capacity of the disk:
Then click Ok. Click Apply (or go to Edit → Apply All Operations). Seat back whilst the program enlarges your partition. It will take some minutes.
Step 7. Make your new virtual disk bootable
When the resizing is finished the program will scan your devices again. When the scan finishes close the partition editor, and shut down the virtual machine. Go to System → Quit → Restart. You will be prompted to remove the disc and press enter. Unmount the CD (in VirtualBox, go to Devices → Unmount CD/DVD-ROM) and press enter to continue.
The virtual machine will now boot your original Windows XP. Windows will recognize your new parition and will tell that it needs to be scanned for errors. Let windows scan your new partition. It will take some time.
When scan finished you will be able to see your new partition under My Computer (it should have been assigned with a driver letter, like E:):
Open disk management (right-click on MyComputer → Manage → Storage → Disk Management). Right-click on your new partition and click Mark Partition as Active:
Step 8. Remove the old virtual disk
Shut down Windows. When the virtual machine is powered-off go once more to your virtual machine’s Settings → Hard Disks. Select your new virtual disk as the Primary master, and select no primary slave at all:
That was all! It wasn’t that hard, was it? You should now be able to boot your virtual machine, and find everything in place just as you remember it, except from more free space in your C: drive:
I hope this helped…