Wednesday, September 2, 2009

The Virtues of Virtualization

Back in the bad old days, say 5+ years ago, when an enthusiast user wanted to run more than one operating system he/she would run a multi-boot setup. That is, the computer would boot into a boot manager that allowed the user to choose which operating system to run.

Although this worked it was kind of a pain to maintain. Recovery was dangerous as one operating system tended to overwrite the boot setup of any other operating system. It also, usually, required separate disk partitions. Deciding how much space to allocate for each operating system was a black art that always seemed to leave lots of space unusable because it had been allocated to one of the other operating systems.

Over time setup and maintenance became easier as operating systems increased their support for multiboot scenarios. Linux users are laughing at that statement since linux has always existed in a heterogenous environment and has pretty much always had support for multiboot (via various boot loaders like grub or lilo). Windows may have been a little later to the party but boot.ini has been around since NT.

Even with improved OS support for playing nice with multiple boot scenarios there's something fundamentally unsatisfying about multiboot. One of the most common reasons to run more than one operating system on a single computer is to be able to test software on a different OS. A similar task is to be able to test a web app in multiple browsers on different OSes. Yet under multiboot each "test" requires a machine reboot. This is an incredibly inefficient way to test. Because it's so inefficient it inhibits the frequent "make small change-test change-repeat" cycle that is key to reducing bugs.

Enter virtualization. Instead of having a single computer run a single operating system at a time, virtualization allows a single computer to run multiple operating systems simultaneously. The first operating system that boots is called the host operating system. Subsequently run operating systems are called guest OSes.

Virtualization allows a single computer to run multiple operating systems simultaneously through the magic of software. The key piece of software is the virtual machine. It is exactly what it sounds like. It is a piece of software whose sole purpose is to fool an operating system into believing it is running on real hardware.

A non-virtual machine, e.g., a computer you might buy from Dell, has a CPU, chipset, memory, a hard disk and peripherals. All of these are physical devices. A virtual machine has the virtual equivalents of these; a virtual chipset, virtual video card, virtual hard disk, etc...

There are several vendors that make virtualization software. Each provides their own flavor of virtual hardware. That is, VMWare provides a different virtual video card than Microsoft's Virtual PC, which is different from the one provided by Sun's VirtualBox.

Virtualization is similar but not identical to emulation. Emulation has been around for years. You can take a quad core, 64bit machine and run software to emulate a Commodore 64. I'm not quite sure why people do this but am told it's all the rage in PC nostalgia. The difference between emulation and virtualization is that virtualization depends on a tighter integration between the virtual machine and the actual machine. An emulator runs in a process like any other; the emulation software runs in user mode, its threads are scheduled like any other user thread.

When a virtual machine is running an operating system, it is executing in the same privileged mode (with a few exceptions) as the host operating system. Programs running in the guest operating system can be pre-empted by the guest operating system. This improves performance and contributes to an illusion that also distinguishes a virtual machine from emulator software: the guest operating system need not be aware that it is running in a virtual machine.

Like physical machines an operating system must be in installed on a virtual machine to profitably take advantage of the system. Unlike physical machines the virtual machine doesn't need a physical hard disk; it uses a virtual hard disk created by the virtualization software. The flip side of this is that virtual machines can only use virtualized hardware. Most virtualization software provides support for virtualizing network adapters, USB, printers, serial ports and a few other commonly used peripherals. If the virtualization software doesn't provide a way to virtualize a given piece of hardware then that hardware probably can't be used in a virtual machine.

No comments :

Post a Comment