Changing VirtualBox’s Disk Image Sizes

I was running out of room in my Virtual Box Windows 7 disk.  Windows was reporting used space of 18.6 GB and free space of 1.22 GB.  My Mac was reporting that my disk image was using up 21.39 GB.


On your Windows Guest:

  1. Run Disk Cleanup.
  2. Run Disk Defragmenter.
  3. Download SDelete and use it to zero out free space. I put sdelete in C:\Windows\System32 and then ran it like this from the command prompt.
    C:\> sdelete -c c:/

  4. Shutdown Windows.

On your Mac Host:

  1. Run VBoxManage from the Terminal to compact the disk image.
    $ VBoxManage modifyhd Windows.vdi --compact

Sad Story

I first tried shrinking the disk image to see if that would free up room using the instructions above which were based on the article How To Shrink Your Virtualbox VM And Free Up Space For Your Hard Disk.

After doing this Windows reported used space of 18.8 GB and free space of 1.03 GB.  In other words no difference. Sad smile  But on the Mac the disk image was now only using up 20.51 GB.


On your Windows Guest:

  1. Shutdown Windows.

On your Mac Host:

  1. Run VBoxManage from the Terminal to resize the disk image. This is how I did it.
    $ VBoxManage modifyhd Windows.vdi --resize N

On your Windows Guest:

  1. Restart Windows.
  2. Use diskpart to resize the C: drive to use the new space.

Happy Story

Realizing that compacting did not work I shut down again and this time increased the size of the disk image by 10 GB from 20 GB to 30 GB (N = 30720).

VirtualBox showed in its settings that the disk image size was now 30 GB.  But Windows still reported used space of 18.8 GB and free space of 1.03 GB.  Again no difference. Sad smile  And on the Mac the disk image was still the same but that was to be expected.

Back to Google which led me to Windows’ brilliant tool diskpart.


Microsoft DiskPart version 6.1.7600
Copyright (C) 1999-2008 Microsoft Corporation.
On computer: WIN-7-IMAC-POOP

DISKPART> list volume

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     D   VBOXADDITIO  CDFS   CD-ROM        38 MB  Healthy
  Volume 1         System Rese  NTFS   Partition    100 MB  Healthy    System
  Volume 2     C                NTFS   Partition     19 GB  Healthy    Boot

DISKPART> select volume 2

Volume 2 is the selected volume.

DISKPART> extend size=10240

DiskPart successfully extended the volume.

Windows now reported free space of 11.0 GB.Open-mouthed smile

End Note

I originally tried resizing the disk by specifying the size of how much I wanted the disk increased, i.e. 10 GB or N=10240.

$ VBoxManage modifyhd Library/VirtualBox/HardDisks/Windows\ 7.vdi --resize 10240

This failed with the strange error:

Progress state: VBOX_E_NOT_SUPPORTED
VBoxManage: error: Resize hard disk operation for this format is not implemented yet!

Fortunately I found out in one of the VirtualBox forums that this happened because I gave the wrong argument to resize.  Too bad the error message wasn’t a little more helpful. Smile

VirtualBox Unable to Run Two Instances

Double Bows by Nicholas_T

I have been using VirtualBox for awhile and have been pretty pleased with it considering it’s a free solution.  I blogged about wanting to try it over two years ago.

Today I started up Windows 7 on my iMac.  Then I tried to start up Windows XP but got this error.

Failed to open a session for the virtual machine Windows XP Pro Media Center.

PIIX3 cannot attach drive to the Secondary Master

Unknown error creating VM (VERR_SHARING_VIOLATION).

Fortunately Google came to the rescue and led me to this article in the VirtualBox forums, Can’t run multiple Instances on OSX Leapord.  Once I unmounted the DVD drive in Windows 7 (Devices –> CD/DVD Devices) I was able to start Windows XP.

The lesson is you can’t run two instances if both want to mount the same DVD drive. Not sure if this is a problem with Parallels or VMWare.

Cygwin 1.7.x, mounts and /etc/fstab

Sunrise Heron Silhouette on FlickrSunrise Heron Silhouette by Brandon Godfrey

A few days I installed Cygwin on a new laptop.  I saw the warnings that Cygwin 1.7.x is new but I chose to ignore it for now.

I soon noticed that Cygwin was not remembering my mounts.  After reading this on the Cygwin front page I realized I needed to do some more research.

… the mount point storage has been moved out of the registry into files. User mount points are NOT copied into the new user-specific /etc/fstab.d/$USER file. Rather, every user has to call the /bin/copy-user-registry-fstab shell script once after the update.

