How to enlarge a VirtualBox disk.
November 25th, 2007
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:
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:
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:
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...
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/sdaOn 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/sdbType "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/sdb1It 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...
January 14th, 2008 at 9:23 pm 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?
January 26th, 2008 at 2:32 am Thank you for a great howto!
Exactly what I was looking for. :)
March 26th, 2008 at 4:37 pm 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/hdbJuly 30th, 2008 at 6:40 pm 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
August 11th, 2008 at 5:34 pm 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"...
September 5th, 2008 at 5:02 am 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!
September 12th, 2008 at 10:51 pm Thanks that was a wonderfully useful tutorial. Will have to try it tonight when I get home.
September 17th, 2008 at 8:38 am 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
September 27th, 2008 at 4:22 pm Thx m8
Great howto - everything was as described
September 29th, 2008 at 1:41 pm 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!
October 28th, 2008 at 1:21 am to Attila Heidrich:
I had the same problem... this fixed it http://forums.virtualbox.org/viewtopic.php?t=6627 ... good luck
November 19th, 2008 at 3:09 pm 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!
December 6th, 2008 at 12:42 am thanks this really helped me out
January 30th, 2009 at 6:30 pm Thanks for the howto! Another small tip: calling dd without any further options will copy everything byte by byte, which takes forever. Add an argument for the blocksize to make dd read a certain amount of data into memory before writing it to the output.
For instance, instead of
sudo dd if=/dev/sda1 of=/dev/sdb1
try calling it like this:
sudo dd bs=64M if=/dev/sda1 of=/dev/sdb1
That's MUCH faster...
April 2nd, 2009 at 5:19 am Thanks for the howto, good thinking. Also, I've found you don't need to use Windows Disk Management at all. Instead after you create the partition and set the type for the second disk, use the "a" option in fdisk to make the partition bootable before using "w" to write and exit. Then before the reboot just change the primary drive to the new resized partition which is already bootable. It will do the disk scan and come up just fine. Although Windows will ask you to reboot once since it detects "new hardware."
April 7th, 2009 at 5:18 pm Thanks much!
May 19th, 2009 at 12:58 pm Thank you for this hint with regards to expanding Virtual HDs. It made me /facepalm and go "Why didnt I think of this myself?" However; I find your use of dd and parted rather tricky, and for someone without prior linux experience, it might even lead to a lot of frustration.
Instead - I urge readers with this 'problem' to consider a dedicated HD-clone tool (like those listed in http://www.thefreecountry.com/utilities/backupandimage.shtml )
I have personally tested the 100% free "HDClone Free Edition" (you even get boot-ready ISO and floppy-images!) and although it is a slow copy (10mbit/s), it is a very simple and intuitive program. No need to worry about partitions or resizing, as the program does all by itself. For the people in a hurry or that have special cloneing-needs - buying HDCLone might be a good option.
May 23rd, 2009 at 9:12 pm I had problems getting Ubuntu to boot up from my Virtual XP CDROM drive
so I downloaded HDClone free edition and it was SO easy. I just copied the smaller
disk to the larger one and then booted from the new virtual drive and
ran a chkdsk /F
It was very easy.
July 6th, 2009 at 4:57 pm Please, you just don't need of property tools. GParted offers a livecd version for free (like in freedom). It's very easy to use and works fine!
Look this:
http://sourceforge.net/projects/gparted/files/
I used gparted-live 0.4.5-3 just now. Great tool!
July 6th, 2009 at 5:01 pm Well two mistakes:
1. *property .. I mean "proprietary" ;-)
2. I forgot to reference the original post that show me how is easy to use the gparted live in that situation: http://www.my-guides.net/en/content/view/122/ approach: "CTRL+C & CTRL+V" ;-)
July 27th, 2009 at 1:57 pm You made my day :-) Followed the HOWTO step by step and had no problems.
I used the Ubuntu 9.04 ISO
Congrats & thanks,
/PA
November 7th, 2009 at 2:57 am Thanks a Bunch! I booted using an Ubuntu ISO (easy) and used Gparted. Copy/paste to get the drive partitioned, copy/paste to move the drive contents and set the boot flag on. It took some time but was simple!
December 13th, 2009 at 11:02 pm Thx.
Simple as hell. Just remember; download your 32-bit Ubuntu ISO from here: http://torrent.ubuntu.com:6969/
And then mount the ISO.
January 19th, 2010 at 12:04 am You can copy & paste partitions in GParted. That way, no resizing is to be done. Just select partition in /dev/sda (menu in the right top corner), click on it, copy, then select /dev/sdb, click, paste, enlarge to fill all the space, click Apply.
February 9th, 2010 at 4:21 pm As toni and a couple of others have correctly pointed out, GParted on a live CD will do the whole thing with far less faffing about. Before closing down GParted, just remember to do Partition -→ Manage Flags and check "boot", otherwise Windows WON'T boot from the new hard disk. This way you can simply shut down the virtual machine, unattach the original C: disk and attach the new bigger one, and reboot straight into Windows on the bigger disk.
March 10th, 2010 at 7:54 pm Use CloneVDI tool:
http://forums.virtualbox.org/viewtopic.php?f=6&t=22422
It's a VERY GOOD tool :D
March 20th, 2010 at 8:08 pm There are simpler ways of doing it but what is described here works and it is very well explained.
Thank you for the effort.
April 1st, 2010 at 3:55 pm Use BS (block size) key in dd to increase speed of copiing
dd if=/dev/sda1 of=/dev/sdb1 bs=1024k
May 6th, 2010 at 3:16 pm You can skip the partition part using fdisk, you you copy the whole partition table:
dd if=/dev/sda of=/dev/sdb