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.

new-virtual-disk.jpg



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.

add-new-virtual-disk-as-primary-slave.jpg



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.

mount-cd-dvd-rom.jpg



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.

enable-boot-from-cd-dvd-rom.jpg



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:

ending-sector.jpg



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:

fdisk-sdb-new-partition-created.jpg



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):

fdisk-sdb-hex-code.jpg



Now, type "w" to write all changes to the disk and exit:

fdisk-sdb-changes-written-to-disk.jpg



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:

sdb-with-lots-of-free-space.jpg



Right-click on the partition and choose Resize/Move:

drag-to-resize.jpg



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:

use-full-size-for-sdb.jpg



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.

ntfs-check-finished.jpg



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:):

windows-xp-new-big-partition.jpg



Open disk management (right-click on MyComputer → Manage → Storage → Disk Management). Right-click on your new partition and click Mark Partition as Active:

marked-partition-as-asctive.jpg



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:

new-disk-configuration.jpg



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:

final-screenshot.jpg



I hope this helped...

13 Comments

  1. Scott says:

    Hello. I have a question. I used this tutorial to expand a 5GB disk to a 20GB disk. Everything seemed to go well until I try and boot up with the new disk, and the system hangs at the "welcome" screen..... do you have any idea why this would happen?
  2. George says:

    Thank you for a great howto!
    Exactly what I was looking for. :)
  3. Rainer says:

    Thx for your howto! I found out that you can leave out the fdisk part if there is only one (and no more than that - like in the tutorial here) partition on your harddisk. You just have to leave out the partition-identifiers with dd:

    dd if=/dev/hda of=/dev/hdb

  4. Mohamed Ghuloom says:

    You're a guy with style!
    Thanks man. totally understandable.. I can do it with no errors at all, but I want to do a refresh install, it's gonna be better. I'm having problems installing some programs so i guess my xp is corrupted somehow don't know.
    Plus that tutorial of yours which we add a new Host interface in the Adapter 1 section so we can connect to the network instead of using the shared folers. It was working PERFECT, until i restarted and now i can't login to my xp.. it tells me: "cannot initialize Host interface". when i go and disable it in the Adapter 1 section, it works fine but i can't access my files.
    Thanks dude, ur a great guy
  5. Attila Heidrich says:

    all ok except the last step... old XP sees the new disk, and shows active, but when i try to boot from the new disk, it says "disk read error"...
  6. Peyton says:

    Thanks so much for the tutorial. I actually used Rainer's method to copy my virtual installation of Vista (same principle). It asked me to insert my installation disks for recovery mode. After that ran, it booted like a charm!
  7. Someone says:

    Thanks that was a wonderfully useful tutorial. Will have to try it tonight when I get home.
  8. Nick says:

    Thanks for the guide Giannis.
    I noticed to boot the Ubuntu livecd, in the settings for my VM under "CD/DVD-ROM" I needed to enable "passthrough" (wasn't by default), then all worked fine.
    Cheers,
    Nick
  9. Terabyte says:

    Thx m8

    Great howto - everything was as described
  10. Thorsten Sperber says:

    Hi,

    you are using gparted to enlarge the partition, but why don't you use it for the other part?

    My steps:

    1. Create new Harddisk
    2. Boot from any Linux CD with gparted
    3. Copy with gparted from a to b and enlarge.

    Finish!
  11. Theseus says:

    to Attila Heidrich:
    I had the same problem... this fixed it http://forums.virtualbox.org/viewtopic.php?t=6627 ... good luck
  12. RoDush says:

    Cool guide!

    It is just particular I needed!
    But in my case one had to make changes (extention) for the disk where I had Kubuntu install.
    In that case you just need create more then one partitions: one 'Extended' and one for 'swap'.
    It was quite fun and simple!

    Thnx a lot again!
  13. ralphie says:

    thanks this really helped me out

Leave a Reply