In order for our new UML kernel to be functional we have to supply it with a root file system. We will create a disk image which will contain the root file system for our guest UML. This image will act as a hard disk for our guest system. In order to create an empty disk image we will use the ‘dd’ (man 1 dd) utility:
host$ cd /home/giorgos/uml
host$ dd if=/dev/zero of=/home/giorgos/uml/root-fs bs=1024K count=1024
With the above command we created an empty disk image with 1GB free space. Now, we must initialize the file system inside of the image file. We will use ext4 as our root file system:
host$ mkfs.ext4 /home/giorgos/uml/root-fs
At this point we have an empty disk image formatted with ext4 file system. The next step is to populate the file system with a copy of the host’s root or with a base system of our favorite Linux distribution. In this guide we choose to install a Debian Squeeze base system. To achieve this, we first mount the disk image to a new directory on the host and then we use the ‘debootstrap’ (man 8 debootstrap) utility to populate the image with a Debian Squeeze base system:
host$ su
host$ mkdir /mnt/root-fs
host$ mount –o loop /home/giorgos/uml/root-fs /mnt/root-fs
host$ debootstrap --arch i386 squeeze /mnt/root-fs http://ftp.us.debian.org/debian
In the above example we chose i386 as the architecture of our new system. We can specify a different architecture by changing the argument after ‘arch’ parameter. However, it’s important to select the same architecture with the UML kernel we built earlier.
Guest system configuration
After populating the disk image with a base Debian system we need to edit some files in order to have our guest system in a valid configuration:
/etc/fstab
The ‘/etc/fstab’ file is a system configuration file that lists all available disks and disk partitions and indicates how they are to be initialized or otherwise integrated into the overall system's file system. In this guide we mount the virtual disk device ‘/dev/ubd0’ on the root specifying ‘ext4’ as the file system. Also, we mount the proc file system on ‘/proc’ directory:
/dev/ubd0 / ext4 defaults 0 1
proc /proc proc defaults 0 0
/etc/hostname
The hostname file contains the host name of the guest system. We add the name:
uml1
/etc/network/interfaces
This file contains network interface configuration information for the ifup(8) and ifdown(8) commands. This is where you configure how your system is connected to the network. At this point we will add the loopback interface to this file. Later on this guide we will add some more network interfaces to provide a fully functional networking on the UML guest. So, we open this file with an editor and we add the following values:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
#
# The loopback network interface
#
auto lo
iface lo inet loopback
Note that the lines beginning with # are comments.
/etc/securetty
The ‘/etc/securetty’ file allows you to specify which TTY devices the root user is allowed to login on. The ‘/etc/securetty’ file is read by the login program usually ‘/bin/login’. Its format is a list of the tty devices’ names allowed, and for all others that are commented out or do not appear in this file, root login is disallowed. We append this file with the following values:
tty0
ttys/0
/dev
The ‘/dev’ directory contains the special device files for all the available devices. If the virtual block device ‘ubd0’ does not exist there we have to create it manually. We run the following commands as root:
host$ chroot /mnt/root-fs
host
$ mknod --mode=660 ubd0 b 98 0host$ chown root:disk ubd0
host$ exit
/etc/inittab
The ‘/etc/inittab’ file describes which processes are started at boot up and during normal operation. To login immediately after the boot messages we commend out the following lines:
# 2:23:respawn:/sbin/getty 38400 tty2
# 3:23:respawn:/sbin/getty 38400 tty3
# 4:23:respawn:/sbin/getty 38400 tty4
# 5:23:respawn:/sbin/getty 38400 tty5
# 6:23:respawn:/sbin/getty 38400 tty6
And we modify ‘tty1’ to say ‘tty0’ in the line beginning with ‘1:’
1:2345:respawn:/sbin/getty 38400 tty0
Now, it’s time to add a new user to the UML guest. To do this we run the following commands as root:
host$ chroot /mnt/root-fs
host$ adduser uml
host$ exit
Instead of using the tool ‘adduser’, we can add a new user by hand, adding an entry to ‘/etc/passwd’ and ‘/etc/shadow’ files. After adding the new user we can specify a password for the root user. We run the following commands as root:
host$ chroot /mnt/root-fs
host$ passwd
host$ exit
After completing the above steps, we can boot our new UML guest. However, it’s important to unmount the guest’s root file system from the host before booting it, otherwise it will be corrupted.
host$ umount /mnt/root-fs
host$ cd /home./giorgos/uml
host$ ./linux ubd0=rootf-fs mem=128MB
In the above example we assume that we use a virtual disk image named ‘root-fs’ as the UML guest root file system. With the ‘mem=128MB’ option we specify the amount of RAM that the UML guest will believe it has. Actually this command doesn’t allocate 128MB of physical RAM on the host. Instead, it creates a 128MB sparse file on the host. Being sparse, this file will occupy very little disk space until data starts being written to it. As the UML instance uses its memory, it will start putting data in the memory backed by this file. As that happens, the host will start allocating memory to hold that data. Since the file is fixed in size, the UML instance is limited to that amount of memory.
------
Get the whole pdf: http://www.cs.uoi.gr/~gkappes/tutorials/uml_guide.pdf
No comments:
Post a Comment