User Mode Linux

Swe05
One problem with RPM is that installing RPM packages almost inherently requires root (administrator) access on the target machine. Not only do packages typically want to be installed in global directories such as /usr/bin for which root access is required, but RPM also registers installed packages in a global database in /var/rpm which is also owner by root. While it is possible to use a relocatable RPM packages and another database, we will not do that for the RPM exercises.

Instead, we are going to use User-Mode Linux (UML). UML allows you to run any number of virtual Linux machines under Linux. Disk storage for such machines is stored in regular files (disk images). In principle any Linux distribution can be installed on such virtual disks. Anything you do inside the virtual machine does not affect the outside world.

Tutorial

Preliminaries

UML only runs on Linux systems, so you should log in onto one of the Linux systems in BBL-401 or BBL-406 (remotely, if necessary, as described in LearnSubversion). You should also add the directory containing UML to your path, as described in LearnSubversion.

Running it

Try to run UML by typing linux on the command line. You should see the Linux kernel start, and eventually the message

  Kernel panic: VFS: Unable to mount root fs on 62:00
That is, we have to specify a disk image for the kernel to use.

Disk images

An image of Red Hat Linux 7.2 has been provided in /praktikum/se/images/. You can run it as follows:

  linux ubd0=/users/yourname/cow,/praktikum/se/images/redhat
ubd0 is the name of the disk image device. In order to save disk space we use UML's copy-on-write feature: any changes you make to the virtual disk will be written to the file cow in your home directory instead of /praktikum/se/images/redhat. This saves you from having to make a complete copy of that file, which is rather big.

Note that the COW file may appear to be very big (600+ MB), but in fact it takes up much less disk space than that due to the use of sparse files (parts of the file that are not actually written to do not take up disk space). However, if you run out of disk space, you can use /net/tmp instead.

A common problem is that UML makes zero-byte COW files if some error occurs when you first try to create it. Subsequent attempts to start UML will then fail with the error message "Failed to read COW header." Deleting the COW file will fix this.

After a while a login prompt should appear. You can login as user root, password root.

Play with it

You can now use RPM inside the virtual machine. For example,

  rpm -qa
will show you what packages are installed. Or we can ask what package /bin/sh belongs to:
  rpm -qf /bin/sh
We see that belongs to package bash. We can try to uninstall the package:
  rpm -e bash
which will complain. If we really want to we can force removal:
  rpm -e --nodeps bash
Congratulations, you have destroyed your system. No matter, you can just delete the COW file and start with a fresh copy.

The UML machine can be shutdown cleanly using the halt command.

Sharing files

To install RPMs built on the host system in the virtual machine you have to have some way to transfer files from the host to the virtual machine. In fact, the entire host file system in mounted under /mnt/host, so you can find your home directory in /mnt/host/users/yourname (a symbolic link has been provided so that /users/yourname also works).

For safety /mnt/host has been mounted read-only (so that, for example, rm -rf / doesn't destroy your real home directory). If you want to copy things to the host file system you have to remount it:

  mount -o remount,rw /mnt/host