User Mode Linux in Debian Etch
Saturday, 4. November 2006, 20:14:25
Prepartion
1. Install user-mode-linux and related packages in debian
2. Get some filesystem images from Nagafix.co.uk UML Resources
Launch Two UML Instances
linux mem=128M ubda=cow1,/home/work/uml/Ubuntu-x86-root_fs umid=ubuntu1 linux mem=128M ubda=cow2,/home/work/uml/Ubuntu-x86-root_fs umid=ubuntu2
Log in as root, no password.
Networking the UML Instances with Multicast
host# uml_mconsole ubuntu1 config eth0=mcast host# uml_mconsole ubuntu2 config eth0=mcast ubuntu1# ifconfig eth0 192.168.0.1 up ubuntu2# ifconfig eth0 192.168.0.2 up
We can verify that we have connectivity by pinging one from the other.
TUN/TAP with Routing
Note: Tap devices are point-to-point connections. There can only be one UML using one at a time.
host# su root
Run the following bash script in host
chmod 666 /dev/net/tun
tunctl -u bob -t uml
ifconfig uml 192.168.1.1 up
iptables --flush
iptables --table nat --flush
iptables --delete-chain
iptables --table nat --delete-chain
iptables --table nat --append POSTROUTING --out-interface eth0 \
-j MASQUERADE
iptables --append FORWARD --in-interface uml -j ACCEPT
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/conf/uml/proxy_arp
arp -Ds 192.168.1.2 eth0 pub
route add -host 192.168.1.2 dev uml
host# exit
host# uml_mconsole ubuntu1 config eth0=tuntap,uml
ubuntu1# ifconfig eth0 192.168.1.2 up
ubuntu1# route add default gw 192.168.1.1
Configure /etc/resolv.conf in ubuntu1.
Compile From Source
Download Kernel Source
host# wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.18.tar.bz2 host# bunzip2 linux-2.6.18.tar.bz2 host# tar xf linux-2.6.18.tar host# cd linux-2.6.18
Apply this patch from Jeff Dike
Index: linux-2.6.17/arch/um/os-Linux/process.c
===================================================================
--- linux-2.6.17.orig/arch/um/os-Linux/process.c 2006-09-20 11:15:08.000000000 -0400
+++ linux-2.6.17/arch/um/os-Linux/process.c 2006-09-20 13:35:24.000000000 -0400
@@ -140,11 +140,9 @@ void os_usr1_process(int pid)
* syscalls, and also breaks with clone(), which does not unshare the TLS.
*/
-inline _syscall0(pid_t, getpid)
-
int os_getpid(void)
{
- return(getpid());
+ return syscall(__NR_getpid);
}
int os_getpgrp(void)
Index: linux-2.6.17/arch/um/os-Linux/sys-i386/tls.c
===================================================================
--- linux-2.6.17.orig/arch/um/os-Linux/sys-i386/tls.c 2006-06-18 13:49:35.000000000 -0400
+++ linux-2.6.17/arch/um/os-Linux/sys-i386/tls.c 2006-09-20 13:37:27.000000000 -0400
@@ -3,8 +3,6 @@
#include "sysdep/tls.h"
#include "user_util.h"
-static _syscall1(int, get_thread_area, user_desc_t *, u_info);
-
/* Checks whether host supports TLS, and sets *tls_min according to the value
* valid on the host.
* i386 host have it == 6; x86_64 host have it == 12, for i386 emulation. */
@@ -17,7 +15,7 @@ void check_host_supports_tls(int *suppor
user_desc_t info;
info.entry_number = val[i];
- if (get_thread_area(&info) == 0) {
+ if(syscall(__NR_get_thread_area, &info) == 0){
*tls_min = val[i];
*supports_tls = 1;
return;
Index: linux-2.6.17/arch/um/os-Linux/tls.c
===================================================================
--- linux-2.6.17.orig/arch/um/os-Linux/tls.c 2006-08-15 21:59:56.000000000 -0400
+++ linux-2.6.17/arch/um/os-Linux/tls.c 2006-09-20 13:37:14.000000000 -0400
@@ -48,14 +48,11 @@ int os_get_thread_area(user_desc_t *info
#ifdef UML_CONFIG_MODE_TT
#include "linux/unistd.h"
-static _syscall1(int, get_thread_area, user_desc_t *, u_info);
-static _syscall1(int, set_thread_area, user_desc_t *, u_info);
-
int do_set_thread_area_tt(user_desc_t *info)
{
int ret;
- ret = set_thread_area(info);
+ ret = syscall(__NR_set_thread_area, info);
if (ret < 0) {
ret = -errno;
}
@@ -66,7 +63,7 @@ int do_get_thread_area_tt(user_desc_t *i
{
int ret;
- ret = get_thread_area(info);
+ ret = syscall(__NR_get_thread_area, info);
if (ret < 0) {
ret = -errno;
}
Apply this patch from Emmanuel Fleury
--- arch/um/include/sysdep-i386/stub.h.orig 2006-11-04 02:33:58.000000000 +0100 +++ arch/um/include/sysdep-i386/stub.h 2006-11-14 11:23:20.000000000 +0100 @@ -12,6 +12,7 @@ #include "stub-data.h" #include "kern_constants.h" #include "uml-config.h" +#include "asm/page.h"
Compile kernel and modules
host# make mrproper
host# make mrproper ARCH=um
host# make defconfig ARCH=um
host# make xconfig ARCH=um
CONFIGURE 2G/2G Host Address Space Split
CONFIGURE Host Filesystem
host# make ARCH=um
Run UML instance with the compiled "linux"
Configure networking
host# make modules_install INSTALL_MOD_PATH=/home/work/uml/mods/ ARCH=um
ubutu# mkdir -p /lib/modules/`uname -r`
ubutu# passwd
ubutu# apt-get install ssh
host# scp -r /home/work/uml/mods/lib/modules/2.6.18/kernel/
root@192.168.1.2:/lib/modules/2.6.18
ubuntu# depmod -a
ubuntu# modprobe xx
ubuntu# rmmod xx
Links
The User-mode Linux Kernel Homepage
UMLWiki
Nagafix.co.uk UML Resources
Kernel Hacking with UML
User Mode Linux HOWTO
Programming with User Mode Linux
Annotated HOWTO for creating an SELinux enabled UML system
Books


How to use Quote function: