Linux Step By Steps

User Mode Linux
Written by Net Llama! on 19-Sept-02.


User Mode Linux (UML) allows you to run one or more Linux virtual machines that may have more hardware and software virtual resources than your actual, physical computer (think a GPL'd version of VMWare).  It provides the functionality of running a fully functional Linux distribution (even with X if you like) within your existing distro.  However, setting it all up is not for the faint of heart.  It requires time, patience, and a decent amount of computing resources.

What I did was setup several UML instances, each with its own static IP, thus making it appear to the outside world as its own Linux server.  However, this isn't a requirement, and in fact you can setup UML without any networking at all, or other variants of networking (such as VPN, DHCP, serial etc).  

In order to install a single instance of UML, you will need to have sufficient computing resources on your computer for the UML plus one.  The plus one, is for your current 'host' Linux install.  By resources, I mean, memory, CPU power, & disk space. While you can control the amount of memory & disk space that the UML utilizes, you cannot directly control the amount of CPU time it needs, as that is dependent on what you run within the UML.

In order to install & run a UML instance, you will need at least 3 things:
  1. The UMLsoftware with kernel
  2. The UML utilities tools
  3. A Linux distro filesystem image
The first 2 can be downloaded here.  As of the time of this writing, the latest software package is user_mode_linux-2.4.18.36um-0.i386.rpm and the latest utilities tools is uml_utilities_20010902.tar.bz2.



There are several different ways of obtaining or building a filesystem image.  You can download an assortment of prebuilt images from several different distros here under Root filesystems.  Alternately, you can build you own.  There are several different options for accomplishing this, however the one that I used, and recommend is called UML Builder.  You can download UML Builder here.

In order to use UML Builder, you will need to place all of the RPMs for the distro that you wish to install in the UML instance onto your harddrive.  See the UML Builder website for specific instructions on which RPMs to copy over.  

UML Builder provides both a command line interface and a GUI for creating a UML image.  If you run umlbuilder_gui you will be taken step-by-step through the process of creatinga UML filesystem image that is preconfigured.  Once you finish building the UML image, you need to make some host side changes.



First, in order to properly route traffic to and from the UML's staticly assigned IP address, you will need to setup an ethernet bridge.  Additionally, you will need to have a 2.4.x kernel that supports ethernet bridging.  All Redhat and Mandrake kernels have this support.  I have not been able to verify whether other distro kernels do or do not, however you can verify whether you have bridging support by one of the following methods:
If neither checks out, then you will need to build a 2.4.x kernel that supports bridging.  While configuring the kernel make sure you have selected "802.1d Ethernet Bridging" under "Networking options" in the kernel configuration main menu, either compiled-in ("Y") or as a module ("M").

Additionally, you will need to obtain the bridge-utils package here.  I simply grabbed bridge-utils-0.9.5.tar.gz however the RPMs should work equally as well.  

User Mode Linux uses something known as tun/tap networking to allow a UML instance to exchange packets with the host.  This is done by setting up a tap interface on the host:
  1. First verify that you have the tun device, /dev/net/tun.  If not, you can create it with "mknod /dev/net/tun c 10 200".
  2. Next fix the permissions on /dev/net/tun so that your users can write to it, with "chmod 666 /dev/net/tun".
  3. And finally, load the tun module with "modprobe tun".
The following steps will take care of all host side networking configuration issues, and therefore need to be run as the root user.  Note, that its best *not* to run your UML as root.  Hence, the name User Mode, in that any user can run it.  Also note that eth0 will be replaced with br0 (the zeroth bridge interface) after you run these commands.  
  1. /usr/sbin/brctl addbr br0
  2. /usr/sbin/brctl stp br0 off
  3. /bin/su - <user_running_UML> -c "/usr/bin/tunctl -u <user_running_UML>"
  4. /sbin/ifconfig tap0 0.0.0.0 promisc up
  5. /sbin/ifconfig eth0 0.0.0.0 promisc up
  6. /usr/sbin/brctl addif br0 eth0
  7. /usr/sbin/brctl addif br0 tap0
  8. /sbin/ifconfig br0 <original_IP_address_of_eth0_on_host> netmask <original_netmask_of_eth0_on_host> up
  9. /sbin/route add default gw <gateway_IP_address_on_host>


Now you should be ready to fire up the UML instance.  If you look in the directory where your UML was created by umlbuilder, you will see a file called control.  This file is a shell script that defines all of the UML variables, and then uses them to start UML.  If you're in a hurry, you can get it started with this command:
./control start

This will boot UML, and should spawn a terminal window that provides a login prompt.  Login as root with the password that you selected when you ran umlbuilder to create the UML image.  If you're really lucky, networking will work perfectly, and you should be able to ping out, and also get back in (assuming that you have something like sshd or apache installed and running within the UML).

Unfortunately, I was never that lucky, and had to tweak a few network settings.  For starters, the default broadcast address and netmask were incorrect.  The only real place to permanently fix this is in /etc/sysconfig/network-scripts/ifcfg-eth0.  This file is different in UML than in a normal distro.  Take a look and you'll see what I mean.  Basically, its just a hack that runs ifconfig or any other command (such as route).  So, what I needed to do was add an appropriate ifconfig statement for eth0, and also a route command to set the correct default gateway (which should be the same as the gateway IP that your host used for its eth0 (now br0).  Thus, the contents of the file for me were (some of the IPs are intentionally obscured for security reasons):

#!/bin/sh
    # this script brute forces the networking.  This is necessary because
    # various modules not being in uml can confuse some scripts (eg Mandrake)
    # and I can't figure out how to get all the distributions to play nice.
    # It won't do any harm if this script is run multiple times
    PATH=/sbin:/usr/sbin:/etc/:$PATH
    export PATH
    ifconfig lo 127.0.0.1 up
    ifconfig eth0 198.186.XXX.XXX broadcast 198.186.XXX.XXX netmask 255.255.255.128 up
    route add default gw 198.186.203.1
#    /etc/umlutil/routeme
    exit 0





That should take care of it all.  Please note that I've left out a huge number of details.  User-Mode-Linux is an incredibly complicated piece of software, and no SxS could ever do it justice.  Feel free to ask me questions about the specific things I've discussed above, however, please see the UML website for much more comprehensive documentation.