How to enlarge a VirtualBox disk.

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…

This entry was posted in Uncategorized. Bookmark the permalink.

31 Responses to How to enlarge a VirtualBox disk.

  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. 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

  14. Jonas says:

    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…

  15. Kirk says:

    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.”

  16. Peter Hansen says:

    Thanks much!

  17. DiCeR says:

    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.

  18. Trevor says:

    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.

  19. Amadeu says:

    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!

  20. Amadeu says:

    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” ;-)

  21. PedroA says:

    You made my day :-) Followed the HOWTO step by step and had no problems.
    I used the Ubuntu 9.04 ISO

    Congrats & thanks,
    /PA

  22. Googie says:

    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!

  23. Andreas says:

    Thx.
    Simple as hell. Just remember; download your 32-bit Ubuntu ISO from here: http://torrent.ubuntu.com:6969/
    And then mount the ISO.

  24. toni says:

    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.

  25. Rob says:

    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.

  26. josh says:

    Use CloneVDI tool:
    http://forums.virtualbox.org/viewtopic.php?f=6&t=22422
    It’s a VERY GOOD tool :D

  27. SillYcoNe says:

    There are simpler ways of doing it but what is described here works and it is very well explained.
    Thank you for the effort.

  28. Dmitry S. says:

    Use BS (block size) key in dd to increase speed of copiing

    dd if=/dev/sda1 of=/dev/sdb1 bs=1024k

  29. D. Morlock says:

    You can skip the partition part using fdisk, you you copy the whole partition table:

    dd if=/dev/sda of=/dev/sdb

  30. M Venter says:

    You are a legend!

    Thanks a mil for the guide!

  31. Andreas says:

    Win 7 has 2 partitions!

    That’s why I cleverly tried this suggestion from the comments:

    > You can skip the partition part using fdisk, you you copy the whole partition table:
    > dd if=/dev/sda of=/dev/sdb

    but then the clone disk had the same “signature” which results in a “harddisk signature collision”.

    So I fiddled around with

    sudo blkid
    sudo dd if=/dev/urandom of=/dev/sdb1 bs=8 count=1 seek=9

    and in Windows
    diskpart http://www.howtohaven.com/system/change-disk-signature.shtml
    but in the end Windows didn’t boot it anymore ;-(

    *sigh* All these attempts take ages, because copying a 25 GB file just needs that long.

    Given up. I now went all the way back to cloning with VBoxManage.exe
    http://www.streamwave.com/systems-administration/how-to-extend-your-virtualbox-virtual-hard-drive/

    but this time deleting/merging all the snapshots before I started. (Otherwise the clone would stupidly load the oldest not the newest snapshot – the anger about that was my reason to have come here in the first place.).

    There is an old tool called “cloneVDI”, but my antivirus warned about a “MalSign.Generic.834″ – so I didn’t touch that.

    Now, half a bad computer karma day later … I have solved it, but
    I hate hate HATE ORACLE for making this simple thing so artificially difficult.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>