Tag Archives: Virtual Box

Shrinking VirtualBox VDI Files

Hi, if like me you use VirtualBox for your Microsoft CRM environments you no doubt have at least one crazy large VirtualBox VDI file taking up space on your hard drive.

Today, I thought I would try and trim mine back. I started with a 90GB VDI file and got it down to 65GB.

Here’s what I did:

1. Ran Disk Defragmenter within the VM and defrag’ed the disk. 

2. Ran TreeSize Free within the VM to check for large files/folders that I could trim (didn’t find anything, but did notice the winsxs folder was huge, so did some research on that…)

3. Ran the DISM command line below to purge the winsxs folder (removes data that resides on your disk to enable rollback of service packs, makes your service packs permanent – do a bit of research on this before you decide to do this)

Here’s what I ran:

clip_image002

This reduced the size of C drive inside my VM by 5GB. I think the results you get will depend upon the initial level of your OS and the number of updates you have installed over top.  There seems to be different clean up utilities like this for different OS’s and Service Packs.   I’m no expert on this though.  I ran this over a Windows 2008 R2 SP1 Enterprise Edition install. 

4. Downloaded sdelete to the C drive of my VM and then ran from a command prompt the following command (from c:\ ) sdelete -c -z C:\

This will write 0’s over any unused space on your VM hard disk.  This makes it crystal clear that that unused space can be purged.

5. Shutdown my VM.

6. Opened a command prompt on my host machine and changed directory over to the VirtualBox program folder (C:\Program Files\Oracle\VirtualBox).  Ran the following command to ask VirtualBox to compact my VM’s VDI file:

VBoxManage modifyhd –compact "D:\VirtualBox\CRM 2011 on SQL 2008 DEV Image\Hard Disk\CRM2011 DEV Image (64-BIT Win2008R2  SQL2008R2).vdi"

That’s it.   Oh, and the VM still launched afterwards Smile

Advertisements

How to Duplicate a Virtual Box Image

If like me you use Virtual Box for demo and development environments you will likely want to duplicate existing Virtual Box images at some point.   Virtual Box doesn’t like this.   Reason for this is each Virtual hard disk is assigned a unique ID and if you simply try a copy and paste your new VDI file will have the same unique ID as the original VDI file and you will get this error:

“Cannot register the hard disk XXXX with UUID YYYY because a hard disk XXXX with UUID YYYY already exists in the media registry blah blah …"

The fix is simple enough though.  Open a command prompt and navigate to the Virtual Box installation folder:

image

Then enter the following, substituting the folder name and file names to localise to the location of your new VDI file:

VBoxManage.exe internalcommands sethduuid "C:\foldername\filename.vdi"

And run that.

Here’s how my mine looks:

image

If you get it right you will get something along the lines of:

image

And you’re ready to rock.

Launch Virtual Box, create a new machine, when asked to select a hard disk browse out to your VDI file and select it and then you should be all good.

I’ve had to figure this out twice now and mucking around in a command prompt quickly drives me nuts so next time I’m coming back to this blog. 

Regards,

Gareth