<<Include(Tag/ContentCleanup)>> <<Include(Tag/NeedsExpansion)>> User-Mode Linux is another virtualisation technique for running VirtualMachines under GNU/Linux. A simplified version of the Linux kernel is run as a normal user-space process. See the User-Mode Linux project page for more information. This page will help you get started using User-Mode Linux with Ubuntu. Guide is created for Hardy LTS, but will most likely work with other releases.
Installing required packages
The first thing we need is to install the uml kernel and utilities we will need.
sudo apt-get install user-mode-linux uml-utilities bridge-utils debootstrap
Creating a virtual machine image
The next step is getting us a nice ubuntu hardy filesystem:
# Create an empty file to contain the root filesystem dd if=/dev/zero of=uml-root-hardy bs=4096 seek=1M count=1 # Create the filesystem on the file mkfs.xfs uml-root-hardy # Mount the filesystem sudo mount -o loop uml-root-hardy /mnt # Switch to root account for the rest sudo -i # Install a base system on the mounted partition. Use i386 or amd64 for the --arch option debootstrap --arch amd64 hardy /mnt http://us.archive.ubuntu.com/ubuntu # Create an fstab file echo "/dev/ubd0 / xfs defaults 0 1" > /mnt/etc/fstab echo "proc /proc proc defaults 0 0" >> /mnt/etc/fstab # Create the device file for the root file system and configure permissions mknod --mode=660 /mnt/dev/ubd0 b 98 0 chown root:disk /mnt/dev/ubd0 # Create a hosts file echo "127.0.0.1 localhost" > /mnt/etc/hosts # Configure network interfaces: eth0 using dhcp echo "auto lo" > /mnt/etc/network/interfaces echo "iface lo inet loopback" >> /mnt/etc/network/interfaces echo "auto eth0" >> /mnt/etc/network/interfaces echo "iface eth0 inet dhcp" >> /mnt/etc/network/interfaces # Add first terminal and serial terminal to secure list echo "tty0" >> /mnt/etc/securetty echo "ttys/0" >> /mnt/etc/securetty # Remove the other terminal events rm /mnt/etc/event.d/tty2 rm /mnt/etc/event.d/tty3 rm /mnt/etc/event.d/tty4 rm /mnt/etc/event.d/tty5 rm /mnt/etc/event.d/tty6 rm /mnt/etc/udev/rules.d/75-persistent-net-generator.rules # Return to normal account exit
TODO: network bridge
Basically what we've done is created an empty filesystem, mounted it, and made some changes that we want done on all our VMs. Most of the commands need to be run as root using
sudo in order to set the permissions correctly.
Running the VM
We should be ready to run our new VM now:
linux ubd0=uml-root-hardy.cow1,uml-root-hardy umid=uml1
This command runs the virtual machine using a copy-on-write (COW) file in
uml-root-hardy.cow1. This file receives all changes that are made in the filesystem.
uml-root-hardy remains unchanged, so we can run several virtual machines from this image.
Note: if your virtual machine crashes when mounting the root filesystem, the copy-on-write mechanism doesn't work. Use the following command instead:
linux ubd0=uml-root-hardy umid=uml1
Just started To have your UML talking to the rest of the world, you have some options and one would be to use a TAP-interface in the host-OS. This interface is created with the use of tunctl as in:
tunctl -u uml-net
where `uml-net` is the user who should own the interface `/dev/net/tun`. It's very important this user matches the one specified in /etc/default/uml-utilities or the network won't work.