home | tech | misc | code | bookmarks (broken) | contact | README

# Xen setup NetBSD Dom0 and DomU

This is a page I will always try to keep up to date with latest NetBSD and Xen versions. At the time of this writing (beginning of 2014) I'm using NetBSD 6.1.2 and Xen 3.3.

This page is a summary of my experiences with NetBSD and Xen since NetBSD 3.1 and Xen 2.0, although it is a very simple experience, as the user of basic features only. Back to that days of NetBSD 3.1 we needed to install GRUB bootloader to be able to boot Xen. We don't need it anymore, since NetBSD comes with its own good bootloader since version 5.0.

A very useful, more complete and probably up to date reference where I got much of the information is the NetBSD/xen HOWTO.

## Installing Xen

After installing NetBSD in your computer (with a common kernel like GENERIC), you need to download and compile the xenkernel from pkgsrc:

# cd /tmp
# ftp http://ftp.netbsd.org/pub/pkgsrc/current/pkgsrc.tar.gz
# tar zxf pkgsrc.tar.gz -C /usr
# cd /usr/pkgsrc/sysutils/xenkernel33
# make install


We now have the xen kernel built in /usr/pkg/xen33-kernel/xen.gz that we will use later. Now, build xentools package:

# cd /usr/pkgsrc/sysutils/xentools33
# make install


After the package was installed, created special Xen devices in /dev:

# cd /dev/
# ./MAKEDEV xen


Copied daemon scripts in the right place and configure rc.conf to lauch them at the system startup:

# cp /usr/pkg/share/examples/rc.d/xend /etc/rc.d/
# cp /usr/pkg/share/examples/rc.d/xenbackendd /etc/rc.d/
# echo 'xend=YES' >> /etc/rc.conf
# echo 'xenbackendd=YES' >> /etc/rc.conf


### Using the right kernel

The GENERIC kernel (the one that comes by default) cannot be used with Xen. You need to get another kernel. In my case, I needed the netbsd-XEN3PAE_DOM0 kernel that I didn't install and had to download it:

# cd /tmp
# ftp http://ftp.netbsd.org/pub/NetBSD/NetBSD-6.1.2/i386/binary/kernel/netbsd-XEN3PAE_DOM0.gz
# gunzip netbsd-XEN3PAE_DOM0.gz
# mv netbsd-XEN3PAE_DOM0 /tmp


Note

It is important to note that you cannot use the modload(8) command with the kernel to be used with Xen, because of a difference of the ABI's (check this link). If you want to use a special feature inside the Xen kernel, you will have to compile it by yourself.

We can use GRUB, but we'll use native NetBSD bootloader, introduced in NetBSD 5.0. What we need is to edit the /boot.cfg file, which is a very simple and plain text file. The man page of this file (boot.cfg(5)) has some examples on how to setup it to load the xen kernel and the NetBSD Dom0 kernel to work with Xen.

What we need to do is just to add the following menu entry:

menu=Xen 3.3 NetBSD PAE 6.1.2:load /netbsd-XEN3PAE_DOM0 console=pc;multiboot /usr/pkg/xen3-kernel/xen.gz dom0_mem=256M


And change the default parameter to where we just put this menu entry.

Reboot, select the right option and see the magic happening!

### Console setup

NetBSD comes with four text consoles setup, but Xen just uses one. You will see console warnings in the boot process.

When you login in your virtual machine, don't forget to turn off all the terminals but console. Change on to off in /etc/ttys.