INR User-Mode-Linux week 3

Joeri Blokhuis March 4, 2010


UML networking
Basic plan

We are going to create small and medium sized networks to getting some practical experience with the lectured routing protocols. We need to create two scripts. One is called the host script and the other the guest script.


Host script
Creating more than one instance

I created two instances by running the following command twice.
linux.uml rootfstype=hostfs rootflags=/uml ro &

The option ’ro’ will mount the filesystem as read-only, so I couldn’t write to the filesystem. For writing you can use the ’rw’ command. I did not encounter any problems by running multiple instances. To make a directory writable I added the following to my rcS script,
if [ ! -z %{home} ]; then mount none /root/#{home} -t hostfs -o /home/joeri/uml_auto/#{home}; fi;

This will mount a unique directory for every instance and will be writable inside the read-only mounted UML. I tested this by writing a file inside the directory.


Guest script

In order to load the guest script at init I added the following line in the inittab:

Now I need to create a /var directory containing lock, log, run and tmp using ramfs. Also /tmp has to be a symlink to /var/tmp
mkdir mount mkdir mkdir mkdir mkdir ln -s /var -t ramfs -o size=20m ramfs /var /var/tmp /var/lock /var/log /var/run /var/tmp


Why these directories and what are they for?

The /var contains data that is changed when the system is running normally. lock Lock files. Many programs follow a convention to create a lock file in to indicate that they are using a particular device or file. Other programs will notice the lock file and won’t attempt to use the device or file. log Log files from various programs, especially login and syslog. run Files that contain information about the system that is valid until the system is next booted. tmp Temporary files that are large or that need to exist for a longer time than what is allowed for /tmp. Source: (


Running more than one instance

To encounter the problem of a UML taking over the console, there are two simple options. Option one is the screen command and the second option is a separate xterm console.



I looked up how screen works and how it can be used for the UML instances. In fact this is pretty easy. The following command was used to start a UML instance in detached mode with screen.
screen -S UML1 -d -m linux.uml rootfstype=hostfs rootflags=/uml umid=uml1 ro -dm start screen in detached mode -S sessionname

To see the list of current screens you can enter screen -list. To attach your screen to your console you can type screen -r and your session name.
screen -r UML1

Using the ctrl+a d keys you can detach it again.



To use xterm I have to use X-forwarding in ssh, which can be done with the -X option. To start a UML with xterm all I did was the following;
linux.uml rootfstype=hostfs rootflags=/uml umid=uml1 ro con=xterm &

I prefer to use the screen command, so from now on no more xterm for me because it will create to many consoles.


Configuring a UML network
Passing information

I added the following to my rcS script to pass IP information. If the IP argument is set it will set the IP address accordingly.
if [ ! -z #{IP0} ]; then echo ’ETH0 found’ /bin/ip addr add #IP0 dev eth0 /bin/ip link set eth0 up fi; if [ ! -z #{IP1} ]; then /bin/ip addr add #IP1 brd + dev eth1 /bin/ip link set eth1 up


fi; if [ ! -z #{IP2} ]; then /bin/ip addr add #IP2 brd + dev eth2 /bin/ip link set eth2 up fi; if [ ! -z #{IP3} ]; then /bin/ip addr add #IP3 brd + dev eth3 /bin/ip link set eth3 up fi;



Next I added roles like host, sniffer, bridge and router to the rcS script.
case #ROLE in host) echo ’host started’; ;; sniffer) echo ’sniffer started’; ;; bridge) echo "Bridge role started" ;; router) echo ’router started’; route add default gw #outergw #routergwdevice echo "1" > /proc/sys/net/ipv4/ip_forward ;; *) echo ’no role assigned’; ;; esac


More automation

The following script is using the start and stop function to create and destroy UML instances and switches. In the following script the X represent the number of the instance. I know this is not the most automated script you will find but it does the job and I’m have more control on errors.
#!/bin/bash case "#1" in ’start’) start-stop-daemon --start --quiet --background --pidfile /home/joeri/uml_auto/ --make-pidfile \ --exec usr/bin/uml_switch -- -unix /home/joeri/uml_auto/switchumlXX.clt (-hub) screen -S UMLX -d -m linux.uml rootfstype=hostfs rootflags=/uml umid=umlX ethX=daemon,,unix, /home/uml/switchumlXX.clt ROLE=Bridge|Sniffer|Host & ;; ’stop’) #To stop all instances without using the halt command for every instance by hand uml_mconsole umlX halt #stopping all the switches created start-stop-daemon --stop --quiet --pidfile /home/uml/ *) echo "Usage: #0 [start|stop]" ;; esac


Re-creating the simple network

The simple script I created in the previous assignment will be as follows;
#!/bin/bash #if I accidentally try to start the script twice killall linux.uml killall uml_switch


case "%1" in ’start’) #number of switches start-stop-daemon --start --quiet --background --pidfile /home/joeri/uml_auto/ --make-pidfile \ --exec /usr/bin/uml_switch -- -unix /home/joeri/uml_auto/switchuml01.clt; #number of uml instances in this format screen -S UML1 -d -m linux.uml rootfstype=hostfs rootflags=/uml umid=uml1 \ eth0=daemon,,unix,/home/joeri/uml_auto/switchuml01.clt IP0= ROLE=Host con=xterm; screen -S UML2 -d -m linux.uml rootfstype=hostfs rootflags=/uml umid=uml2 \ eth0=daemon,,unix,/home/joeri/uml_auto/switchuml01.clt IP0= ROLE=Host con=xterm; ;; ’stop’) #To stop all instances without using the halt command for every instance by hand uml_mconsole uml1 halt; uml_mconsole uml2 halt; #stopping all the switches created start-stop-daemon --stop --quiet --pidfile /home/joeri/uml_auto/; ;; ’status’) screen -ls ;; *) echo "Usage: %0 [start|stop|status]"; ;; esa


Sign up to vote on this title
UsefulNot useful