Monday, July 19, 2010

How to resize VirtualBox disk images?

-- Update on May 8, 2012 --

Having to resize an image again, I looked at the VirtualBox documentation before following the CloneVDI route a second time. And I was pleasantly surprised that the version 4.1 of VBoxManage accepts a parameter --resize to the command modifyhd!

The process can be done in a matter of minutes:
  1. Stop the hosted system (Win7 in my case).
  2. Run the following command in the folder of your VDI file
       VBoxManage modifyhd <name>.vdi --resize <size-in-mb>
  3. Start the virtual machine.
  4. Open the disk manager tool (Use the Menu Windows, type disk man in the search box, and select 'Create and format hard disk partitions').
  5. You should see your drive with the initial partition(s) and new free space.
  6. Click on the partition to extend and choose the command 'Extend Volume' in the contextual menu.
  7. And voilĂ .
No need to copy the VDI on the host machine. Very fast and robust process.
'Extend Volume' option in the contextual menu.


-- Original post on July 19, 2010 --

Quick post to share a wonderful VirtualBox companion: CloneVDI!

Almost two months ago, I switched from Windows XP to GNU/Linux with Ubuntu 10.04 distribution. Everything goes very well and I do not regret the move.

In my day-to-day job, as the architect/developer/tester of the Twetailer project, engine and of many of its clients, I still need to run programs on the Windows OS, especially the series of Internet Explorer 7 & 8 (IE 6 is killed, isn't it?).

To verify my test suites for Internet Explorer, I rely on VirtualBox running the initial Windows XP release. Because the disk size requirement for the initial version is low, I stupidly created a small  4 GB disk image! Then it required hours to load and install the service packs 2 & 3, plus IE 8, plus the latest .Net framework, plus the security updates. Be careful: 4 GB is way too small to store the system, the virtual memory page file, and the additional stock coming with the service packs and others!

Few days after the initial setup, I was facing the "Not enough space available" warning :-( Instead of wasting another set of hours in a re-installation, I googled virtualbox increase vdi size, and the first article I found was from the VirtualBox forums. I thought it was a good sign and I started reading... but I became quickly disappointed because the given explanations required many tricks and time to setup too. Then I jumped to the last pages (page 6 to be precise) to read:
...

The new way:
Run the CloneVDI tool. Enter name of source VDI and desired disk size into dialog box. Click "Proceed" button. Expect to spend maybe 5 minutes for a typical VDI, longer of course with big drives.

The CloneVDI tool has existed since mid September 2009. It was created specifically so as to remove the need to recommend an embarassingly complicated rigmarole for performing what should have been a simple task. So, in late May 2010 it is quite disheartening to see people still joining the site in order to provide uninformed endorsement of the obsolete procedure.
The post was from Don Milne, alias mpack, the creator of the CloneVDI tool.

Then I loaded CloneVDI from the referenced post, installed Wine with the Ubuntu Software Center, ran CloneVDI, selected my initial image, specified a new name and a new size (now 10 GB), and all the magic transformation occurred in less than 1 minute!

CloneVDI pane: clone an virtual image with an increased size in just a few clicks!

Warning: It seems the cloning only works up to the first snapshot, as my clone did not get the snapshots. This was not a issue for me but be careful on your side because it might be necessary to merge the snapshots. As the cloning is very fast, producing a new image per snapshot should work-around the issue.

Anyway, I wholeheartedly recommend CloneVDI when it's time to allocate more disk space to a VirtualBox machine!

A+, Dom

3 comments:

  1. Thanks for the kind words about my CloneVDI tool. Just a quick note that the tool clones whatever you tell it to clone. So if you clone the base, you get a clone of the base only. If you select the latest snapshot the clone will have a merge of all the data from the snapshot chain.

    ps. I see you have discovered "modifyhd --resize". I humbly suggest that CloneVDI is simpler and much safer for resizing disks, because it doesn't touch your original and hence doesn't risk corrupting your current VM.

    Regards, Don Milne.

    ReplyDelete
  2. You're welcome Don.

    You're right: CloneVDI is safer for most users. As I consider myself an advanced user on Ubuntu and dislike using Wine, I just prefer the command line version. I wanted to update my post accordingly ;)

    A+, Dom

    ReplyDelete