Fast, Efficient Message Archiving for BizTalk with the BizTalk Message Archiving Pipeline Component. Download a Free 14-Day Trial!

Re-sizing a VirtualBox Virtual Disk Image File

Update 17th April 2009: This post has been updated to include the latest suggestions posted to the comments, including using the gparted Live CD instead of the Gentoo Linux System Rescue CD.

In my previous post I extolled the virtues of Sun’s desktop virtualisation software, VirtualBox. One thing niggled me though – I couldn’t easily expand a Virtual Disk Image (VDI) and was regularly reaching the space limits of the modest 20Gb disks I was creating; I needed an easy way of expanding disks before I could use it as my main virtualisation platform and felt comfortable in recommending it to my readers.

Given that there is very little information out there on how to perform this task – apart from a single obscure forum post – here is my attempt to walk you through the process of expanding a virtual disk image. This guide assumes that you are trying to expand a disk configured with Windows, however the procedure should be pretty much the same for a Linux/OpenSolaris etc. based disk.

Getting Started

  • Ensure that the Virtual Machine that uses the disk you want to re-size is shutdown.
  • Take a backup of your VDI that you want to resize (by copying and pasting the .vdi file in Windows Explorer) – if we mess our resize up we can recover back to this backup.
  • While the VDI file is copying, download the latest stable release of the gparted Live CD ISO from Sourceforge (approx 95Mb).
  • While the ISO is downloading, create a new empty Virtual Disk in the VirtualBox console that is the size of the larger disk you need.
  • Attach the new disk to your virtual machine that needs its disk expanding as the slave disk.
  • Once the System Rescue CD download has completed, mount the ISO on the virtual machine CD drive.

Starting the Disk Image Utility

  • Boot the virtual machine from the mounted ISO – you may need to reconfigure your VM to ensure that you boot from the CD-ROM drive before the HDD, so change the VM settings as shown below or hit F12 at boot and change there (given that VirtualBox is currently under development, the screenshot below will always be out of date, but I’m sure you get the idea ;-):

virtualboxbootorder

  • During the boot process the gparted Live CD will prompt you to select the correct keymap – if you are using a QWERTY keyboard, simple select the ‘Don’t Touch Kepmap’ option; next, you will be prompted for the language settings to be used – select the appropriate language code, in my case ‘02′ for British English; finally, you will be prompted for the X-Windows mode – select ‘0′ to automagically start gparted in an X-Windows session.
  • Once gparted starts, you will be presented with a graphical representation of your disks – left-click the left-to-right bar named /dev/sda1 (your primary hard disk that is to be expanded) and then click on the Copy icon.
  • Select the drop-down-box to the right of the tool-bar and select the second (currently empty) disk – /dev/sdb (possibly /dev/hdb in your environment), the graphical representation of your disks will change to show you the second slave disk which is currently empty. Click on the Paste icon.
  • gparted will will prompt you that all data on the new partition will be erased and if you’re happy, subsequently prompt you on how the disk should be formatted. For a Windows environment, select MSDOS (this will give you an NTFS partition, trust me!).
  • gparted will finally present you with a slider dialog indicating the desired size of the new disk. Drag the slider to the right to select the maximum size of the new partition on this new disk (I’d just drag it so the partition consumes the whole disk), as shown in the screenshot below:

selectsizeofnewpartitiongparted

  • Click the Apply icon, you’ll be presented with something along the lines of the screenshot below as the contents of the source disk are copied to the new, larger, disk:

  • Once the copy has completed (approx. 35 mins to create a 30Gb disk from an original 20Gb disk), you will need to mark the new disk as bootable (if this is to be a bootable partition – if not, simply skip the next step).
  • To mark the partition as bootable, right-click the graphical representation of the new disk and left-click Manage Flags. In the dialog that appears, select Boot and click Ok to close. gparted will apply the necessary flag and re-scan your disks.
  • Close gparted and click the Exit icon to shutdown the system.

Completing the Re-Sizing

  • Once the virtual machine has powered off, re-configure the hard disks to use the newly created/copied disk as the primary and remove the old primary disk from the system; finally, unmount the System Rescue ISO from the CD-ROM.
  • Power on your new VM and you should be presented with the the usual Windows boot sequence; if you are just presented with a black screen with a flashing cursor at the top left-hand corner of the screen, there isn’t a boot sector on the disk, so restart gparted and add the boot flag as directed above.
  • Hopefully, your virtual machine will start without issue. Windows may perform a check of the disk during boot. Once logged-in, open Windows Explorer and confirm that the newly created drive is the new larger size.

The procedure described above has been tested on Windows Server 2003 and works without issue (although the first time around I forgot to apply the boot flags…), so it should work seamlessly on Windows XP, Vista and Windows Server 2008.

I appreciate that this procedure does involve running a flavour of Linux to acheive the desired results, however its very straightforward and shouldn’t be off putting to a Linux novice.

Reblog this post [with Zemanta]

61 Responses to “Re-sizing a VirtualBox Virtual Disk Image File”


  1. 1 Tomas Restrepo

    Nice post, Nick! VBox is a pretty nice virtualization platform (I use it for linux guests, but been a bit reluctant to move my existing vpc images over to it).

    BTW, if the guest OS is vista or WinServer2k8, you should be able to resize the partition using Disk Manager directly from the OS without having to go through the system rescue cd.

  2. 2 Nick Heppleston

    Tomas,
    Thanks for the pointer, I’ll try Disk Manager later today on a 2008 Server. One question though: how can Disk Manager increase the size of a partition if the virtual disk is already at its size limit?

  3. 3 Briefe Schreiben

    Hey! Your Post “ng a VirtualBox Virtual Disk Image File at Nick Heppleston’s BizTalk Blog” is very interesting for me. Unfortunately my written English is not so good so I write in German: Dir, meinem liebsten, geh

  4. 4 Be_Mons

    Nice!!!!Thanks a lot!!!!quick and easy way to do it!!!!

  5. 5 Jules

    Clear, concise instructions — many thanks.

    Can these same steps be used to copy a fixed-size disk to a dynamically expanding one? I can’t see any reason why not, but after trying it, I get a “A disk read error occurred” error when I try to boot from the new disk…

  6. 6 Nick Heppleston

    Jules,
    I don’t know whether a dynamically expanding disk needs some ’special’ configuration within the disk itself, so maybe it isn’t possible…. Out of interest, are you sure that you marked the partition as bootable before you tried to use it?

    Nick.

  7. 7 Chris

    Great steps! Thanks for figuring this out and passing it along!

  8. 8 Chris

    Let me add a bit to the end of the process – I did this with an XP image, and though everything appears to work fine, I did see one issue. During the boot process, Chkdsk ran, didn’t find anything and booting continued. Once XP got to the login screen, VirtualBox reported a fatal error and was “stuck”. VB locked up good at that point so I killed it and restarted. 2nd time was the charm. The VM came right up, and once logged in, the Add Hardware process picked up the new disk.

  9. 9 Amit

    Your steps are really helpful. Great work. Thanks…

  10. 10 jconstantino

    thanks! :)

  11. 11 sonofjon

    Pretty good instructions! Took me less than 15 minutes in total to increase my Windows XP from 4GB to 8GB. Everything runs fine. Very cool. Thanks! PS. I use dynamically expanded storage format.

  12. 12 Myke

    Worked like a charm for me too. (increased Windows XP from 7GB to 22GB). Thanks a lot for this!

  13. 13 Mike Rooney

    Thanks, very awesome tutorial, this worked for me! However I’d recommend using the gparted live cd instead, which is what I used. It is 95 megs instead of 230, and automatically boots into a graphical environment after choosing the keyboard, so it shouldn’t be as off-putting as you aren’t ever manually typing things into a terminal. Additionally there is a shut-down icon on the desktop so you don’t have to manually halt it either. By the way this worked fine on a dynamic image (.vdi) file. Thanks again!

  14. 14 Antoine Leclair

    Thanks for the tutorial. Worked great for my Vista 32-bits guest under Ubuntu 8.10 64 bits.

    I had to mount Vista .iso to repair the installation after resizing (something about the booting). Anyway, worked great, withouth hacking anything.

  15. 15 Elvis

    Imagine, I ran out of virtual disk space after migrating iTunes and all my music to my virtual Windows machine.
    Gotta love open source software! Let’s all pray that Sun can remain that way.

    - Kubuntu 8.10, Vbox 2.2

    Elvis

  16. 16 Nick Heppleston

    I have updated this post to include all comments so far – many thanks to those who have commented. Nick.

  17. 17 Andrew Barnes

    Brilliant guide – did EXACTLY what I needed it to – thank you very much!

  18. 18 UncleBoxy

    @Nick Heppleston

    Great post man. I was definitely skeptical about having to download GParted and use it, but it actually turned out to be a great learning experience. I’m not really new to Unix or Linux, but I’m not expert at it either. The GUI and your instructions on using it were spot on and very helpful.

    @Antoine Leclair

    Thanks for the advice for Vista. By following your additional instructions, I was able to get a Vista 64 bit guest running on a Vista 64 bit host.

    This may alarm some people, so I think it’s worth a mention: CHKDSK ran when Windows started up the 1st time, and after that it (of course) booted fine.

    Good stuff. Thanks

  19. 19 Afonso Junior

    excelent post. Congratulations!

  20. 20 mlopez

    Thanks!

  21. 21 Bart

    Followed the guide successfully for a Windows 7 install. The only additional step needed was to repair the Windows 7 install before it was able to boot.

  22. 22 Jonathan

    Worked perfectly. Thanks!

  23. 23 Alex

    Hi Nick,

    have tried it today.
    unfortunately I had the same problem than Jules and got a “A disk read error occurred” error.
    I have tried it with an dynamically expanding one and a fixed one.
    Both of them create the same error message.

  24. 24 Rob W

    This was great! Thank you so much. I was not paying enough attention on my initial install. How annoying that clonevsi doesn’t accommodate this.
    After following these instructions my experience was a little different:

    * upon boot into Vista after making a larger partition and otherwise following these instructions, I got an error from windows about winload.exe not being found.

    * I booted with my vista disk, hit repair and let it reboot and do something to the disk and it’s all good now.

    Thanks for this tutorial

  25. 25 Luke

    Thanks for this guide Nick. It has been very helpful and instructions are nice and clear.

    Cheers!

  26. 26 jiez

    thanks, man! It is really helpful.

  27. 27 Dave

    Thanks so much. I’m a relative novice with Linux and I followed this with no problem. Worked perfectly with a XP dynamic machine.

    Well done!

  28. 28 Dinesh

    One more happy camper, thanks to your instructions. Of all the options I’ve seen to accomplish the task, this was the simplest, the most straightforward. Thanks much.

  29. 29 Alex

    Thanks Nick, worked like a charm for a Windows guest under a Linux host.

  30. 30 Nick Heppleston

    Thanks for the positive feedback guys ;-)

  31. 31 Tim Toombs

    Nick,
    Thanks! These instructions worked like a charm. I had the same problem with the Vista-32 reboot as Rob W. and Antoine, but the Windows “Repair” was quick and painless.
    Host: Ubuntu 9.04 – 64bit
    Client: Vista-32 Ultimate

  32. 32 mehdi

    I used the procedure for Server 2008 and it FAILED:

    Although I made the disk as “boot” as instruction, but it failed to start normally. I tried to repair it from by windows installation CD and it didn’t also work out! May be it is better to make a whole backup when from OS running , not just simply copy the image of system (VDI) which doesn’t help at this stage.

  33. 33 Fantastic! Worked perfectly.

    Worked perfectly with latest VirtualBox, Karmic, and XP Pro guest OS.
    Thanks a bundle!

  34. 34 Great post!

    Thanks a lot!

    Worked perfectly with ubuntu 9.10 64 bit as host, virtualbox 3.0.12 and winxp sp3 as guest.
    The instructions are very easy to follow.

  35. 35 Rob

    First off, thanks for the great information!

    For anyone that stumbles on this post, I wanted to share my experiences with a Win2008 x64 guest on a 64 bit win7 host:

    You will need to repair the 2008’s boot sector, its just not very intuitive to find the fixboot command anymore. follow these steps:

    Boot using the installation media
    Select repair
    Select the partition and click ok
    Choose the command line option
    At the command prompt type c:
    Type bootrec.exe /fixboot
    Type exit and reboot the machine.

    It may take a bit for the machine to start, and scandisk will run, but you will successfully be up and running.

  36. 36 Kamil

    Kudos for this awesome idea and walk-through!

  37. 37 Paul

    Have tried this with Windows Server R2 guest on Windows 7 host with no success, including Rob’s suggestion for using the repair option. When Gparted runs it shows TWp partitions in the existing single 20GB vdi drive. the /dev/hda1 is quite small and the main disk (showing as 20GB) is dev/hda2. I copied the hda2,set its boot flag and then applied Rob’s Server 2008 x64 trick to do a repair from installation media for bootfix. IT applied this and said successful but then on reboot get the “BOOTMGR” is missing. My guess is that this is the small partition (/dev/hda1)that I did not copy. I cannot see how within Getparted that I can clone a disk to be both partitions or copy them sequentially as it looks as the second will over right the first.

    Any suggestions to copy both partitions – wonder about using a disk cloning tool from within Server 2008R2

  38. 38 Paul - follow up

    re: server 2008R2. I have now got both partition on the new larger drive (using Gparted) and have marked the first one -it is 100MD only- as boot i.e. it mirrors the stup of original.Have run the bootfix trick as per Server 2008 but still will not boot. Get an error message saying it is missing a Driver and asking to reboot from installation media and do a repair but not sure what else I should repair. Any suggestions – not familiar with the repair command line.

  39. 39 Oscar

    Excelent tip… Thank you, It help me a lot

  40. 40 Scott

    EXCELLENT! Thanks so much! I couldn’t find anything about resizing a VDI before I found this. I just assumed it would be an option right within the Virtual Media Manager… yikes, NOT.

  41. 41 simi

    thanks mate, this worked for me like a charm. running vbox on ubuntu karmic, needed to enlarge my winxp drive a little.

  42. 42 David Souther

    If all you need to do is increase the size of a virtual box disk image, I have found this to be slightly more effective.

    1) Create a new expanding disk image of the appropriate maximum size
    2) Attach this as the slave image
    3) Mount a Ubuntu (or whatever) live disk
    4) Boot into the live disk
    5) run “dd if=/dev/sda of=/dev/sdb” (double check the correct /dev/sd’s, they should be right but this could kill your disks very quickly if you have if and of backwards).
    6) Power off the vm, remove the small disk from the machine, set the large disk as master
    7) Boot the machine.

  43. 43 Juca

    Tks! Works like a charm!

  44. 44 justin

    Instructions work great running a win xp on virtual box on an iMac. One thing I had to do to get the image to boot into gparted iso was to remove the guest editions mounted iso file (the gparted iso came up as a second cd drive). Otherwise perfect!

  45. 45 Pom

    Perfect, You save my live. Thanks a ton.

  46. 46 Xavier

    It worked great!
    Thanks…

  47. 47 Ryan C

    Nick,

    This post was excellent. I was linked here from http://www.ubuntuforums.org, and was happy they knew of this gem. I just followed the steps one by one (some parts are outdated with the current version of VirtualBox), but all in all, it worked beautifully. I just rebooted, and was now finally able to finish the XP updates on my virtual install.

  48. 48 IPityTheWise

    Excellent HOWTO!!!!!!

    I forgot to expand the gui of my copied vdi. So I initially had the VDI + 40 Gigs of unallocated space. I went back in, expanded the GUI and voila!!!! Instant resized drive.

    Lesson: READ THE ENTIRE POST FIRST. Don’t skim through it. If you brick your drive(s), you will have wished you had.

    AGain, Great HOWTO…thanks a million!

  49. 49 Ion Freeman

    I’m having the same issue as Paul. I open gparted on a Windows 7 image to see three partitions,
    unallocated 1.00 MiB
    /dev/hda1 System Reserved 100.00 MiB boot
    /dev/hda2 9.90 GiB

    I feel like I could live without ‘unallocated,’ but I don’t seem to be able to copy both of the others at once, and I’ll take Paul’s word for it that copying them sequentially won’t work. How do I proceed?

  50. 50 Ion Freeman

    Actually, they didn’t really turn out to be issues at all. I copied over hda1 then hda2 — they didn’t overlap.
    Shutting down gparted took far longer than I had expected, with many message list

  51. 51 Gnana

    Beautiful! Thank you. Just one addition, when started for the first time windows does a disk scan….

  52. 52 Paul

    Excellent post, Nick. Just an FYI, I’m running openSolaris as the host with multiple Windows VMs and this works fine with that configuration as well.

  53. 53 Nick Heppleston

    Paul,

    Many thanks for the feedback on the OpenSolaris host.

    Cheers, Nick.

  54. 54 Boyan Boychev

    Hi all,

    If your root partition is lvm type and you are using LVM try this out:
    ——————————————————————————————————————————————–
    Use LiveCD with dd and fdisk utilities:
    —————————————-
    1) dd if=/dev/hda of=/dev/hdb # /dev/hda – old disk with smaller size, /dev/hdb – new disk with bigger size
    2) fdisk -u /dev/hdb
    3) Steps from 2) to 6) (incl.) described here – http://www.linuxquestions.org/questions/fedora-35/lvm-partition-resizing-666683/#post3281556
    4) Shutdown the Virtual machine and remove the old disk and the LiveCD from the virtual CDROM

    After the shutdown, boot the system normally (only with the new disk and without the LiveCD):
    ———————————————————————————————
    5) pvdisplay -v # Checks the PV name (e.g. /dev/hda2)
    6) pvresize –verbose /dev/hda2
    7) vgdisplay -v # Checks the Free PE (e.g. 384)
    8) lvextend -l+384 /dev/VolGroup00/LogVol00
    9) resize2fs /dev/VolGroup00/LogVol00
    10) Наздраве!
    ——————————————————————————————————————————————–

    Tested with VM:
    CentOS release 5.4 (Final)
    kernel-2.6.18-164.11.1.el5
    lvm2-2.02.46-8.el5_4.2

    Don’t do that on production systems but better create a new partition with fdisk and a new PV, extend the existing VG and LV after that (see http://www.linuxquestions.org/questions/fedora-35/lvm-partition-resizing-666683/#post3281556).

    Be sure that you have a backup!!!

    Best Regards,

    Boyan Boychev
    Bulgaria

  55. 55 Jul

    Hi All,
    I’ve tested on 2008 R2, and I’ve also encountered with the “BOOTMGR is missing error”. Just wanted to share how i resolve the issue and the image is working perfectly fine for me. The following steps from http://www.binarywar.com/ resolves my issue:-

    1. Put in the 2008 R2 installation cd
    2. In the System Recovery Options dialog box, click Command Prompt
    3. Type Bootrec /RebuildBcd, and then press ENTER.
    4. If the Bootrec.exe tool runs successfully, it presents you with an installation path of a Windows directory. To add the entry to the BCD store, type Yes. A
    5. Next, I booted the server from a Windows 7 ISO and ran the Startup Repair option.
    6. After running the startup repair, on the first boot, do let the check disk run. After which, you are able to logon to your Windows 2008 R2 server as per normal with your storage size enlarge.

    Hope this helps for those with 2008 R2. :)

  1. 1 When Windows Won’t Load | Job Searching Blog
  2. 2 Resizing a VirtualBox HDD « 0×0000
  3. 3 VirtualBox Snapshots « Nathan Fast
  4. 4 Ender Özcan (enderozcan) 's status on Thursday, 16-Jul-09 20:59:47 UTC - Identi.ca
  5. 5 Resizing a VirtualBox VDI image / hard disk « HyperPac´s site
  6. 6 Increase virtual hard disk size under VirtualBox 3.1 « Thoughts on Life

Leave a Reply





Get Adobe Flash playerPlugin by wpburn.com wordpress themes

Nick Heppleston’s BizTalk Blog is Digg proof thanks to caching by WP Super Cache