User Mode Linux: Coming to a Kernel Near You, Part 1

By: Dee-Ann LeBlanc
Wednesday, March 12, 2003 11:51:10 AM EST
URL: http://www.linuxplanet.com/linuxplanet/tutorials/4712/1/

What Exactly is User Mode Linux?

There are a number of fundamental additions coming in the next Linux kernel. One of these will be a great boon to software developers, beta testers, product reviewers, hosting services, and more: User Mode Linux (UML). Just as VMware allows us to run a machine within a machine, UML lets us do run multiple, separate, isolated instances of Linux on a single Linux box.

Seems a bit too good to be true, doesn't it? Let's take a closer look at UML, how it works, and the pros and cons involved in determining if this upcoming kernel feature is for you.

The name for this feature isn't the most self-explanatory. User Mode Linux is thusly named because it runs in user space. With a UML, you can run a miniature Linux system with its own kernel and filesystem without needing root access to the entire machine. Your UML is your own little world, and you can configure its kernel, networking, and all other aspects of the virtual machine to your satisfaction.

You're not limited to the same distribution of Linux, either. While VMware lets you run any operating system it's designed to handle within its virtual machine, UML allows you to run any particular distribution's kernel and filesystem setup. The key is that you run the UML kernel as you would run any other command, and the UML kernel then communicates directly with the host machine's kernel--though at times the UML kernel must modify instructions before sending them to the main kernel. Limitations come in when a package must communicate directly with hardware instead of an intermediary, but there are workarounds available that solve most of these issues.

Your UML filesystem is actually contained in a single file (per UML you've set up), swap space and all, making it a sort of filesystem within a filesystem. Between the isolated filesystem and kernel, a UML can act as an island where users can enter, but cannot break out through the shark-infested waters to reach the main system. A break-in only effects the UML system. The overall kernel and filesystem remain untouched.

Practical Uses and Issues

There are quite a number of uses for a feature such as UML. People like myself who install a lot of beta software or even just evaluate a lot of software can end up with a real mess on our hands, for example. I tend to use a second machine but it's much slower than my primary, and my setup requires me to bounce back and forth between computers using a switchbox so I can't see everything at once. UML would allow me to lock the beta software and whatnot into a virtual system on my main computer, ensuring that beta bugs only messed up the UML session and not my entire work machine.

Then there's the issue of services we don't quite trust, or don't dare trust. Worried that someone might break out of the FTP server space? Run your FTP server from within a UML, and even if the person does they can't reach the main machine. Worried about all of those BIND security warnings? Farm the nameserver onto a UML too.

Of course, there is a performance hit for using UML. You've got a virtual kernel for each UML instance, plus your main kernel, the programs running in your UMLs, and the programs running on your main machine. RAM is your friend when you're using UML. But, then, RAM is just as important with a tool like VMware.

The performance drag is most apparent when you're running many UML instances. Rather than running a co-location service, there are already people in the UML community running multi-UML services where each client or participant gets their own virtual machine on the same box, with their own root login and so on, to administer as they see fit. As people run more and more services in their UMLs, the whole machine's load increases, and so you can end up with one person hogging many of the CPU cycles if you're not careful.

To avoid this, you can specify how much RAM each UML is allowed to ask for. You set this value individually so you're not required to give every UML the same amount of RAM, so those services that you consider high priority can receive a larger allocation than the low priority ones. Fortunately, while you'll want to do the math to ensure that you've got enough RAM to suit everyone's needs, if all of your UMLs together ask for more RAM than is actually available, the main machine's kernel swaps out those requests just like any other RAM over usage. You can also assign swap space to the UMLs for their own use.

Trying Out UML Right Now

UML might not be production quality yet, but it's in heavy use by a number of beta testers, and of course the more, the merrier. In these days before it's integrated into the main, production kernel, you need to follow two installation steps in order to add it to your machine. I'm going to expressly cover methods that utilize either the RPM or Debian package management system. If you desperately feel the need to build it from source, I recommend that you do a lot of reading before you start. I've included a resource list at the end of Part 2 of this article.

The two steps involved in installing UML are first to install the UML's kernel (not to be confused with your main machine's kernel, we're not replacing it), and then to add the UML's filesystem. To install the kernel, if you're running a Debian system or want to try it on a Debian-related distribution, then type the following:

apt-get install user-mode-linux

That's it (for the kernel portion of the installation). Really.

If you're using an RPM-based distribution, then start by going to the UML project site on SourceForge (http://user-mode-linux.sourceforge.net/). Click the Downloading It link, scroll down to the Recommended Installation section, and click the specified RPM in the table to download the (approximately 1.8 MB) file. Once you've got the file downloaded, change to the directory you placed it in, and type as root or while su'ed into the superuser account:

rpm -ivh user_mode_linux

Press the Tab key to expand the filename and press Enter. This action will install the kernel for you.

Once you have the kernel installed, you'll need to add a UML filesystem. Which filesystem you choose depends on what distribution you want to run on your virtual machine. There are a number of choices available in the download section of http://user-mode-linux.sourceforge.net/. The abbreviations are md for Mandrake (www.mandrake.com), rh for Red Hat (www.redhat.com), toms for Tom's Linux (www.toms.net/rb/), co for Conectiva (www.conectiva.com), and debian for, well, Debian (www.debian.org).

These filesystem snapshots are all offered in .bz2 format, so you type bunzip2 filename to unpack them.

By default, UML expects you to be working within X, and therefore opens a pair of login windows as you start the system_giving you an error if you aren't in X. I'm going to focus on running this in X since the purpose here is to introduce you to UML, not to send you fussing with the thing trying to get it to run exactly the way you want it.

If you're not interested in trying to figure out how to get this to work the way you want, then by far the easiest method is to run your UML within the GUI. All you have to do from here is type the following to try out your virtual Linux system from the X Window System with:

linux ubd0=/path/to/unpacked/filesystem

Once your UML has started, then it will open a pair of virtual consoles, one of which is shown in Figure 1.

There are two login accounts enabled by default. One of them is the root user, with the clever password root (you'll obviously want to change that as soon as possible if anyone else has access to the system), and the other is the account user with the password user (another one you might want to change). The first time you log in the system might require you to change the password, so be prepared.

Mind you, this is the equivalent of installing a new, isolated, generic box. If you're out to develop software that doesn't require networking or beta test (again without needing networking) then this might be exactly what you're looking for. If not, read on.

Note: If you insist on not using the GUI, then you have a bit of work ahead of you. See http://user-mode-linux.sourceforge.net/input.html for coverage of this feature. One example of running a UML on one of your host's virtual consoles, involves typing something like the following in the first virtual console:
linux ubd0=/home/dee/Downloads/root_fs.rh-7.2-server.pristine.20020312
con=tty:/dev/tty1

In Part II of this article, we will examine how to connect your UML to the outside world and polishing up your UML configuration.

Dee-Ann LeBlanc is an award-winning technical author with 11 books and over seventy articles in print. Along with writing, Dee-Ann teaches, develops courses, and also consults when time allows. Learn more at http://www.Dee-AnnLeBlanc.com/.

Copyright Jupitermedia Corp. All Rights Reserved.