getting started with user-mode linux
TRANSCRIPT
32
wants to com-municate with a
device (for instance, todisplay something on a monitor,
print a document, or copy a file to afloppy), the process asks the Linuxkernel to manage the communicationwith the hardware (Figure 1).
User-Mode Linux is a Linux kernelthat runs in Linux as a process. The dif-ference between a UML kernel and anordinary kernel is that the UML kerneldoes not communicate directly with thehardware. Commands pass instead tothe “real” Linux host kernel, whichmanages the hardware communication.
about anew oruntested patch.System administratorsuse UML to test system con-figurations. You can even run multipleversions of UML on the same host tosimulate a network.
What is User-Mode Linux?User-Mode Linux is not really an emula-tor, nor is it an API. The best way toexplain User-Mode Linux is to start witha look at the role of the Linux kernel.
The kernel runs processes and talkswith the hardware. When a process
Thepopularand versatile
User-Mode Linux (UML) [1] creates afully operatational virtual Linux systemon a Linux host. UML has many uses inthe Linux world. Developers rely onUML to test their applications withoutputting the host system at risk. Linuxusers run UML to experiment with ker-nel versions without having to worry
Getting started with User-Mode Linux
LINUX IN LINUX
Schlagwort sollte hier stehenLINUX USER User-Mode LinuxCOVER STORY
32 ISSUE 54 MAY 2005 W W W . L I N U X - M A G A Z I N E . C O M
There is a very interesting documentthat explain how to set up an SELinux-enabled UML system at [15]. AnSELinux-enabled UML can be very use-ful for creating more secure servers andtesting SELinux policy without puttingthe system at risk.
SELinux into UML
User-Mode Linux feels like Linux because it is Linux. You’ll find a hundred uses for this fast and sensible
virtual Linux system. BY FABRIZIO CIACCHI
ww
w.sxc.hu
Because the virtual system and thehost system are both Linux systems withnearly identical structures, the commu-nication passes very efficiently from thevirtual system to the host, requiring min-imal overhead for abstraction or transla-tion.
Setting Up UMLYou can install User-Mode Linux withyour package manager. For example,with Debian, you need to give this com-mand as root:
# apt-get install U
user-mode-linux U
uml-utilities U
kernel-patch-uml
This command installs the UML kerneland also other utilities. Other packagemanagers are equally simple, but if youhave a problem installing from a pack-age system, or if you have memory prob-lems during boot [2], you may wish todownload a normal linux kernel (we rec-ommend the 2.4.27 version [3]) and theUML kernel patch [4]. You can find otherUML patches at [5]. When you havedownloaded the patch and kernel files(in the same directory, of course), opena terminal window and execute the fol-lowing commands:
$ bunzip2 linux-2.4.27.tar.bz2$ tar -xvf linux-2.4.27.tar$ bunzip2 uml-patch-2.4.27-1.bz2$ patch -p1 -d linux-2.4.27 U
< uml-patch-2.4.27-1$ cd linux-2.4.27$ make menuconfig ARCH=um$ make linux ARCH=um$ strip linux
After you sucessfully complete thesecommands, you will have a file called“linux” in your original directory. Thisfile is the User-Mode Linux kernel thatwill be used to boot the virtual linuxsystem.
To make UML work properly, youneed to include two other pieces of thepuzzle: a root filesystem (a compressedimage of a linux partition that contains
33
COVER STORYUser-Mode Linux
33ISSUE 54 MAY 2005W W W . L I N U X - M A G A Z I N E . C O M
Figure 1: Normal Linux process structure.
Figure 2: UML runs as a process. In this fig-
ure, Proc1 is running on the host Linux sys-
tem. Proc2 is running on the User-Mode
Linux virtual system.
Perhaps the best way of understandingthe advantages of UML is to considerthat software of this type comes in threeforms:
• Software emulation
• Hardware emulation
• No emulation
Bochs [4] is one of the most famous soft-ware system emulators. The principalactivity of Bochs is to supply an emula-tion of a particular hardware architecture(IA-32, called also x86) on top of a partic-ular operating systems, like Windows,MacOS and, obviously, Linux. Once thehardware is emulated, it is possible toinstall any x86 operating system on it(Linux, Windows, Dos and so on), butthe execution is very slow, becauseevery computer instruction needs to betranslated from the guest operating sys-tem to the host operating system.
Hardware emulation consists of thecode built on the native hardware archi-tecture. A hardware emulator is moreefficient than the software emulator butit needs to intercept all the calls to thehardware. This solution has the big dis-advantage that the code must be spe-cialized for a particular hardware archi-tecture that is the same for host andguest environment. An example of thistype of emulator is VMware [5], a com-mercial system emulator.
User-Mode Linux fits in the last cate-gory; it doesn’t need to emulate any spe-cific hardware, but it instead talks nearlydirectly with the real hardware. Instruc-tions pass efficiently from the UML ker-nel through the host kernel. UML canexecute native code and can run with, atworst, a 20% slowdown compared torunning the same code on the host.
Emulation Choice
Figure 3: Booting the UML virtual system.
$ bunzip2 U
root_fs_toms1.7.205.bz2$ linux U
ubd0=root_fs_toms1.7.205
The ubd0= parameter tells the virtualsystem to use the file specified as theroot filesystem.
If all goes well, you’ll see the virtualsystem booting (Figure 3), and you canlog in to the virtual system with theusername root and the password root.
Sharing the Root FileSystemIt is possible to launch two or more vir-tual machines using the same rootfilesystem. The udb0 driver uses a mech-anism called Copy-On-Write (COW),which reads the root filesystem as aread-only shared device and stores thechanges in a read/write private file (theCOW file). For example, if you want to
start two virtual machines (VM1 andVM2) with the same filesystem, youneed to open two terminal sessions andwrite the following commands:
[xterm 1]$ linux U
ubd0=uml_vm1.cow, U
root_fs_toms1.7.205[xterm 2]$ linux U
ubd0=uml_vm2.cow, U
root_fs_toms1.7.205
All the modifications to the two virtualhosts will be written on the respectiveCOW files. In truth, the filesystem is notshared, but the two executions are inde-pendent of each other. The most impor-tant thing to avoid when the two COWfiles are created is booting the filesystemdirectly (with ubd0=root_fs_XXX),because every cow file has registered thesize and the timestamp of the rootfilesystem, and every modification willmake the COW files unusable. The cor-rect syntax to use for the next reboot,when we have a COW file, is as follows:
[xterm 1]$ linux U
ubd0=uml_vm1.cow[xterm 2]$ linux U
ubd0=uml_vm2.cow
Virtual and RealNetworkingUML provides several interesting optionsfor networking virtual Linux systems.Once you get your UML virtual systemup and running, you may wish to experi-ment with networking the virtual systemwith its host or networking it with othervirtual systems. You’ll find a thoroughdescription of UML networking at [8].
The basic idea behind UML network-ing is that several optional transports areprovided for managing the exchange ofpackets between the virtual system andthe host. Table 1 shows some of thetransport types available for UML.
all the programs) and the UML utilities.For the root filesystem, you can find allthe available images at [6]. You’ll needto download the UML utilities from [7]and type the following commands:
$ bunzip2 uml_utilitiesU_XXXXXXXX.tar.gz$ tar -xvf uml_utilitiesU_XXXXXXXX.tar$ cd tools$ make all$ make install DESTDIR=/
You now have a directory that containsthe root filesystem. Remember to put the linux program in a location thatpermits you to use it. (If you haven’tmoved the linux program, it is still in thelinux-2.4.27 directory.) Then enter thefollowing commands to read the rootfilesystem:
User-Mode LinuxCOVER STORY
34 ISSUE 54 MAY 2005 W W W . L I N U X - M A G A Z I N E . C O M
Figure 4: Booting process of the second UML virtual system.
Etherap, TUN/TAP Transports used for exchanging packets between the virtual system andthe real host.
Switch daemon A transport designed for purely virtual networking with other UML sys-tems.
Multicast Another transport designed for virtual networking.Slip, slirp Transports used primarily when Ethertap and TUN/TAP are not available or
if you don’t have root access to the networking configuration on the host.Pcap A transport that provides a read-only network interface and is, therefore, a
good option for network monitoring.
Table 1: UML Transport TypesIf your goal is to use UML for testingnew Linux distributions, you can opt forQEMU [12] system emulator application.QEMU (based on Bochs [13]) is verysimple to install, set up, and use. Formore on QEMU, see “Virtual Benefits:System Emulation with QEMU” in LinuxMagazine Issue #52, March 2005; youcan download the article in Pdf formatfrom our archive [14].
QEMU: A Good Alternative
User-Mode LinuxCOVER STORY
36 ISSUE 54 MAY 2005 W W W . L I N U X - M A G A Z I N E . C O M
To enable a network device in thevirtual machine, pass a string like thefollowing to the kernel command line:
eth<n>=U<transport>,<transport args>
where <n> represent the real hostinterface (i.e., eth0) to which the virtualmachine will attach. The theoreticalexplanation is that, in the UML virtualmachine, there is an eth0 device thatcorresponds to a tap0 device on the realhost; this tap0 interface is directly con-nected to the eth0 interface of the realhost.
So, we can use the command:
linux ubd0=root_fs_slack8.1 U
eth0=ethertap,tap0,Ufe:fd:0:0:0:1,192.168.0.254
to permit UML to set up eth0 in the vir-tual machine with its own IP address.
The IP address of real tap0 and virtualeth0 can be the same for simpler config-urations. (See [8] for more complex net-work configurations.)
You then need to set up the interfacein the virtual machine (/etc/hosts,/etc/resolv.conf, /etc/network, etc.) tohave fully operative Internet access inthe UML environment.
ConclusionUser-Mode Linux provides a quick andconvenient means for creating virtualLinux systems in Linux. You can use can UML as a tool for planning, model-ing, testing, and troubleshooting Linuxsystems. UML is also the basis for manyother open source projects and expe-riments, as well as for business appli-cations and personalized hosting ser-vices. Perhaps User-Mode Linux is notso easy to install and configure, but ifyou can get it working, you’ll find manyuses for it. ■
[1] User-Mode Linux Homepage: http://user-mode-linux.sourceforge.net
[2] UML on 2G/2G hosts: http://user-mode-linux.sourceforge.net/UserModeLinux-HOWTO-4.html#2G-2G
[3] Official Linux kernel 2.4.27: http://ftp.ca.kernel.org/linux/kernel/v2.4/linux-2.4.27.tar.bz2
[4] UML patch for kernel 2.4.27: http://prdownloads.sourceforge.net/user-mode-linux/uml-patch-2.4.27-1.bz2
[5] UML Downloads: http://user-mode-linux.sourceforge.net/dl-sf.html
[6] Root filesystem list: http://user-mode-linux.sourceforge.net/dl-jails-sf.html
[7] UML Utilities: http://prdownloads.sourceforge.net/user-mode-linux/uml_utilities_20040406.tar.bz2
[8] UML Network configuration: http://user-mode-linux.sourceforge.net/networking.html
[9] Compiling the kernel: http://user-mode-linux.sourceforge.net/compile.html
[10] Kernel debugging: http://user-mode-linux.sourceforge.net/debugging.html
[11] UML debugging session: http://user-mode-linux.sourceforge.net/debug-session.html
[12] QEMU Homepage: http://fabrice.bellard.free.fr/qemu/
[13] Bochs homepage: http://bochs.sourceforge.net
[14] QEMU Article “Virtual Benefits”:http://www.linux-magazine.com/issue/52/QEMU_System_Emulation.pdf
[15] SELinux and UML: http://www.golden-gryphon.com/software/security/selinux-uml.xhtml
INFO
Figure 5: The COW files of two UML Virtual Machines.
Figure 6: A UML Virtual Machine with network services available.
Fabrizio Ciacchi (http://fabrizio.ciacchi.it – [email protected]) is anitalian student of Computer Sci-ence at the University of Pisa. Hismain activities are studying Linux,developing Web Sites in PHP, andprogramming in Java. He alsoworks as a consultant for severalcompanies and writes articles onLinux.
THE
AU
THO
R