Next I looked at the /etc/fstab file which pointed me to the Cygwin Mount Table documentation.  Using this documentation I did the following steps so that my mounts are always remembered.

  1. Manually mounted the C: drive.
    $ mount c: /c
  2. Ran mount to determine what to add to my /etc/fstab.
    $ mount
    C:/cygwin/bin on /usr/bin type ntfs (binary,auto)
    C:/cygwin/lib on /usr/lib type ntfs (binary,auto)
    C:/cygwin on / type ntfs (binary,auto)
    C: on /c type ntfs (binary,user)
  3. Based on the output of mount I added this line to my /etc/fstab.
    C: /c ntfs binary,user
  4. Closed the Cygwin shell, opened a new one and verified the C: drive was properly mounted.

Update 06-15-2010: I should have just followed Cygwin’s directions and ran /bin/copy-user-registry-fstab.

Microsoft Windows Vista Error 0x80070091 and Cygwin

In Windows Vista I installed JBoss.  When I then logged in as another user for some reason all the JBoss directories had no permissions, i.e. their permissions were 000.  I ignored this and went ahead and copied one of the server directories.  Then I tried to go into the copied server directory and could not.

Thinking something was funky I tried to delete the whole JBoss directory but got this maddening and uninformative window.

Microsoft Windows Vista Error 0x80070091

I googled for a long time but could not find a satisfying solution.  I gave myself full control permissions for all files and folders but that did not help.  Then I noticed that if I clicked on one of the directories that Windows Vista was not letting me delete I would be prompted for permission to enter this directory.  Then I would repeat this process for all directories within.  After doing this I could delete that directory.

I then looked in Cygwin and found out what Vista had done, it had simply given the directory read and write permission.

Therefore the simple solution was to do the following:

chmod -R 500 .

After doing that simple change I could remove everything.

Moving Your Cygwin Installation

I was running out of space on one drive so I decided to move my Cygwin installation to another drive.

It turned out not to be too difficult thanks to this article Hints for Setting up Cygwin.  This is how I did it though there might be a simpler way.

  1. In a bash shell save the mount points as a batch script.
    $ mount -m > /c/cygwin-mount.bat
  2. Close the bash shell.
  3. Move the cygwin folder from one drive to the other.  In my case that was from C:\cygwin to D:\cygwin.
  4. Update all the short cuts for Cygwin in the Start Menu to use the new drive.
  5. Update  cygwin.bat, which is in the top level of your Cygwin installation, to use the new drive.
  6. Update your Windows environment variable to use the new Cygwin bin path, e.g. D:\cygwin\bin.
  7. Open a DOS cmd prompt.  Run umount to unmount the old Cygwin mounts.
    > umount
  8. Next run the mount points script.
    > C:\cygwin-mount.bat
  9. Open a Cygwin bash shell to make sure everything is working correctly.

Mac Hibernate

I tried to make the Mac hibernate based on this article, Make my Macbook Pro Hibernate. Unfortunately it did not work and I am wondering if it is because this article is older and maybe it does not work for Mac OS X Leopard.

In the end I have gotten used to not having hibernate on the Mac since start up and shutdown are so fast.

NTFS Junctions

Windows NTFS has a nice but relatively unknown feature called NTFS junctions.  It is like hard links in Unix except it is only for directories.  Microsoft has a KB article about it which points to several utilities.  However I have been using Mark Russinovich’s junction tool exclusively.

Using Junction

Usage: [-s]

-s Recurse subdirectories

If you want to create or delete a junction, use Junction like this:

Usage: [-d] []

To delete a junction specify the -d switch and the junction name.

Here is an example of using junction.  Note that the order of arguments is opposite of the Unix ln command.

> junction foo d:\docs\foo

The above example will create a junction called “foo” in the current directory.  This junction will point to d:\docs\foo.

To do the same in Cygwin:

$ junction foo `cygpath -aw /d/docs/foo`

One tip is to use the DOS dir command.  It will display instead of

in directory listings for junctions.

Microsoft Office 2008 update 12.1.0 will not install

I tried many times to install the Microsoft Office 2008 update 12.1.0 but each time it would hang.

Finally I found this forum thread about the exact same problem, Msi Wind Forums • View topic – Microsoft Office 2008 update 12.1.0 will not install.

This is how to get the update to install.

Should have an option to edit……thing is it’s to late because your forced quit. Run the installer again and when the installer hangs move the installer window to one side…the error window noted above should be directly behind the installer and thats why you missed it in the first place…the installer has halted (and appears hung) as the error window is awaiting a response from you…..but you dont see it. All you have to do is click the edit button on the error window and then installer will continue…thats it. You can close the error window and the installer will continue.

Cygwin Bash Scripts and Java

Running Java scripts in Cygwin bash scripts becomes a little tricky because you want to treat most paths in Cygwin as normal UNIX paths but Java expects DOS paths.  Therefore to get around this you can use the mixed option for cygpath.

For example:

if [ -e /usr/bin/cygpath ] || [ -e /bin/cygpath ]
  export FOO=`cygpath --mixed "e:\work\betweengo/target/foo"`
  export FOO="e:\work\betweengo/target/foo"

The result on Cygwin is that FOO will be set to “e:/work/betweengo/target/foo” which will work both in DOS and UNIX.