Running ReSoA in a Slackware UML

Table Of Contents

1 About This Document
2 Host System Setup
2.1 Important Note
2.2 Host Kernel
2.3 tmpfs
2.4 UML Networking Support
3 File Systems
4 User-Mode Linux Kernel
5 Slackware
5.1 Package Installation
5.2 Configuration
5.3 Booting
5.4 First Boot Configuration
6 Example Slackware Package List
7 Running ReSoA
8 References

1 About This Document

This file is part of the CD distribution of my Studienarbeit about the

Design and Implementation of the Remote Socket Architecture (ReSoA) for Linux 2.4 .

It contains basic information about how to create and use the User-mode Linux image based on Slackware provided on the CD.

2003/05/14 Tobias Poschwatta <posch@ft.ee.tu-berlin.de>

2 Host System Setup

2.1 Important Note

You should make sure, that both host system and UML use the same gcc compiler version. You will encounter serious problems, i.e. crashes, if you mix gcc versions 2 and 3.

Slackware 9.0, used in this README, is based on gcc 3.2.2. If you want to compile your UML kernel with gcc 2, you can use packages from Slackware 8.1.

2.2 Host Kernel

If you want your UMLs to run fast, you should consider recompiling your host kernel using the SKAS patch available at the User-mode Linux site.More information about SKAS can be found here: http://user-mode-linux.sourceforge.net/skas.html

2.3 tmpfs

UMLs will create a temporary memory file with the size of the UML's memory ( mem option) in the directory denoted by $TMPDIR . It is recommended to use a tmpfs file system for $TMPDIR as it reduces system load significantly and thus improves overall performance.

To set up a tmpfs directory, create a directory and mount it as type tmpfs . The start script shown later in this document will set the TMPDIR environment variable before booting the kernel. Note, that it is not a good idea to use /tmp with tmpfs as this might break some applications.

You must be root to mount the tmpfs directory. Adjust the size option as needed (Should be as large as the sum of memory assigned to UMLs).

# mkdir umltmpfs
# mount -t tmpfs -o mode=1777,size=512M none umltmpfs/

It is also possible to add the tmpfs directory to the host's fstab to mount it during host system boot.

none       /.../umltmpfs  tmpfs  mode=1777,size=512M     0  0

2.4 UML Networking Support

There are several different approaches to allow UMLs to access the network. A description of the possibilites can be found at http://user-mode-linux.sourceforge.net/networking.html .

The UML start script provided later in this file uses TUN/TAP devices and bridging to attach the UMLs to the real network.

The following script creates the br0 bridge and five tap devices (tap0..tap4). Each UML is assigned a separate tap device (see start script later in this file). The bridge is created so that it replaces an existing eth0 device.

Creating the tap devices requires the UML utilities package to be installed ( tunctl program). Also, as Slackware does not include the bridge utilities, you probably have to install them, too.

The tap devices are assigned to UID 1000. Make sure /dev/net/tun is readable and writeable by this user, e.g. do chmod 666 /dev/net/tun .

#!/bin/sh

USER=1000

IP=$(/sbin/ifconfig eth0 | awk '/inet addr:/ {print substr($2, 6)}')
BCAST=$(/sbin/ifconfig eth0 | awk '/inet addr:/ {print substr($3, 7)}')
NETMASK=$(/sbin/ifconfig eth0 | awk '/inet addr:/ {print substr($4, 6)}')
DEFGW=$(/sbin/route -n | awk '/^0\.0\.0\.0/ {print $2}')

echo "IP=$IP, BCAST=$BCAST, NETMASK=$NETMASK, DEFGW=$DEFGW"

start_tap()
{
    TAP="tap$1"
    /sbin/ifconfig $TAP 1>/dev/null 2>/dev/null
    if [ $? -ne 0 ]; then
        echo "Creating device $TAP..."
        TAP=$(tunctl -b -t $TAP -u $USER)
	/sbin/ifconfig $TAP 0.0.0.0 promisc up
    fi
}


/sbin/modprobe tun
/sbin/modprobe bridge

echo "Setting up bridge br0..."
brctl addbr br0
/sbin/ifconfig eth0 0.0.0.0 promisc up
/sbin/ifconfig br0 $IP netmask $NETMASK broadcast $BCAST up
brctl stp br0 off
brctl setfd br0 1
brctl sethello br0 1
brctl addif br0 eth0

