mensi.ch

Archive for November, 2009

Creating a Debian lenny XEN DomU with root on NFS

by mensi on Nov.30, 2009, under debian

An easy and simple way to manage VMs with Xen is to let linux boot off NFS, so you can serve these filesystems off a central storage machine and still have access to the complete directory hierarchy, enabling you to do fancy stuff like incremental backups. Sure, NFS is not the best way to do this, but in a low budget situation or with older hardware, this solution works quite well.

Creating a DomU for use with NFS isn’t such a hard thing, there are several possible pitfalls though. Here is a step-by-step guide:

Create empty directory on the NFS server and export it with no_root_squash for the VM itself and the xenhost or the host you want to use to bootstrap the VM

/some/dir/www.example.org www.example.org(rw,no_root_squash,no_subtree_check)
/some/dir/www.example.org xen.example.org(rw,no_root_squash,no_subtree_check)

Don’t forget to reload NFS exports

exportfs -r

Mount it on the xenhost (or the host you’re using for bootstrapping)

mkdir /tmp/www.example.org
mount -t nfs xen.example.org:/some/dir/www.example.org /tmp/www.example.org

Use debootstrap to bootstrap an initial Debian lenny install

debootstrap lenny /tmp/www.example.org/ http://mirror.switch.ch/ftp/mirror/debian

We need to do some extra things inside the VM before we can actually boot it up, so we chroot into it

chroot /tmp/www.example.org

Correctly set the hostname

echo "www" > /etc/hostname

And the hostsfile, at least localhost is required

echo "127.0.0.1 localhost" > /etc/hosts

Add and configure the loopback interface

echo "auto lo" > /etc/network/interfaces
echo "iface lo inet loopback" >> /etc/network/interfaces

Add all desired sources to /etc/apt/sources.list

nano /etc/apt/sources.list

Install the bigmem kernel for your architecture. If you do not want to do this because you already have a kernel and an initrd, at least install udev.

apt-get install linux-image-2.6-686-bigmem

Install locales to get rid of warnings regarding LC_*

apt-get install locales
dpkg-reconfigure locales

Adjust initramfs for NFS support (set BOOT=nfs instead of local)

nano /etc/initramfs-tools/initramfs.conf

Add the xen frontend drivers to the initramdisk (add xen-netfront and xen-blkfront)

nano /etc/initramfs-tools/modules

Regenerate initramdisk

update-initramfs -u all

Spawn a console on hvc0 (add the following to /etc/inittab)

0:2345:respawn:/sbin/getty 38400 hvc0

Leave chroot

[Control-D]

Copy the kernel and initramdisk to some location on the xenhost

cp /tmp/www.example.org/boot/* /vmkernel/

To be able to use NFS properly be sure to:

  • DO NOT add the root to /etc/fstab as this will cause problems with the checkroot rcS script
  • Add ASYNCMOUNTNFS=no to /etc/default/rcS to be able to mount additional nfs shares
Leave a Comment :, , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...