"The talent of success is nothing more than doing what you can do, well." - Henry W. Longfellow   |    "Our doubts are traitors, and make us lose the good we oft might win, by fearing to attempt." - William Shakespeare   |    "Nothing will ever be attempted if all possible objections must first be overcome." - Samuel Johnson   |    "We are still masters of our fate. We are still captains of our souls." - Winston Churchill   |    "Nothing great was ever achieved without enthusiasm." - Ralph Waldo Emerson   |    "We are what we repeatedly do. Excellence, therefore, is not an act but a habit." - Aristotle   |    "Every artist was first an amateur." - Ralph Waldo Emerson   |    "Success is the sum of small efforts, repeated day in and day out." - Robert Collier   |    "The more difficulties one has to encounter, within and without, the more significant and the higher in inspiration his life will be" - Horace Bushnell   |    "The big secret in life is that there is no big secret. Whatever your goal, you can get there if you're willing to work." - Oprah Winfrey   |    "Good luck' follows careful preparation; 'bad luck' comes from sloppiness." - Robert Heinlein   |    "The more you learn, the more you need to learn." - Robert Heinlein   |    "Nothing can stop the man with the right mental attitude from achieving his goal; nothing on earth can help the man with the wrong mental attitude." - Thomas Jefferson   |    "Take calculated risks. That is quite different from being rash." - George S. Patton   |    "Perl - The only language that looks the same before and after RSA encryption." - Keith Bostic   |    "There is no such thing as luck; there is only adequate or inadequate preparation to cope with a statistical universe." - Robert Heinlein   |    Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.   |    "If Java had true garbage collection, most programs would delete themselves upon execution." - Robert Sewell   |   

Code Reactor

The best of modern Web development

Changing size of VirtualBox disks before and after deleting snapshots

If you search for guides for changing the size of VirtualBox .vdi disks, there are plenty, and really the solution is pretty simple, just

vboxmanage.exe modifyhd "<path-to-vdi>" --resize <newsize-in-MB>

But what some of the guides fail to mention (some of them don’t fail to mention it, but since you are reading this post you probably failed to see it in the guides that did mention it) is that you really should delete all the snapshots for the disks you are trying to change the size of, BEFORE changing the size. Otherwise you’ll pretty quickly notice that the guest OS doesn’t recognize the drive size change, and now you can’t delete the last snapshot, getting instead the error with something about “virtualbox could not merge the medium VERR_INVALID_PARAMETER”.

So this post is really for you that are now stuck with a virtual machine that has a disk that cannot be size-changed and a snapshot that cannot be deleted.

Basically the solution is to clone the whole virtual machine using the standard virtualbox functions, because the cloned version will be free of any snapshots and still represent the current state of the original VM.

When you are going to clone it you will be presented with some options which are self-explanatory. But one of those options will have you choose to keep or discard all the snapshots, and you obviously have to choose discard at that point.

One small drawback of this operation is that VirtualBox does not seem to let me choose where to put the disk of the cloned machine and creates it in the default location, which can be problematic if you keep your disks somewhere else.

Now you will still have to resize the new disk. This is where another small problem arises: if you just use the command line fromt he beginning of the post on the newly created disk, you may receive the error “VBoxManage.exe: error: Cannot register the hard disk … becase a hard disk …. with UUID … already exists”. Long story short, the solution is to first run

vboxmanage.exe internalcommands sethduuid "path-to-the-new-disk"

It will assign a new uuid to the disk which will solve the problem, and you can now resize the disk with your normal command (the modifyhd one, from the beginning of the post).

Now just boot into the guest and use Gparted (if you have *nix) or Computer Management -> Storage -> Disk Management in Windows 7 (probably Vista had this already) to make the guest OS understand the new disk change.

Of course, now would be also a good time to make sure the guest OS works properly and delete the original VM in VirtualBox gui to save space.

Leave a Reply

You must be logged in to post a comment.

loading...
Your connection appears to be too slow, automatically disabling HeavyAjax (TM) for better performance...
You seem to run a browser without JavaScript support or it has been disabled. To fully experience Code Reactor please enable JavaScript. (It is not 1995 anymore :)
You seem to be using Internet Explorer. If you want to experience both Code Reactor and the rest of the web to their fullest and fastest, you are advised to download and install a real browser, like Opera, Firefox or Google Chrome.
Close
You seem not only to use Internet Explorer, which is by far a joke when it comes to browsers, but to even use an old version of it!
If you want to experience both Code Reactor and the rest of the web to their fullest and fastest, you are STRONGLY advised to download and install a real browser, like Opera, Firefox or Google Chrome.
Close