I've recently setup a simple UML instance on debian. What I find truly great is, that utilizing rootstrap and slirp, I can create, configure and run a user-mode-linux instance without once needing root access (that is, after the required packages are installed).
First we need some additional debian packages:
$ sudo aptitude install user-mode-linux uml-utilities slirp rootstrap
/etc/rootstrap/rootstrap.conf and remove the comments for the 'slirp' paragraph in the '[network]' section.
After this, a new debian-etch filesystem can easily be build using rootstrap:
$ dd if=/dev/zero of=root bs=1 count=0 seek=256M $ /sbin/mke2fs -F root $ dd if=/dev/zero of=swap bs=1M count=128 $ /sbin/mkswap swap $ rootstrap root
Now we can boot into the new instance and configure the system. Since I don't like logging in using xterms or whatever, I want to login on the terminal where I started the uml instance. To do this, we need to change '/etc/inittab' within the uml. We boot UML into single user mode
$ linux.uml con=nul con0=fd:0,fd:1 ubda=root ubdb=swap \ root=/dev/ubda eth0=slirp,,slirp-fullbolt s
in single user mode within the UML we edit /etc/inittab:
UML# vi /etc/inittab
We comment out all '/sbin/getty' lines except the first and replace the terminal 'tty1' in the first '/sbin/getty' line with 'tty0'. We exit vi and add 'tty0' as a valid secure terminal and reload the inittab.
UML# echo 'tty0' >>/etc/securetty UML# init q
Next we add the swap partition:
UML# echo '/dev/ubdb swap swap defaults 0 0' >>/etc/fstab UML# swapon -a
Then change the hostname to something meaningful:
UML# echo 'myuml' >/etc/hostname UML# hostname -F /etc/hostname UML# echo "127.0.0.1 localhost.localdomain localhost `hostname`" >/etc/hosts
That's it. We can exit single user mode and continue to boot into runlevel 2. There we can then login as root (no password).
Use 'shutdown' to exit the UML.
UML# shutdown -h now
A 256M partition is large enough to install a minimal etch system but not much more. To resize the filesystem, use resize2fs:
$ /sbin/e2fsck -f root $ dd if=/dev/zero of=var/root bs=1 seek=1G count=0 $ /sbin/resize2fs root 1G
Will resize the root filesystem to 1G (sparsely). The same procedure may be used to shrink a filesystem. Shrinking and then re-enlarging a filesystem can help save space since it will recreate unused space in the image as sparse regions.