The Best Virtualization Program You've Never Heard Of (Part 2)
Part Two : Sun's VirtualBox is a quiet performer. Learn how to get it up and running.
In part 1 we compared VirtualBox to VMWare and Xen, learned some crazy-sounding new terms like paravirtualization and hypervisor , created a virtual machine, and installed Linux on it. VirtualBox doesn't have all the enterprise bells and whistles of VMWare; I think of it as an excellent replacement for multi-boot systems, a safe test bed, and a reliable tool for server consolidation for smaller shops.
I had forgotten what a pain using CDs or DVDs can be on VirtualBox. It doesn't detect the correct device name, and when you fix it manually it complains about not being able to find it. Installing new guest operating systems from an installation CD/DVD has some pitfalls, so here are a few tips that might help:
- Enable ACPI and IO APIC in your VM settings
- Boot the CD/DVD with the ide=nodma option
The easiest way to install any Linux is directly from the .iso image on your hard disk. Then you don't have to bother with burning a disk, and it goes a lot faster. Set this up in the Settings -> CD/DVD-ROM menu for your virtual machine. After installation, go back and disable this or it will re-run the installer next time you start it up. You can even perform network installations this way if you have a bootable network installer, like Debian's netinst.iso.
Networking is a combination of easy and more complicated. You don't have to configure anything to accept the default configuration, which lets your guest OS function as a network client. VirtualBox does some fancy NAT (network address translation) tricks to enable Internet and LAN connectivity. You'll have Web and email, and can SSH into other LAN hosts. You'll have access to CUPS printers and Samba shares if their their own access controls allow access from VirtualBox's network range. VirtualBox assigns addresses from the 10.0.0.0/16 range, and creates four virtual interfaces that use the 10.0.2.0, 10.0.3.0, 10.0.4.0, and 10.0.5.0 private networks. The user manual details how to set up NAT port forwarding, and its limitations in a virtualized environment.
NAT imposes a number of limitations. If you want to run servers, then you'll need to perform some fancy port-forwarding tricks. Anything that depends on ICMP messages, such as the ping command, won't work. UDP broadcasts are unreliable, and only TCP and UDP are supported, so other protocols won't work. The default NAT-based networking is suitable for workstations; if you're going to run servers there is a better option, and that is Host Interface Networking (HIF). HIF creates virtual Ethernet interfaces that allow routing and bridging, so you don't have to hassle with the limitations of NAT. Setting up HIF is documented in the VirtualBox user manual.
Snapshots For Cheap Insurance
VirtualBox has a snapshot feature that lets you save the state of your guest OS, and then revert to it if something goes wrong after making changes. You can take a snapshot from the VirtualBox main window, or from inside a running virtual machine. If you use the main VirtualBox control panel, you must first stop the virtual machine. If you take a snapshot from inside a running VM it will automatically pause it for you, and then resume when it's finished. You should give your snapshots helpful descriptions so you'll know what they are. The snapshots record only the differences between the new image and the old one; use the Virtual Disk Manager to see how much space your snapshots are using.
Reverting to an earlier snapshot means losing all changes made after it was taken, including any files you created. One way to preserve your files is by using a separate write-through hard disk to store your data files, and then keep your system files on a normal virtual disk. Write-through virtual disks are not saved in snapshots. You'll have to create them from the command line, since the graphical Virtual Disk Manager doesn't include the write-through option:
$ vboxmanage createvdi -static -size 10000 -register -type
writethrough -filename /mnt/sdb1/virtualbox/rthru
VirtualBox Command Line Management Interface Version 1.5.0_OSE
(C) 2005-2007 innotek GmbH
All rights reserved.
Disk image created. UUID: b21b4ffe-2719-4966-05bf-19ae8377baeb
That creates a static 10 GB virtual hard disk. register means make the image available. Un-registering an image marks it as not available. It's still there, but with the unwelcome mat out.
There are two different ways to revert to an earlier snapshot. First stop your VM, and then go to the Snapshots tab. If the Current State is different from your last snapshot, you can revert to that snapshot and discard all changes made since it was taken. Or you can skip back to an earlier snapshot, which requires "Discard current snapshot and state". An easy way to practice and to see for yourself how this works is to use the touch command to create some empty files, like touch file1, touch file2 and so forth, and then take a new snapshot each time you create some new files. Then when you try the different methods of reverting you'll quickly see how it works.
If you're used to VMWare, VirtualBox may feel like it's missing some features. With VMWare you can move your VMs with snapshots, but not in VirtualBox, nor can you merge them the way VMWare does. However, they are still useful and easy, and efficient of disk space.
Guest Additions are nice extras that automate mouse and keyboard switching between your different environments, seamless windows, better video performance, and shared folders between your guest operating systems. However, installing Guest Additions can be a real pain, and sometimes impossible, because of kernel incompatibilities. The Guest Additions rely on a special kernel module that must be built from sources on each Linux guest. Here's how it works: go to Devices -> Install Guest Additions from any running guest Linux. This downloads and mounts an ISO image containing the Guest Additions and a Linux installation script, VBoxLinuxAdditions.run. All you do is figure out where the ISO image is mounted and then run the script, like this:
But this may not work, because you need a build environment and kernel headers for this work. On Debian and the Buntu family, get them this way:
# aptitude install build-essential dkms linux-headers
And that should do it. On Fedora:
# yum groupinstall 'Development Tools'
# yum install kernel-devel
This should work on most last-generation Linux guests, such as Ubuntu Gutsy and Fedora 8. The problem is when you have the last release, version 1.5. It won't work with Ubuntu Hardy Heron or Fedora 9 guests, to give two examples. The build will fail and the install log reports this error:
make KBUILD_VERBOSE=1 -C /lib/modules/2.6.24-16-generic/build SUBDIRS=/tmp/selfgz5495/module/test SRCROOT=/tmp/selfgz5495/module/test modules
test -e include/linux/autoconf.h -a -e include/config/auto.conf || (
echo " ERROR: Kernel configuration is invalid.";
echo " include/linux/autoconf.h or include/config/auto.conf are missing.";
echo " Run 'make oldconfig && make prepare' on kernel src to fix it.";
Which is misleading, because running make oldconfig && make prepare won't fix anything, and the supposedly missing files are present. Getting the latest 1.6.x release of VirtualBox should cure most problems. There have been several significant releases of VirtualBox since the beginning of the year, and most Linux distributions have not caught up, so your options are grab the latest source tarball, or use the binary package which is free of cost but not open source. Admins who prefer to install from their distribution repositories are stuck with waiting until they catch up.