Sunday, November 11, 2012

VirtualBox

I really like VirtualBox so far, but there are a few caveats. First of all, I find that I have to use PIIX chipset emulation because ICH emulation (which is marked experimental) dies frequently and nastily running Vista. This problem so far appears completely resolved running an emulated ICH board.

The other thing is that installing the VirtualBox extensions on Vista is a pain because Vista locks d3d9.dll, so the VirtualBox installer can't replace it with a paravirtualized version. The solution is inconvenient. First off, you have to mount the VDI file containing the Vista install so that you can rename d3d9.dll so that Vista will stop locking it immediately upon boot. However, contrary to the instructions I've found scattered online, I've been completely unable to mount VDI files directly. Instead, I use:

ionice -c 3 VBoxManage clonehd --format RAW in.vdi out.img

and this converts the Virtual Disk Image file to a raw disk image which, as far as I know, is just the concatenation of all of the data on the disk as it would appear on a physical disk. "ionice -c 3" is optional but, on my system, it prevents the IO operation from hogging all of the system's IO-time, so that I can continue doing amazingly important things in the foreground, such as this blog entry.

Great. So, now we have a disk image, but we can't mount an entire partitioned disk. So we have to do:

parted out.img
u b
p


and that gives something like:

Model:  (file)
Disk /home2/wine/out.img: 69632786432B
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start     End           Size          Type     File system  Flags
 1      1048576B  69631737855B  69630689280B  primary  ntfs         boot
where the value in the "Start" column is the byte-offset into the image at which the first and only partition begins. The intervening data is probably stuff like the partition table and MBR.

FINALLY. We can do:

mount -o loop,offset=1048576B out.img /mnt/vbox
mv /mnt/vbox/windows/System32/d3d9.dll /mnt/vbox/windows/System32/d3d9.dll.bak
umount /mnt/vbox


At this point, we discover that VirtualBox cannot directly load raw disk images, so we do:

ionice -c 3 VBoxManage convertfromraw out.img nod3d.vdi --format vdi

And now, finally, we have a vdi file which is exactly like the one we started with, except for the name of a single file, and now we can boot to Vista and install VirtualBox Guest Extensions, complete with the experimental D3D driver, which I hope will work instead of bluescreening every few minutes.

Incidentally, I've somewhat accidentally hit upon a neat strategy for speeding up my virtualized Vista install. I've found that by placing my base disk image on my SSD, it effectively separates my base Vista install from all subsequent snapshots, whose location defaults to my home directory, which is an old platter drive. The base install is 21(!!!) GB excluding the pagefile, and this is mostly libraries and executables that never change, so the SSD is a great place for this data. But because I always run this disk image from a differential snapshot located on a platter drive, the base image is effectively read-only, so I don't have to worry about Windows thrashing my SSD to death with constant write operations. And best of all, I don't have to worry about shoving a non-standard configuration into Windows, which is apt to break irreparably the moment you do anything out of the ordinary with it. It's all handled by Linux and the VB hypervisor. As far as Windows is concerned, it's just writing to a single regular hard drive when, in fact, all of the system files are read at high speed from an SSD, while all of the pagefile, document, and application I/O is quietly routed to a hardy old mechanical drive. And best of all, I can run Windows without listening to the tortured disk head grinding I've come to associate with it

1 comment:

  1. Ok. So, it's actually far, far easier to simply load a live-CD image into the virtual machine, boot it, and use it as a conventional rescue disk to modify Vista's NTFS filesystem. But at least now I know how to manipulate VB disk images.

    ReplyDelete