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:
host% mkdir ~/uml
host% cd ~/uml
host% tar -xjvf linux-2.4.0-prerelease.tar.bz2
host% cd ~/uml/linux
host% bzcat uml-patch-2.4.0-prerelease.bz2 | patch -p1
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.
to see the true size of the UML kernel.
host% strip linux
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 -d:pserver:email@example.com:/cvsroot/user-mode-linux 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
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.
host% cvs co -r v_2_3_x linux
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:
and changing /etc/fstab and /etc/inittab to refer to the non-devfs devices.
UML# for i in 0 1 2 3 4 5 6 7; do mknod ubd$i b 98 $[ $i * 16 ]; done
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):
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.
host% make modules ARCH=um
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:
host% mount root_fs mnt -o loop
host% make modules_install INSTALL_MOD_PATH=`pwd`/mnt ARCH=um
host% umount mnt
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:
UML# mount none -t hostfs path to UML pool -o path to UML pool
UML# cd path to UML pool ; make modules_install
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
If the module build process has something that looks like
cd uml-tree ; make script 'SCRIPT=@echo $(CFLAGS)' ARCH=um
then you can define CFLAGS in a script like this
$(CC) $(CFLAGS) file
and like this in a Makefile
CFLAGS=`cd uml-tree ; make script 'SCRIPT=@echo $(CFLAGS)' ARCH=um`
CFLAGS=$(shell cd uml-tree ; make script 'SCRIPT=@echo $$(CFLAGS)' ARCH=um)
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:
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
host# make && make install