With all the recent activity happening with Linux being ported to things, people started running out of hardware to port linux to. So one smart cookie decided to port Linux to uh, Linux! And thus the UserModeLinux project was born.
User mode linux is basically a program that lets you run linux as a normal process under linux.
To get it running under debian sid I did:
apt-get install user-mode-linux
you then want to add yourself to the uml-net group. I didn't find this documented anywhere, but if you don't do this, you'll get weird random messages when you try and use networking under user-mode-linux. People in this group can do nasty things to your network so only give it to people you trust yadda yadda yadda. Remember to logout/login again after making this change
Then, I created a 512 mb "hard disk"
dd if=/dev/zero of=root_fs bs=1M count=512
and formatted it with ext2
then mounted it as a loop back device
mkdir uml && mount -o loop ./root_fs uml
then built my disto on it
debootstrap woody uml /mirrors/debian
you can then boot uml
linux single rw devfs=mount eth0=tuntap,,,the-ip-of-your-host-machine
it'll boot up into single user mode so you can configure and finalise the installation
ifconfig eth0 the-ip-of-your-uml-machine netmask the-netmask route add -net 0 gw the-ip-of-your-gateway
If you get the error SIOCSIFFLAGS: Operation not permitted when trying to bring up eth0, ensure that the user you are running UML as on the host has read/write permissions to /dev/net/tun. See the note about the uml-net group above.
apt-get update apt-get upgrade
This failed on my system, but it passed after creating a /etc/apt/apt.conf file with the following content
APT::Default-Release "woody"; APT::Cache-Limit 10000000; Apt::Get::Purge;
You don't need lilo, and it gets in the way, so lets get rid of it.
apt-get remove lilo
Now lets configure all the packages
dpkg-reconfigure -a tzconfig
now before we reboot we need to create some files that the installer usually creates
echo /dev/ubd/0 / ext2 defaults,errors=remount-ro 0 1 >/etc/fstab echo none /proc proc defaults 0 0 >>/etc/fstab echo hostname-of-your-uml-machine >/etc/hostname
and lets set up networking on boot
echo 'auto lo' >/etc/network/interfaces echo 'iface lo inet loopback' >>/etc/network/interfaces echo 'auto eth0' >>/etc/network/interfaces echo 'iface eth0 inet static' >>/etc/network/interfaces echo ' address address-of-your-uml-box' >>/etc/network/interfaces echo ' netmask netmask' >>/etc/network/interfaces echo ' network network' >>/etc/network/interfaces echo ' broadcast broadcast' >>/etc/network/interfaces echo ' gateway gateway' >>/etc/network/interfaces
and setting the hardware clock will always fail in uml
now, lets configure /etc/inittab correctly, replace tty1 with vc/0, tt1 with vc/1 in the file.
and now lets copy the modules over
mkdir -p /mnt/host mount none /mnt/host -o / -t hostfs mkdir -p /lib/modules/`uname -r`/kernel cp -r /mnt/host/usr/lib/uml/modules/`uname -r`/kernel/* /lib/modules/`uname -r`/kernel depmod -a
for me it complains about the scsi devices, since this is a virtual kernel, I figure i don't need them so I deleted them then rerun depmod
and now your box should be ready to boot again, so shutdown -h now the box then
linux devfs=mount eth0=tuntap,,,10.100.1.8 ro
voila, it should boot up, pop up some windows and ask you to login!
Or you can do it the easy way: copy /etc/rootstrap/rootstrap.conf into the current working directory, edit the networking config (don't meddle with too many of the options, many of them don't work if you change them, for instance installing sid doesn't work...) and run (in the same directory)
wait a significant time. you now have a uml image installed. you can start it with
./linux th0=tuntap,,,ip-of-your-host-machine ro
If you want to reduce the size that your root_fs take up, try the following:
If you receive the following error when trying to start your uml process with networking:
Exec of 'uml_net' failed - errno = 2 tuntap_open_tramp failed - errno = 22 SIOCSIFFLAGS: Invalid argument
I tried EVERYTHING to get rid of this. Finally the solution was VERY simple. Run as a standard user, who is in the uml-net group, and not as root. Note: This is a "works for me". I still don't know why this solved the problem, only that it did. Also, another oddity is that AFTER I had run it as a user, I could then run it as root with no problems. This smacks of tap0 being created with incorrect permissions or some oddity. Anyway, it works now.
It took a while for me to work out how to mount a root FS for RH9 so I could change it before booting UML. The FS had two partitions and a partition table, so mount the_fs /mnt -o loop didn't work. It turns out you need to specify an offset to mount to skip past the partition table. You can find out how many bytes to skip by doing this:
# fdisk redhat9.image.server-minimal.disk Command (m for help): u Changing display/entry units to sectors Command (m for help): p Disk redhat9.image.server-minimal.disk: 0 MB, 0 bytes 128 heads, 32 sectors/track, 0 cylinders, total 0 sectors Units = sectors of 1 * 512 = 512 bytes Device Boot Start End Blocks Id System redhat9.image.server-minimal.disk1 * 32 3756031 1878000 83 Linux redhat9.image.server-minimal.disk2 3756032 4194303 219136 82 Linux swap Command (m for help): q # bc bc 1.06 Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. 32*512 16384 # mount redhat9.image.server-minimal.disk /mnt -o loop,offset=16384 -t ext3
This is a fairly trivial task if you are used to compiling kernels. The main point to remember is to add
to each command (or export it as a shell variable).
make defconfig ARCH=um make ARCH=um mount -o loop ./root_fs /mnt/uml make modules_install INSTALL_MOD_PATH=/mnt/uml ARCH=um umount /mnt/uml
If you're compiling on 64 bit Linux you will probably also need to add SUBARCH=i386 as well.