Simple Step by Step
- Download one of the kernel images
- Uncompress it:
bunzip2 kernel*bz2
- Make it executable:
chmod +x kernel*
- Download a root_fs filesystem (not all of these filesystem images are compatible with UML!)
- Then simply boot this root_fs filesystem:
./kernel* ubda=./root_fs mem=256m
You can login as
root
, the password should be blank/not required.
Adding networking
Having a virtual machine running is nice, being to access the network with it is nicer.In the example below, we assume that the subnet 192.168.0.1/24 is unused so we can attach our UML instance to it. You may need to modify this address to prevent clashes on your own network.
- We must create a
tap
device that we can allocate to the UML instance:(You will need the tunctl utility which may be available for your distribution, which is available here otherwise).tunctl -t tap1
- Let's assign an IP address on the host side:
ifconfig tap1 192.168.0.1
- The easiest way to manage IP addresses for the guest is to use a DHCP daemon on the host.
Let's create a DHCP configuration file in~/dhcp.conf
:Note: you will need place your own DNS IP in thedefault-lease-time 6000; max-lease-time 72000; option domain-name-servers 192.168.0.1; option routers 192.168.0.1; server-name "192.168.0.1"; ddns-update-style none; subnet 192.168.0.0 netmask 255.255.255.0 { range 192.168.0.100 192.168.0.254; }
domain-name-servers
(which you can grab from the host's/etc/resolv.conf
) if the host does not run its own DNS. - Then start the DHCP server on this new interface, using the new config file:
dhcpd -cf ~/dhcp.conf tap1
- Then you can modify the kernel command line to give UML access to this new network interface:
./kernel32-2.6 ubda=./root_fs eth0=tuntap,tap1,fe:f0:00:00:00:01,192.168.1.254 con0=fd:0,fd:1
Adding routing
The instructions above should allow you to communicate between the host and guest.In order for the guest to reach the outside world, you must tell the host how to route the packets coming to/from the guest:
- First, allow the host to forward packets to and from the guest:
echo 1 > /proc/sys/net/ipv4/ip_forward
- Then, add firewall rules to forward the packets:
iptables -t nat -I POSTROUTING -o eth0 -j MASQUERADE iptables -I FORWARD -i tap1 -j ACCEPT iptables -I FORWARD -o tap1 -j ACCEPT
Terminology
- Host: refers to the machine (generally a real physical machine) which will run the UML guest.
- Guest: refers to the virtual machine you boot using UML.