Thursday, June 7, 2007

Virtual machine on your flash drive

Today we'll discuss deployment of virtual machine on generic flash drive. Of course, there’s nothing difficult to copy virtual machine files to flash drive and then open .vmx file and start virtual machine, but I’ll try to “do it right way” and automate process of launching machine as much as possible.

Everybody knows about Windows “autorun” feature. That’s exactly what we need! To enable autorun behavior we should place file named autorun.inf to the root directory of flash drive. Let’s find out exact content of this file for our purposes. Starting from simple things: let’s change default drive icon to virtual machine one. All we need is a config.ico file from VMware installation and one line in .inf file. Copy config.ico to the root folder of flash drive and rename it to config.icon (otherwise Windows will suspect graphical media content on flash drive and may be will prompt to view it). Hence the first line of our file is:

[autorun]
icon=config.icon

Second step is a new drive label. I’ll install Ubuntu on my flash drive, so the new file line is:

[autorun]
icon=config.icon
label=Ubuntu


The main thing: how to launch virtual machine? Open command does not work, but shellexecute is a thing we need. Simply type shellexecute=ubuntu.vmx – this will launch installed virtualization software.

Looks pretty good, but there are small problems here:

1) Workstation does’not run virtual machine, it just opens vmx file (-X command line parameters solves this)

2) Player 2.0 does not understand gui.fullScreenAtPowerOn = "TRUE" vmx entry anymore, so we can’t just launch virtual machine in full screen.

I wrote a small application called vmlauncher that detects installed virtualization software and launches it appropriately. It also configures shared folder from the host’s My Documents folder. If no virtualization software detected, vmlauncher offers to install VMware Player (distributive should be placed on the same flash drive in “VMware\VMware Player” folder).

The final autorun.inf content:

[autorun]
icon=config.icon
label=Ubuntu
shellexecute=vmlauncher.exe .\ubuntu\ubuntu.vmx
UseAutoPLAY=1

Plus vmlauncher.exe in the flash drive’s root directory.