Saturday, 4 June 2011

Booting a VM from USB

Recently I started up my Linux VM for the first time in some months. It has Ubuntu installed on it. It had version 9.10 on it, known as Karmic Koala. I found out pretty quickly that this version is rather dated, and that support for it ended in April 2011. I decided to upgrade but was unsure whether to go for 10.04 LTS (Lucid Lynx), 10.10 (Maverick Meerkat) or 11.04 (Natty Narwhal) but didn’t want to fully install each one just to see what it was like.

Popping along to the Ubuntu download page I found that they offered the 10.04 Long Term Support (LTS) version or the current 11.04 version for download as a CD .ISO image and was reminded of the fact that the CD has the option of running as a ‘Live CD’, meaning you don;t have to install it – you can boot off the CD and run it directly from there. That’s great – I can pull the .ISO files down, connect my VM’s CD drive to the .ISO imge (as VMWare Workstation allows you to do, and I’m sure the other VM software, Virtual PC and Virtual Box do also).

Then I noticed the suggestion that you can burn the ISO to a bootable USB device and boot off that. This sounded interesting. When I decide on a suitable Ubuntu version, I can burn it to a spare USB memory stick and free the PC of the .ISO file, potentially allowing me to boot pretty much any PC into Ubuntu if the need or desire arises.

Well, I figured I’d better test this by booting my VM off the USB device. The first problem was how to make a bootable USB device from the .ISO, but this one is easily solved. The Ubuntu download page has a link to the Universal USB Installer from PendriveLinux.com. This makes the whole process trivial and even allows any spare space on the USB stick to be used as persistent storage for the installed Linux OS.

Universal USB Installer

Having got a bootable USB device with Ubuntu on it I need to prove that one of my virtual machines can successfully boot from it. And this is where things got sticky. It seems the VMWare BIOS does not support booting from USB devices, which seemed to rain on my parade, somewhat. Until I did a little searching and came across a free boot manager called, simply, Plop. You can read up all about Plop on their Boot Manager info page.

In short though, if you download the current Plop Boot Manager .zip archive and unzip it you’ll find 2 key files in it: plpbt.img (currently 1,474,560 bytes) and plpbt.iso (currently 327,680 bytes). The .img file is a bootable floppy disk image, hence being 1,440 kB (floppies used to be described as having a capacity of 720 kB or double that, which was referred to as 1.44 MB). The tiny .iso is a bootable CD image. If you connect one of these to the virtual floppy drive (if present, though there should be an option to add it if not) or the virtual CD drive in a VM (and ensure the BIOS is set to boot off the legacy floppy device or the CD-ROM drive before the hard drive) then Plop will be invoked.

Plop’s job is to present you with all the available bootable devices to boot from, including USB, and in that it works just great and allows the VM to boot successfully from a USB device.

Plop Boot Manager

Of course what you don’t see in the screenshot above is that all those dots are actually a very smooth star field you’re heading through.

Ok, so there we go – I now have a bootable USB device and I can boot any reasonably modern computer from it and can also boot a VM from it. One final thing I thought would be useful was to set up a dedicated dummy VM that could be used to boot from CD or USB devices, if desired, to avoid occupying one o the regular ‘real’ VMs. I wanted this dummy VM to take up as little space as possible and so, preferably, not have to chew up physical disk space by allocating a virtual hard drive, which after all won’t be used.

I went through the steps of creating a new VMWare VM, decided to tell VMWare that it would be a Linux guest OS that would be installed, but that it would be installed later and found there was no way of specifying no hard disk in the VM. I opted to use an existing virtual disk from another VM, but wasn’t too happy about making this dummy VM dependant on another one that my get moved to another physical drive at some point. So when the VM setup was complete I took a look in the new VM’s .vmx file, which contains all its main settings.

Near the top I saw these values:

scsi0:0.present = "TRUE"
scsi0:0.fileName = <path_to_some_VMs_vmdk_virtual_disk_file>

The last piece of the puzzle was to simply set the scsi0:0.present value to "FALSE". Now I have a trivial VM with no hard disk whose sole purpose is to boot an OS from either a CD, via a connected .ISO file, or from a USB device, which can be done by connecting the Plop floppy image or CD image to the VM.