Saturday, October 15, 2011

RESIZING AN EXISTING HDD IMAGE IN VIRTUALBOX

[ If you deem this article as helpful, please consider downloading my game "Just Survive XP" on the Appstore (free for a limited time):

=> http://itunes.apple.com/app/just-survive-xp/id461876025 ]

Yesterday I was installing a new virtual machine on my desktop with VirtualBox and, don’t ask me why ‘cause I don´t know, but I made a rookie mistake …

… when I created the vdi file for the virtual hardrive I forgot to assign a custom size so it ended up with the default 20GB. Sigh!

Soon I noticed my mistake when I realized I would need more space on the drive to install the whole set of tools I wanted to use, so I opened VirtualBox in order to resize the drive and guess what … I found no way on settings to directly do it. Bummer …

Maybe it is there somewhere but I didn´t find it so fearing the worst –that is, reinstalling everything on a new image from scratch, I did a search on the Internet for a solution. Why not reading VirtualBox’s help file, right?

Well, to my surprise I found any kind of cumbersome solutions like cloning the .vdi file and using a parition manager to blá, blá, blá. Tired of this dead-ends, I finally did what I should have done on the first place: read the help file!

Yes; the solution was always there: VirtualBox includes a command-line tool named “VBoxManage” with a set of interesting options available and one of them is “modifyhd”. Its syntaxis is the following:

VBoxManage modifyhd <uuid><filename>
[--type normal | writethrough | immutable | shareable
readonlymultiattach]
[--autoreset onoff]
[—compact]
[--resize <megabytes>--resizebyte <bytes>]

Having opened a command-line terminal in the host OS of your machine, a simple way to use this command would be, say:

VBoxManage modifyhd “<fullpath>/<filename>”
--resize 30720

It is important to notice that you should use not a relative but the fullpath to the .vdi file for optimal results. So, if your .vdi file is located on “C:/mypath/myvdifile.vdi”, use this string on the command (in case of other OS than Windows, use the path from root).

If everything goes well you should see a new text line showing the progress:

0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%

But sometimes, like in my case, things turn out not to be that simple. You may find your-self facing an error message like:

ERROR: Cannot register the hard disk 'C:/mypath/myvdifile.vdi' with UUID {someUUIDtext} because a hard disk 'C:/mypath/myvdifile.vdi' with UUID {someUUIDtext} already exists in the media registry ('…/VirtualBox.xml')
Details: code NS_ERROR_INVALID_ARG (0x80070057), component VirtualBox, interface IVirtualBox, callee nsISupports
Context: "OpenHardDisk(Bstr(szFilenameAbs), AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), srcDisk.asOutParam())" at line XX of file VBoxManageDisk …

If that happens don´t panic; a solution that worked for me was using the UUID assigned to the virtual hdd, instead of the path to the file, so if the UUID is “{13f2…-…-…342a}” then the command should look like:

VBoxManage modifyhd 13f2…-…-…342a
--resize 30720

Now, when the new size of the .vdi file gets allocated, all you need to do is open your virtual machine, log into the OS, and assign the new free space to the hdd. If your hosting Windows, then execute the provided managing tool (rightclick on your PC icon and select “Manage”), find the vitual disk and extend its size.

Well, that’s it. Hope you find this tips useful.

Cheers!
~Pete

> Link to Spanish version.

1 comment:

  1. Hey thanks dude! Nice and simple I wish finding other stuff online was so easy...

    ReplyDelete

Any thoughts? Post them here ...