The root file system is the file system that is directly mounted by the kernel during the boot phase and that holds the system initialization scripts and the most essential system programs. More specifically, the root file system includes the root directory together with a minimal set of subdirectories and files including ‘/boot’, ‘/dev’, ‘/etc’, ‘/bin’, ‘/sbin’ and sometimes ‘/tmp’.
Mounting the root file system is a crucial part of system initialization. The Linux kernel allows the root file system to be stored in many different places [4], such as a hard disk partition, a floppy disk, a ramdisk or a remote file system shared via NFS. In any case, the root file system can be specified as a device file in the ‘/dev’ directory either when compiling the kernel or by passing a suitable ‘root=’ option to the initial bootstrap loader. The root file system is mounted in a two-stage procedure:
The root file system of a domU guest can be stored on a disk image in dom0, on a physical disk partition or in a directory hierarchy on dom0 or on a remote system which can be exported to the client via NFS. In this section we follow the last approach. More specifically, the root file system for the domU guest will be located on an exported directory hierarchy stored in a NFS server. This server could be dom0 guest, a remote machine or even another domU guest. Our goal is the domU client to mount this exported directory hierarchy as its root file system via NFS.
- The kernel mounts the special ‘rootfs’ file system, which provides an empty directory.
- The kernel mounts the real root file system over this empty directory.
The root file system of a domU guest can be stored on a disk image in dom0, on a physical disk partition or in a directory hierarchy on dom0 or on a remote system which can be exported to the client via NFS. In this section we follow the last approach. More specifically, the root file system for the domU guest will be located on an exported directory hierarchy stored in a NFS server. This server could be dom0 guest, a remote machine or even another domU guest. Our goal is the domU client to mount this exported directory hierarchy as its root file system via NFS.
1. Preparation
Our working environment consists of the dom0 guest with IP address 192.168.1.100 and of a domU guest (‘domu1’) with IP address 192.168.2.2. The ‘domu1’ can see our home network through a virtual bridge with IP address 192.168.2.1 which resides on dom0. The dom0 guest will act as an NFS server and will provide the root hierarchy to the clients. Thus, our goal is the ‘domu1’ to mount the server’s exported root hierarchy as its root file system via NFS. Note that the root file system can also be stored on a remote machine or even in a domU guest who acts as sever.
2. Server configuration
At this point we will analyze the necessary steps that need to be done on the server side. Initially, we will focus on the server’s kernel configuration and then we will see how to create the root file system for the guest and how to export it.
On the server side we will need to compile NFS server support into the kernel. More specifically, our dom0 kernel must have the following options enabled as build-in:
Network File Systems →
NFS client support – enabled
NFS client support for NFS version 3 – enabled
NFS client support for the NFSv3 ACL protocol expansion – enabed
NFS client support for NFS version 4 – enabled
Use the new idmapper upcall routine – enabled
NFS server support – enabled
NFS server support for NFS version 3 – enabled
NFS server support for the NFSv3 ACL protocol expansion – enabed
NFS server support for NFS version 4 – enabled
Assuming our server’s file system is ext4, we should also select the following options if we wish to use NFSv4’s extended attributes and ACL features:
File Systems →
The extended 4 (ext4) filesystem
Ext4 Extended attributes – enabled
Ext4 POSIX Access Control Lists – enabled
Now we will create a root file system for our domU guest. Let’s assume that we have an NFSv4 server already configured and running. For a guide on how to set up an NFSv4 server look on [http://www.cs.uoi.gr/~gkappes/tutorials/nfs_installation.pdf]. Firstly, we create the directory ‘/export’ if it doesn’t already exist:
root@dom0$ mkdir /export
Then, we create a new directory under ‘/export’ to place the guest’s root file system:
root@host$ mkdir /export/domu1
Now, we can populate the guest’s root file system either by copying from the dom0’s root:
root@ dom0$ cp –ax /{root,dev,var,etc,usr,bin,sbin,lib} /export/domu1
root@ dom0$ mkdir /export/domu1/{proc,sys,home,tmp}
or by installing a base Linux distribution, for example Debian Squeeze:
root@dom0$ debootstrap --arch i386 squeeze /export/domu1 http://ftp.us.debian.org/debian
Next, we tailor the file system by editing ‘/etc/fstab’, ‘/etc/hostname’, ‘/etc/network/interfaces’ etc and adding some user accounts. Note that ‘/etc/fstab’ and ‘/dev/’ need some caution. In ‘etc/fstab’ we have to mount the root file system via the NFS server. Assuming that our NFS-server is on 192.168.2.1, the guest’s ‘/etc/fstab’ must look like this:
192.168.2.1:/ / nfs rw 0 0
proc /proc proc defaults 0 1
Furthermore, we have to create a dummy device on the guest’s ‘/dev’ directory:
root@dom0$ chroot /export/domu1
root@dom0$ mknod /dev/nfs b 0 255
root@dom0$ chown root:disk /dev/nfs
root@dom0$ exit
Also, the guest’s ‘/etc/network/interfaces’ file must look like this:
# Used by ifup(8) and ifdown(8). See the interfaces(5) manpage or
# /usr/share/doc/ifupdown/examples for more information.
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.2.2
netmask 255.255.255.0
network 192.168.2.0
broadcast 192.168.1.255
gateway 192.168.2.1
up route add -net 192.168.1.0/24 gw 192.168.1.1
up route add default gw 192.168.1.1
Of course, you can adjust it properly to suit your needs.
With the root file system populated on the NFS server and NFS services running, the next step is to export it so that it can be mounted on the domU guest. This is achieved by adding an entry to the ‘/etc/exports’ file on the server:
/export/domu1 192.168.2.2(rw,fsid=0,async,wdelay,no_root_squash,no_subtree_check)
In the above example 192.168.2.2 is the IP address of the domU guest which will use the exported root file system. The option ‘rw’ indicates that the domU guest can make changes to the file system, while the ‘fsid=0’ signals that the current export is the root. Also, ‘async’ enables asynchronous writes and ‘wdelay’ tells to the NFS server to delay writing to the disk if it suspects another write request is imminent. The ‘no_root_squash’ option disables root squashing on the server and finally the ‘no_subtree_check’ disables the sub tree check. Once the ‘/etc/exports’ file has been updated, the ‘exportfs’ command can be run to update the table of exported NFS file systems:
root@dom0$ exportfs –a
Alternatively you can restart the NFS service.
On the other side, the domU guest’s kernel needs the following settings as minimum in order for the guest to be able to mount its root file system via NFS:
Networking support →
Networking options →
IP: kernel level autoconfiguration – enabled
IP: DHCP support – enabled
IP: BOOTP support – enabled
IP: RARP support – enabled
File Systems →
Network File Systems →
NFS client support – enabled
NFS client support for NFS version 3 – enabled
NFS client support for the NFSv3 ACL protocol expansion – enabed
NFS client support for NFS version 4 – enabled
Root filesystem on NFS – enabled
Use the new idmapper upcall routine – enabled
Be careful to compile the above options as build in and not as modules. Modules only work after the kernel is booted, and these things are needed during boot.
In order to successfully boot the new domU guest we have to pass it some options in order to tell it how to mount its root file system. This task could be done through its Xen configuration file ‘/etc/xen/domu1’:
# -*- mode: python; -*-
#=========================================
# Python configuration setup for 'xm create'.
# This script sets the parameters used when a domain is created using 'xm create'.
# You use a separate script for each domain you want to create, or
# you can set the parameters for the domain on the xm command line.
#=========================================
# Kernel image file.
#kernel = "/boot/vmlinuz-3.0.4"
kernel = "/home/giorgos/xen/domains/domu1/vmlinux-3.0.4-domu"
# Optional ramdisk – In order for the domU guest to mount its root
# filesystem via NFS correctly, make sure to disable this option.
#ramdisk = "/home/giorgos/xen/domains/domu1/initrd.img-3.0.4-domu"
# Initial memory allocation (in megabytes) for the new domain
memory = 128
# A name for your domain. All domains must have different names.
name = "domu1 "
# Define network interfaces.
vif = [ '','bridge=br0' ]
# Set ip.
ip='192.168.2.2'
# Set netmask.
netmask='255.255.255.0'
# Set default gateway.
gateway='192.168.2.1'
# Set the hostname.
hostname='domu1’
# Set root device for nfs.
root ='/dev/nfs'
# The nfs server.
nfs_server ='192.168.2.1'
# Root directory on the nfs server.
nfs_root ='/export/domu1'
# Sets runlevel 4.
extra = "4"
on_poweroff = 'destroy'
on_reboot = 'restart'
on_crash = 'restart'
#=========================================
Let’s explain the basic options we use above:
- vif = [ ‘’,‘bridge=br0’ ]: With this option we specify the custom bridge ‘br0’ to xend. You can use its default bridge if you want to.
- ip = ‘192.168.2.2’: With this option we set the IP address of the domU guest’s primary network interface.
- netmask = ‘255.255.255.0’: With this option we specify the netmask of the domU guest’s primary network interface.
- gateway = ‘192.168.2.1’: With this option we specify the gateway of the domU guest’s primary network interface.
- hostname = ‘domu1’: With this option we specify the hostname of the domU guest.
- root = ‘/dev/nfs’: Here comes the ‘/dev/nfs’ dummy device file that we created earlier. This is necessary to enable the pseudo-NFS-device. Note that it’s not a real device but just a synonym to tell the kernel to use NFS instead of a real device.
- nfs_server = ‘192.168.2.1’: This option specifies the location of the NFS server that exports the domU guest’s root file system.
- nfs_root = ‘/export/domu1’: This option tells to the domU guest where to find its root file system on the NFS server.
Note that it’s important to specify all the necessary information for the domU guest in order to set up its primary network interface correctly, because we need the guest’s networking to be correctly configured before it tries to mount its root file system. We achieve this by specifying the parameters ‘ip, ‘netmask’, ‘gateway’ and ‘hostname’. To automatically assign an IP address to the guest using DHCP service we can simply use the option dhcp = “dhcp” and omit the ‘ip’, ‘netmask’ and ‘gateway’ options.
Now, we can start the new guest domain by typing:
root@dom0$ xm create –c domu1
No comments:
Post a Comment