This is a short howto of setting up a networked (public IP via DHCP, using bridge) User-mode Linux on Debian unstable/sid 1). The guest installed here is Debian Etch.
The reason I prefer UML is because it is practically unconcerned of kernel upgrades and other system changes (host kernel does not require modifications).
You can either compile one yourself or use the one provided in Debian (package user-mode-linux).
To compile one:
$ wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.20.6.tar.bz2 $ tar jxf linux-2.6.20.6.tar.bz2 $ cd linux-2.6.20.6/ $ make menuconfig ARCH=um # make the selections you need, like iptables etc $ make linux ARCH=um
Now you should have a linux binary that is hopefully a working guest kernel.
Create a dedicated user for running UMLs:
# aptitude install bridge-utils uml-utilities # adduser --disabled-password uml # adduser uml uml-net
To use SSH from your regular account (ssh uml@localhost):
# su uml $ mkdir ~/.ssh/ $ nano ~/.ssh/authorized_keys2 # add the public key of your normal user
Once the kernel has been compiled, copy the linux binary to the uml user's home directory.
As the “uml” user:
$ mkdir $NAME; cd $NAME $ dd if=/dev/zero of=root_fs bs=1M count=0 seek=500 # 500 MB $ /sbin/mkfs.ext3 -F root_fs $ mkdir mounted $ su # mount -o loop root_fs mounted/ # debootstrap etch mounted/ # If you are running apt-proxy, add parameter "http://localhost:9999/debian"
Now configure the box before booting it:
# (echo 'auto lo'; echo 'iface lo inet loopback') >> mounted/etc/network/interfaces # echo 'auto eth0' >> mounted/etc/network/interfaces # echo 'iface eth0 inet dhcp' >> mounted/etc/network/interfaces # echo $NAME > mounted/etc/hostname # echo '/dev/ubd0 / ext3 defaults 0 0' >> mounted/etc/fstab # echo 'linux' >> mounted/etc/securetty # echo 'tty0' >> mounted/etc/securetty # echo '127.0.0.1 localhost' >> mounted/etc/hosts
Edit mounted/etc/inittab and comment out all gettys, and add:
# We launch just one console for UML: c0:1235:respawn:/sbin/getty 38400 tty0 linux
Change root password by booting the UML with “init=/bin/sh” and running “passwd”
I had hard time finding examples that didn't involve writing custom boot scripts. Here's the “debian way” I use:
/etc/network/interfaces:
auto br0
iface br0 inet dhcp
pre-up chgrp uml-net /dev/net/tun
pre-up tunctl -u uml -t tap0
bridge_fd 0
bridge_hello 0
bridge_stp off
bridge_maxwait 5
bridge_ports eth0 tap0
post-down tunctl -d tap0
Also, comment out “auto eth0” since dhclient is called on the bridge.
host$ ssh uml@localhost
Open ~/$NAME/params and type all the parameters you want to use in it:
~/$NAME/params
ubd0=root_fs eth0=tuntap,tap0 mem=256M
Now create a start.sh file with the following content:
~/start.sh
#!/bin/bash if [ $# -lt 1 ]; then echo "Usage: $0 <name> [params]" exit 1 fi NAME=$1 shift cd ~/$NAME || exit 1 ../linux umid=$NAME $(cat params) $*
host$ chmod a+x start.sh host$ crontab -e @reboot screen -d -m $HOME/start.sh $NAME
This will start the UML inside a screen after each reboot. You can attach to the screen with screen -x.
To resize it later (take care here):
(shut down the UML) $ e2fsck -f root_fs $ dd if=/dev/zero of=root_fs bs=1M count=0 seek=700 # 700 MB $ resize2fs root_fs $ e2fsck -f root_fs
When file system images are created for UMLs, they are initially sparse. However, as they get used the actual image fills up to consume the full size. Making the files sparse again is useful for saving space (for backups):
uml$ dd if=/dev/zero of=zero; sync; rm zero (shut down uml) host$ cp --sparse=always root_fs root_fs.sparse
~~DISCUSSION~~