Introduction to User-Mode Linux

Home / Introduction to User-Mode Linux

Introduction to User-Mode Linux

December 9, 2015 | Article | No Comments

If you are practicing for network engineering, there are many options to setup your own virtual network lab. GNS3, Netkit, Marionnet, VNUML, just name a few. All of those tools are great way to setup network lab. They are great for learning how to build network and practice various network topology in easier way. Yes, they are not low level. They keep us from customizing our linux node used in network lab. If we want true network with various setting and configuration, then we need dive deeper.

So imagine I want some nodes with different configuration. All configuration files (including the ones for the virtual hosts) are kept into one subdirectory and able to be modified while the lab was running. The node should start in few seconds. Is it possible? Well, let’s discuss User-Mode Linux. Well, it’s not fancy solution like other tools are. More like a home-made solution to match some of things you need.

User-Mode Linux, as hinted by the name, is a linux kernel that run as a process on another GNU/Linux operating system. It is a secure way of running Linux as a process. We can call it as type of virtualization but has different approach compared to VirtualBox or VMWare. It is closed to containerization but not the same. We run buggy software, experiments with new Linux kernels or distributions, and poke around in the inernals of Linux, all without risking main Linux.

User-Mode Linux and Virtualization Technology

Technology-wised, there are two types of virtualization technologies. They are full-virtualization and containerization, both offers some advantages over the other. The full virtualization, as in VirtualBox, VMWare, Xen, create a virtual resources or emulate physical platforms from CPU to the peripherals in which Linux will run. The containers, as in chroot, jail, docker, rkt, are sharing the same OS kernel as the hosts and run in some kind of isolation.

UML is closely related to the containers. However, UML itself is a fully functional Linux running as a process, make it different to containers. In the perspective of host, UML is like another process, running and ask for resources. From the perspective of UML, it is a kernel and give services to its processes. The UML itself is a modified copy of Linux kernel. Therefore, we can say that UML is a kernel as well as a userspace program in the same time.

Grab the Materials

There are two components of UML: the kernel and the filesystem. The kernel is the vital part. You can obtain the kernel here: http://uml.devloop.org.uk/

That links provide a kernel up to certain version. All are available in 32-bit and 64-bit architecture.

You can download a filesystem on here: http://fs.devloop.org.uk/

For this article, I will use Kernel version 3.11.2 64-bit and file system Slackware 12.x 64-bit.

We can create our own UML and filesystem, but that’s for another time.

Extract the kernel and filesystem. Here I have:

  1. kernel64-3.11.2
  2. Slamd64-12.1-root_fs

For the sake of simplicity, I will refer the kernel64 for the kernel we use and slamd64 for the filesystem.

First Boot

Let’s head to kernel first. Check and run the kernel:

chmod +x kernel64
./kernel64 mem=512M

It is quite straightforward. I run kernel and having virtual RAM about 512MB. Don’t worry if you encounter a kernel panic. It’s fair to assume that we didn’t specify any root filesystem (and that’s right). Now, let’s boot UML in proper way. This time, we will boot kernel and specify a filesystem.

./kernel64 ubda=Slamd64 mem=512M

Now you can see the familiar login prompt on your terminal.

Add a Network Support

To add network capability to UML node, we have to create a new TAP interface. We should allocate the TAP device to UML instance. Here, on you host Linux:

tunctl -t tap0

tap0 is the device name of our new interface.

Next, assign an IP address to it, assuming the IP address is 192.168.135.1 and on 192.168.135.0/24 network. Of course you need to adjust it to your network.

ifconfig tap0 192.168.1.1

Then modify the kernel invocation, by:

./kernel64 ubda=Slamd64 mem=512M eth0=tuntap,tap0,MAC_ADDR,IP_ADDR con0=fd:0,fd:1

There is also an option to utilizing DHCP daemon on the host to gives IP automatically to UML nodes. For example we use dhcpd for DHCP daemon. Create a DHCP configuration file in ~/dhcp.conf. Let’s say we want to create network 192.168.135.0/24

default-lease-time 6000;
max-lease-time 72000;
option domain-name-servers 192.168.135.1;
option routers 192.168.135.1;
server-name "192.168.135.1";
ddns-update-style none;
subnet  192.168.135.0  netmask  255.255.255.0  {
   range 192.168.135.2 192.168.135.254;
}

Our DNS might not be 192.168.135.1 so we should make it to the real DNS server.

Start the DHCP server on tap interface.

dhcpd -cf ~/dhcpd.conf tap0

and then modify kernel command line to give UML access to this new network interface.

Add Routing

The previous section should allow communication between the host and the guest (UML node). In order for the guest to reach the outside world we must configure the routing table. It means we need to tell the host to route the packets coming to/from the guest. It can be achieved by modifying firewall rules. However the very first thing to do is to make sure host is allowed to forward packets.

Execute following command.

echo 1 > /proc/sys/net/ipv4/ip_forward

Then add firewall rules.

iptables -t nat -I POSTROUTING -o eth0 -j MASQUERADE
iptables -I FORWARD -i tap0 -j ACCEPT
iptables -I FORWARD -o tap0 -j ACCEPT

In the next occasion, we will discussing some labs for UML.

,

About Author

about author

xathrya

A man who is obsessed to low level technology.

Leave a Reply

Your email address will not be published. Required fields are marked *

Social media & sharing icons powered by UltimatelySocial