for i in 0 1 2 3 4; do
start_tap $i
brctl addif br0 tap$i
done

/sbin/route add default gw $DEFGW

3 File Systems

First, create the file systems for use by the UMLs. The following commands will create a 2G ext3 root file system and a 128M swap partition. This does not require root privileges.

$ dd if=/dev/zero of=root_fs bs=1M count=1 seek=2000
$ /sbin/mke2fs -F -j root_fs

$ dd if=/dev/zero of=swap_fs bs=1M count=1 seek=127
$ /sbin/mkswap swap_fs

Note, that the resulting files are so-called sparse files, i.e. they take up less space than ls reports (Try du instead). If you want to copy these files using rsync , use the -S ( --sparse ) option.

4 User-Mode Linux Kernel

More detailed info about compiling the kernel can be found on the User-mode Linux homepage.

First, unpack the kernel and apply the UML-patch. Then configure the kernel and compile the linux binary and the modules. Do not forget the ARCH=um!

$ tar xjvf /path/to/linux-2.4.20.tar.bz2
$ cd linux-2.4.20
$ bzcat /path/to/uml-patch-2.4.20-2.bz2 | patch -p1

$ make menuconfig ARCH=um
$ make linux modules ARCH=um

Module installation requires root privileges and the root_fs to be mounted. This step should be done later, after the package installation is completed.

# make modules_install INSTALL_MOD_PATH=/path/to/uml/mnt ARCH=um 

Alternatively, you can run the following command inside the UML, if you configured hostfs or NFS access to your UML kernel sources (requires make and findutils to be installed in your UML):

# make modules_install ARCH=um

5 Slackware

5.1 Package Installation

This section will use standard Slackware package management tools, therefore this will only work on systems running Slackware Linux. Mounting and installing packages into the root_fs file usually requires root privileges.

To mount the root file system, create the mount point and use the loopback device:

# mkdir mnt
# mount -o loop root_fs mnt/

Packages are installed using the standard pkgtools installpkg program. The command line argument -root /path/to/uml/mnt will install files into the mounted root file system.

The -ask and -menu options provide an easy way to select only desired packages. Note, that you do not need to (and should not) install any of the kernels.

Change to the slackware directoy (the one that contains the disksets a/, ap/, d/, ...) and install packages. The following installpkg command is only an example, you can add packages from more disksets if you want. An example list of packages is shown at the end of this section.

