Faster Windows 7 under Ubuntu by using raw SSD access

This post is about how I made Windows 7 run fast as a guest under Ubuntu by running it from a rawVirtualBox 4.1.6.
partition of a Solid State Drive under


This week I was given an ADATA S599 2.5" SATA II Solid State Drive in 115GB capacity from Mantech for my office workstation -- a 2008 Dell Precision T5400 specced as quad-Xeon with 4GB RAM, and installed Ubuntu 11.10 amd64 desktop on it. It now boots in 17 seconds, and the previously 30-second-long first-time login now takes less than 5 seconds. I use Python/Linux but most of the other devs use .NET/Windows so I require a Windows 7 virtual machine.  In fact, the slowness of my Windows 7 VM on a rotating drive was the main motivator for buying the SSD.

I wanted Windows to take advantage of the TRIM command, to avoid the SSD slowing down once all its blocks have been written to.  I created an extra partition for windows during Ubuntu installation rather than have the VM run from a file, because I don't think TRIM issued by the guest OS would be passed down to the SSD if the virtual disk is a file on the host filesystem.

To get ownership of the partition for VirtualBox, I created the following udev rule in /etc/udev/rules.d/customdisk.rules which permanently gives graham write permission to the Windows partition which is /dev/sdb1 on my machine.  I ran udevadm info -a -n sdb1 to get the start and size attributes to prevent the rule matching any other sdb1.  The rule sets UDISKS_PRESENTATION_HIDE to prevent Nautilus from displaying the partition, so I can't corrupt it by accidentally mounting and writing to it while the VM is running.

KERNEL=="sdb1", SUBSYSTEM=="block", ATTR{start}=="2048", ATTR{size}=="136716288", SYMLINK+="win7", OWNER="graham", GROUP="disk", ENV{UDISKS_PRESENTATION_HIDE}="1"

I ran the udevadm test to make the rule to take effect:

sudo udevadm test "$(udevadm info --query=path --name=sdb1)"

Following Virtual Box Manual Chapter 9 on Using a raw host hard disk from a guest I first listed partitions to get the correct partition number:

sudo VBoxManage internalcommands listpartitions -rawdisk /dev/sdb

And created a raw VMDK for partition 1 of sdb:

sudo VBoxManage internalcommands createrawvmdk -filename /home/graham/.Virtualbox/RawDisks/sdb1.vmdk -rawdisk /dev/sdb -partitions 1 -relative

From virtualbox I created a Windows 7 machine, selecting sdb1.vmdk as the disk. On first run of the VM I added the Official Windows 7 SP1 ISO from Digital River to the virtual CD/DVD drive, installed Windows, and installed VirtualBox guest editions with 3D enabled. VirtualBox setting changes included:

  • System: Base Memory=1024MB, Enable IO APIC=Ticked, Processors=2
  • Storage: SATA Controller: sdb1.vmdk: Solid-state drive=Ticked
  • Display: Enable 3D and 2D Acceleration. Video Memory=256MB

The 3D isn't perfect: I disabled animations in guest's system settings, the Windows Experience benchmark crashes, and IE9 scrolling is jumpy (turned out to be an IE9 bug).

But in general the VM is snappy and no longer slows down the Ubuntu host much.

Popular posts from this blog

Cutting down on clutter with the Outbox Method

A comparison of file synchronisation software