Next Previous Contents

2. Compiling the kernel and modules

2.1 Compiling the kernel

Compiling the user mode kernel is just like compiling any other kernel. Let's go through the steps, using 2.4.0-prerelease (current as of this writing) as an example:

  1. Download the latest UML patch from the download page In this example, the file is uml-patch-2.4.0-prerelease.bz2.
  2. Download the matching kernel from your favourite kernel mirror, such as: .
  3. Make a directory and unpack the kernel into it.
    mkdir ~/uml
    cd ~/uml
    tar -xjvf linux-2.4.0-prerelease.tar.bz2
  4. Apply the patch using
    cd ~/uml/linux
    bzcat uml-patch-2.4.0-prerelease.bz2 | patch -p1
  5. Run your favorite config; `make xconfig ARCH=um' is the most convenient. `make config ARCH=um' and 'make menuconfig ARCH=um' will work as well. The defaults will give you a useful kernel. If you want to change something, go ahead, it probably won't hurt anything.

    Note: If the host is configured with a 2G/2G address space split rather than the usual 3G/1G split, then the packaged UML binaries will not run. They will immediately segfault. See UML on 2G/2G hosts for the scoop on running UML on your system.

  6. Finish with `make linux ARCH=um': the result is a file called `linux' in the top directory of your source tree. You may notice that the final binary is pretty large (many 10's of megabytes for a debuggable UML). This is almost entirely symbol information. The actual binary is comparable in size to a native kernel. You can run that huge binary, and only the actual code and data will be loaded into memory, so the symbols only consume disk space unless you are running UML under gdb. You can strip UML:
    host% strip linux
    to see the true size of the UML kernel.

Make sure that you don't build this kernel in /usr/src/linux. On some distributions, /usr/include/asm is a link into this pool. The user-mode build changes the other end of that link, and things that include <asm/anything.h> stop compiling.

The sources are also available from cvs. You can browse the CVS pool or access it anonymously via

cvs command

If you get the CVS sources, you will have to check them out into an empty directory. You will then have to copy each file into the corresponding directory in the appropriate kernel pool.

If you don't have the latest kernel pool, you can get the corresponding user-mode sources with

host% cvs co -r v_2_3_x linux
where 'x' is the version in your pool. Note that you will not get the bug fixes and enhancements that have gone into subsequent releases.

If you build your own kernel, and want to boot it from one of the filesystems distributed from this site, then, in nearly all cases, devfs must be compiled into the kernel and mounted at boot time. The exception is the tomsrtbt filesystem. For this, devfs must either not be in the kernel at all, or "devfs=nomount" must be on the kernel command line. Any disagreement between the kernel and the filesystem being booted about whether devfs is being used will result in the boot getting no further than single-user mode.

If you don't want to use devfs, you can remove the need for it from a filesystem by copying /dev from someplace, making a bunch of /dev/ubd devices:

for i in 0 1 2 3 4 5 6 7; do mknod ubd$i b 98 $[ $i * 16 ]; done
and changing /etc/fstab and /etc/inittab to refer to the non-devfs devices.

2.2 Compiling and installing kernel modules

UML modules are built in the same way as the native kernel (with the exception of the 'ARCH=um' that you always need for UML):

host% make modules ARCH=um
Any modules that you want to load into this kernel need to be built in the user-mode pool. Modules from the native kernel won't work. If you notice that the modules you get are much larger than they are on the host, see the note above about the size of the final UML binary.

You can install them by using ftp or something to copy them into the virtual machine and dropping them into /lib/modules/`uname -r`.

You can also get the kernel build process to install them as follows:

  1. with the kernel not booted, mount the root filesystem in the top level of the kernel pool:
    host% mount root_fs mnt -o loop
  2. run
    make modules_install INSTALL_MOD_PATH=`pwd`/mnt ARCH=um
  3. unmount the filesystem
    host% umount mnt
  4. boot the kernel on it

If you can't mount the root filesystem on the host for some reason (like it's a COW file), then an alternate approach is to mount the UML kernel tree from the host into the UML with hostfs and run the modules_install inside UML:

  1. With UML booted, mount the host kernel tree inside UML at the same location as on the host:
    UML# mount none -t hostfs path to UML pool -o
    path to UML pool
  2. Run make modules_install:
    UML# cd path to UML pool ; make modules_install
The depmod at the end may complain about unresolved symbols because there is an incorrect or missing installed in the UML filesystem. This appears to be harmless. insmod or modprobe should work fine at this point.

When the system is booted, you can use insmod as usual to get the modules into the kernel. A number of things have been loaded into UML as modules, especially filesystems and network protocols and filters, so most symbols which need to be exported probably already are. However, if you do find symbols that need exporting, let us know, and they'll be "taken care of".

If you try building an external module against a UML tree, you will find that it doesn't compile because of missing includes. There are less obvious problems with the CFLAGS that the module Makefile or script provides which would make it not run even if it did build. To get around this, you need to provide the same CFLAGS that the UML kernel build uses.

A reasonably slick way of getting the UML CFLAGS is

cd uml-tree ; make script 'SCRIPT=@echo $(CFLAGS)' ARCH=um
If the module build process has something that looks like
 $(CC) $(CFLAGS) file
then you can define CFLAGS in a script like this
CFLAGS=`cd uml-tree ; make script 'SCRIPT=@echo $(CFLAGS)' ARCH=um`
and like this in a Makefile
CFLAGS=$(shell cd uml-tree ; make script 'SCRIPT=@echo
$$(CFLAGS)' ARCH=um)

2.3 Compiling and installing uml_utilities

Many features of the UML kernel require a user-space helper program, so a uml_utilities package is distributed separately from the kernel patch which provides these helpers. Included within this is:

The uml_utilities tree is compiled with:
make && make install
Note that UML kernel patches may require a specific version of the uml_utilities distribution. If you don't keep up with the mailing lists, ensure that you have the latest release of uml_utilities if you are experiencing problems with your UML kernel, particularly when dealing with consoles or command-line switches to the helper programs

Next Previous Contents