# cd /path/to/slackware/
# installpkg -root /path/to/uml/mnt -ask -menu \
    a/*.tgz ap/*.tgz d/*.tgz e/*.tgz n/*.tgz

# cd /path/to/uml
# chroot mnt /sbin/ldconfig

5.2 Configuration

After package installation, you need to do some basic configuration before the first start. Note, that all file paths given here are relative to the mounted uml root file system!

First, create the initial etc/fstab:

none  /dev/pts  devpts  gid=5,mode=620  0  0
none  /proc     proc    defaults        0  0

/dev/ubd/disc0/disc  /     ext3  defaults  0  0
/dev/ubd/disc1/disc  swap  swap  defaults  0  0

If you want to mount directories on the host file system in the UML, you can add entries like the following to fstab. You must have compiled hostfs support into your UML kernel.

none /mnt/shared hostfs defaults,/path/on/host/uml/shared 0 0

Now edit etc/rc.d/rc.S and remove the blocks dealing with fsck, this won't work from inside the UML:

#  if [ ! -r /etc/fastboot ]; then
#    echo "Checking root filesystem:"
#    /sbin/fsck $FORCEFSCK -C -a /
#    RETVAL=$?
#  fi
#  # An error code of 2 or higher will require a reboot.
#  if [ $RETVAL -ge 2 ]; then
#    ...
#    reboot -f
#  fi
# Check all the non-root filesystems:
#if [ ! -r /etc/fastboot ]; then
#  echo "Checking non-root filesystems:"
#  /sbin/fsck $FORCEFSCK -C -R -A -a
#fi

UMLs also do not have access to the hardware clock, so remove the hwclock block from etc/rc.d/rc.6 :

# Save the system time to the hardware clock using hwclock --systohc.
# Detect SGI Visual Workstation, since hwclock will make those freeze up:
#if fgrep -l Cobalt-APIC /proc/interrupts 1> /dev/null 2> /dev/null ; then
#  echo "SGI Visual Workstation detected.  Not running hwclock."
#elif [ -x /sbin/hwclock ]; then
#  if grep "^UTC" /etc/hardwareclock 1> /dev/null 2> /dev/null ; then
#    echo "Saving system time to the hardware clock (UTC)."
#    /sbin/hwclock --utc --systohc
#  else
#    echo "Saving system time to the hardware clock (localtime)."
#    /sbin/hwclock --localtime --systohc
#  fi
#fi

Next, edit etc/inittab, remove all tty terminals and add the c0 console:

# These are the standard console login getties in multiuser mode:
c0:1235:respawn:/sbin/agetty 38400 console linux
#c1:1235:respawn:/sbin/agetty 38400 tty1 linux
#c2:1235:respawn:/sbin/agetty 38400 tty2 linux
#c3:1235:respawn:/sbin/agetty 38400 tty3 linux
#c4:1235:respawn:/sbin/agetty 38400 tty4 linux
#c5:1235:respawn:/sbin/agetty 38400 tty5 linux
#c6:12345:respawn:/sbin/agetty 38400 tty6 linux

If you installed emacs, but not X, you need to create a symlink for the emacs binary, that is not linked against X libraries:

# cd usr/bin
# ln -snf emacs-21.2-no-x11 emacs

Remember to unmount the root file system:

# umount mnt

5.3 Booting

The root file system is now prepared for the first boot. If you intend to create multiple UMLs, you can simply create copies of the root_fs as it is now.

Below is an example script to start the UML. The script requires the root_fs and swap_fs files as well as the linux kernel binary or a link to it in the current directory.

#!/bin/sh

name=usermode
mem=48M
tap=tap1

# change this path to point to correct tmpfs dir
export TMPDIR=/.../umltmpfs

echo "Checking root file system..."
/sbin/e2fsck -C -p root_fs
if [ $? -gt 1 ]; then
    echo "*** An error occured during the root filesystem check. ***"
    exit 1
fi

/sbin/ifconfig $tap
if [ $? -ne 0 ]; then
    exit 1
fi

echo "Starting kernel..."
./linux \
    ubd0=root_fs ubd1=swap_fs \
    con=pty con0=fd:0,fd:1 \
    mem=$mem \
    eth0=tuntap,$tap \
    umid=$name

5.4 First Boot Configuration

After you booted your UML the first time, proceed with the final configuration steps:

  1. Setting a root password
  2. Setting the host name
  3. Timezone configuration
  4. Network setup

Log in as root (no password) and set the hostname and a root password:

# echo "testuml.local" > /etc/HOSTNAME
# /bin/hostname `cat /etc/HOSTNAME | cut -f1 -d .`

# passwd

Run timeconfig to chose your time zone and netconfig to setup your network interface. After the next reboot, you should be able to access the network (or run /etc/rc.d/rc.inet1 to setup eth0 immediately)

Finally, customize your installation as usual, e.g.:

# cd /etc/rc.d
# chmod a-x rc.nfsd rc.serial rc.font.sample

6 Example Slackware Package List

This is an example set of packages from Slackware Linux 9.0.

aaa_base-9.0.0-noarch-1
at-3.1.8-i386-1
bash-2.05b-i386-2
bin-8.5.0-i386-1
bzip2-1.0.2-i386-4
cpio-2.5-i386-1
cxxlibs-5.0.2-i386-1
dcron-2.3.3-i386-4
devfsd-1.3.25-i386-2
devs-2.3.1-i386-13
diffutils-2.8.1-i386-1
elflibs-9.0.3-i386-1
emacs-21.2-i386-1
emacs-info-21.2-i386-1
emacs-leim-21.2-i386-1
emacs-misc-21.2-i386-1
emacs-nox-21.2-i386-1
etc-5.0-noarch-11
fileutils-4.1-i386-2
findutils-4.1.7-i386-1
gawk-3.1.1-i386-2
gettext-0.11.5-i386-1
glibc-solibs-2.3.1-i386-3
glibc-zoneinfo-2.3.1-noarch-2
grep-2.5-i386-2
groff-1.17.2-i386-3
gzip-1.3.3-i386-2
inetd-1.79s-i386-1
infozip-5.50-i386-1
iptables-1.2.7a-i386-2
iptraf-2.7.0-i386-1
kbd-1.08-i386-2
less-381-i386-1
lftp-2.6.5-i386-1
links-0.98-i386-2
logrotate-3.6.3-i386-1
lsof-4.66-i386-1
lynx-2.8.4-i386-5
make-3.80-i386-1
man-1.5l-i386-1
man-pages-1.56-noarch-1
modutils-2.4.22-i386-1
nc-1.10-i386-1
ncftp-3.1.5-i386-1
netpipes-4.2-i386-1
nfs-utils-1.0.1-i386-1
nmap-3.00-i386-1
openssh-3.5p1-i386-2
openssl-0.9.7a-i386-2
openssl-solibs-0.9.7a-i386-2
perl-5.8.0-i386-3
pkgtools-9.0.0-i386-1
portmap-4.0-i386-2
procps-3.1.6-i386-1
rsync-2.5.6-i386-1
screen-3.9.13-i386-1
sed-4.0.5-i386-2
sh-utils-2.0-i386-1
shadow-4.0.3-i386-6
slocate-2.7-i386-1
strace-4.4-i386-1
sysklogd-1.4.1-i386-7
sysvinit-2.84-i386-25
tar-1.13.25-i386-1
tcpdump-3.7.2-i386-1
tcpip-0.17-i386-16
tcsh-6.12.00-i386-2
texinfo-4.5-i386-1
textutils-2.0-i386-1
traceroute-1.4a12-i386-2
util-linux-2.11z-i386-1
wget-1.8.2-i386-2

7 Running ReSoA

To start ReSoA inside a UML, you must recompile the ReSoA sources with LINUXPATH in src/Config.make pointing to your UML kernel sources:

$ cd resoa/src
$ make clean all

An easy way to gain access to the ReSoA sources and modules from inside a UML is to mount the ReSoA source directory using the hostfs feature of User-mode Linux. E.g, add a line like the following to the UML's fstab . Replace /path/on/host/uml/shared with the path where you have copied the ReSoA sources to.

none /mnt/shared hostfs defaults,/path/on/host/uml/shared 0 0

You can then mount the shared directory on both UMLs (client and server) and start ReSoA as usual.

Server:

# mount /mnt/shared
# cd /mnt/shared/resoa/src
# ./rc.iplhp start
# ./rc.kresoad start

Client:

# mount /mnt/shared
# cd /mnt/shared/resoa/src
# ./rc.iplhp start
# ./rc.resoa start <server IP address>

If the ReSoA client successfully connected, you should see a CONNECTED message in /var/log/debug . After you have installed the ReSoA client utility, you can use ReSoA and invoke programs (e.g. resoa ncftp ftp.kernel.org ).

# cd /mnt/shared/resoa/src/tools/resoa
# make install

In case, you get unresolved symbols (e.g. ip_queue_xmit ) when loading the modules, you can either modify linux/net/netsyms.c to explicitly export these functions, or you can activate IPv6 or kHTTPd in the kernel config. Note that ReSoA does not depend upon IPv6 or kHTTPd, but enabling one of these options will export the functions, that ReSoA needs.

If you have set up UML networking as described above using a bridge, you can monitor the complete network traffic on the host computer. The CD contains a customized version of tcpdump that prints ReSoA messages in a human-readable format.

8 References

  1. The User-mode Linux Kernel Home Page: http://user-mode-linux.sourceforge.net/
  2. The Slackware Linux Project: http://www.slackware.com/
  3. Linux ethernet bridging: http://bridge.sourceforge.net/
  4. User-mode Linux: skas mode http://user-mode-linux.sourceforge.net/skas.html
  5. User-mode Linux: Setting up the network http://user-mode-linux.sourceforge.net/networking.html
  6. UML-based pseudo-dedicated hosting service http://uml.openconsultancy.com/paper.php
2003.05.14 18:12 CEST, tp@ananas.local.fonz.de