Debian domU on NetBSD/xen dom0

It’s all about virtualization these days. XEN is one of them – virtual machine monitors or hypervisors, responsible for creating, running and manipulating virtual machines. And so much more. XEN runs directly on hardware (bare-metal hypervisor) and needs a host OS, respectively a XEN-enabled host OS kernel for creating the first virtual machine upon boot called control domain, dom0 /domain zero/ or privileged domain. Xen is useless without its dom0, used for the entire virtualization environment. Currently NetBSD and Linux (Xen support was kicked out from Solaris 11) have dom0 support.

Preparations

Fine tune for your needs and compile a netbsd/xen dom0 kernel:

% cd /usr/src/sys/arch/$(uname -m)/conf
% config XEN3_DOM0
Build directory is ../compile/XEN3_DOM0
Don't forget to run "make depend"
% cd ../compile/XEN3_DOM0
% make depend && make
rm -f amd64
ln -s ../../../../arch/amd64/include amd64
rm -f x86
ln -s ../../../../arch/x86/include x86
rm -f xen
ln -s ../../../../arch/xen/include xen
.
.
.
#      link  XEN3_DOM0/netbsd
ld -Map netbsd.map --cref -T ../../../../arch/amd64/conf/kern.ldscript.Xen -Ttext 0xffffffff80100000
-e start -X -o netbsd ${SYSTEM_OBJ} ${EXTRA_OBJ} vers.o
NetBSD 6.1_RC3 (XEN3_DOM0) #0: Thu Apr 11 15:27:29 EEST 2013
   text    data     bss     dec     hex filename
9886163  628840 1799616 12314619         bbe7fb netbsd

% cp netbsd /netbsd.xen

Build and install xen kernel (xen.gz) from pkgsrc/sysutils/xenkernel41:

% cd /usr/pkgsrc/sysutils/xenkernel41
% make install clean
 => Bootstrap dependency digest>=20010302: found digest-20121220
 => Checksum SHA1 OK for xen-4.1.4.tar.gz
 => Checksum RMD160 OK for xen-4.1.4.tar.gz
 ===> Installing dependencies for xenkernel41-4.1.4
 .
 .
 .
 ===> Installing for xenkernel41-4.1.4
 => Creating installation directories
/usr/bin/install -c -o root -g wheel -m 644 /usr/pkgsrc/sysutils/xenkernel41/work/xen.gz
/usr/pkgsrc/sysutils/xenkernel41/work/.destdir/usr/pkg/xen41-kernel/xen.gz
/usr/bin/install -c -o root -g wheel -m 644 /usr/pkgsrc/sysutils/xenkernel41/work/xen-debug.gz
/usr/pkgsrc/sysutils/xenkernel41/work/.destdir/usr/pkg/xen41-kernel/xen-debug.gz
 => Automatic manual page handling
 ===> Building binary package for xenkernel41-4.1.4
 => Creating binary package /usr/pkgsrc/packages/All/xenkernel41-4.1.4.tgz
 ===> Install binary package of xenkernel41-4.1.4
 ===========================================================================
 $NetBSD$
The Xen hypervisor is installed under the following locations:
 /usr/pkg/xen41-kernel/xen.gz (standard hypervisor)
 /usr/pkg/xen41-kernel/xen-debug.gz (debug hypervisor)
 ===========================================================================
 ===> Cleaning for xenkernel41-4.1.4
% cp /usr/pkg/xen41-kernel/xen.gz /xen.gz

With copied netbsd dom0 kernel and xen hypervisor to /, you’re almost ready. Now add a boot menu line to /boot.cfg for booting XEN (touch params to fit your needs):

menu=Boot Xen with 1024MB for dom0:load /netbsd.xen console=pc;multiboot /xen.gz dom0_mem=1024M

Build and install xen userland tools. Copy rc.d scripts to /etc/rc.d, then add few lines to /etc/rc.conf to start the userland tools on boot (for more options in rc.conf, look the docs). You’ll also need xen devices populated in /dev:

% cd /usr/pkgsrc/sysutils/xentools41
% make install clean
.
.
.
% cp /usr/pkg/share/examples/rc.d/xen* /etc/rc.d/
% echo xend=YES >> /etc/rc.conf; echo xenbackendd=YES >> /etc/rc.conf
% cd /dev; ./MAKEDEV xen

Create network bridge so your debian VM can access the host network adapter and use internet:

% cat << EOF > /etc/ifconfig.bridge0
> create
> !brconfig $int add IF_NAME up
> EOF
%

Reboot. If everything is OK, your system now have NetBSD/xen dom0 and userland tools up and running. You’re ready to create domU machines.

Create Debian domU

Unless you’ve got a dedicated partition for your guest OS, you can create an image file for putting the new debian system into: dd if=/dev/zero of=debian.img bs=1m count=2048.

Download a debian xen kernel, ramdisk and config from <mirror>/debian/dists/wheezy/main/installer-amd64/current/images/netboot/xen/. Touch name, memory, kernel, ramdisk, disk and vif params in your debian.cfg:

kernel="vmlinuz"
ramdisk="initrd.gz"
memory = 256
name = "debian"
vif = ['bridge=bridge0']
disk = ['file:debian.img,xvda,w']

Install debian as domU:

% xm create -c debian.cfg install=true

P.S.
After installing, remove the first two lines from debian.cfg, they’re no longer needed. That’s in brief. There’re many other options to play with, beyond the scope of this document.

[1] http://www.netbsd.org/ports/xen/howto.html
[2] http://wiki.centos.org/HowTos/Xen/InstallingCentOSDomU
[3] http://wiki.xen.org/wiki/Main_Page
[4] http://netbsd0.blogspot.com/2012/05/centos-under-netbsdxen-in-15-minutes.html

Leave a Reply

Your email address will not be published. Required fields are marked *