Tags : NetBSD
Xen is a free software used to do servers virtualization. Just like other virtualization softwares (WMWare, Virtual PC, Virtual Box, QEMU ...), a host operating system is needed in order to run several guest operating systems, isolated each of them.
For Xen, I choose NetBSD (Version 5.1, at the time I wrote this article) with PAE extension. It is also possible to use NetBSD on 64-bits processor (amd64). With amd64 architecture, PAE extension does not make sense, but the following procedure will be globally the same.
$ uname -a NetBSD pampa 5.1 NetBSD 5.1 (XEN3PAE_DOM0) #0: Sun Nov 7 15:07:49 UTC 2010 email@example.com:/home/builds/ab/netbsd-5-1-RELEASE/i386/201011061943Z-obj/home/builds/ab/netbsd-5-1-RELEASE/src/sys/arch/i386/compile/XEN3PAE_DOM0 i386
First of all, you need to make a default NetBSD installation. You will find all the informations needed here.
Then, it could be useful to configure your network device and activate OpenSSH. Edit the /etc/rc.conf file by adding the following lines :
# Local system clock rtclocaltime=YES # Network configuration ifconfig_re0="dhcp" sshd=YES
Of course, adjust the ifconfig_re0, variable accordingly, depending of your network device. rtclocaltime=YES variable is used to set an offset on the system clock, depending of the timezone machine.
You will find all the informations needed here.
I used the following command line, in order to get the 2011 branch stable :
cd /usr && cvs -q -z3 -d anoncvs@anoncvs.NetBSD.org:/cvsroot checkout -r pkgsrc-2011Q1 -P pkgsrc
Install the 2 following packages
cd /usr/pkgsrc/sysutils/xentools3 && make package cd /usr/pkgsrc/sysutils/xenkernel3 && make package
Xen tools and kernel will be installed on your NetBSD host system.
Copy the Xen kernel file
cp -p /usr/pkg/xen3-kernel/xen-PAE.gz /
Copy the RC scripts in order to autostart a few Xen daemons
cp -p /usr/pkg/share/examples/rc.d/xen* /etc/rc.d/
Then, add the following lines in your /etc/rc.conf file
# Xen xend=YES xenbackendd=YES xendomains=YES
Create a bridge virtual Ethernet interface. To do this, create a /etc/ifconfig.bridge0 file with the following lines :
create !brconfig $int add re0 up
Of course, adjust the ifconfig_re0, variable accordingly, depending of your network device.
Download the following files :
cd / ftp ftp://ftp.fr.netbsd.org/pub/NetBSD/NetBSD-5.1/i386/binary/kernel/netbsd-INSTALL_XEN3PAE_DOMU.gz ftp ftp://ftp.fr.netbsd.org/pub/NetBSD/NetBSD-5.1/i386/binary/kernel/netbsd-XEN3PAE_DOM0.gz ftp ftp://ftp.fr.netbsd.org/pub/NetBSD/NetBSD-5.1/i386/binary/kernel/netbsd-XEN3PAE_DOMU.gz
The next step is to reboot the NetBSD Xen kernel, with its module netbsd-XEN3PAE_DOM0.gz. NetBSD will be the first domain (in Xen vocabulary), called the dom0.
We will add a new entry in the NetBSD bootloader.
Edit the /boot.cfg file and add this line on top of the file :
menu=Boot NetBSD/XEN-PAE:load /netbsd-XEN3PAE_DOM0.gz console=pc;multiboot /xen-PAE.gz dom0_mem=128M
Your boot.cfg file will look like this
menu=Boot NetBSD/XEN-PAE:load /netbsd-XEN3PAE_DOM0.gz console=pc;multiboot /xen-PAE.gz dom0_mem=128M menu=Boot normally:boot netbsd menu=Boot single user:boot netbsd -s menu=Disable ACPI:boot netbsd -2 menu=Disable ACPI and SMP:boot netbsd -12 menu=Drop to boot prompt:prompt default=1 timeout=5
If a problem occurs, you could always revert to the original generic NetBSD kernel (2nd line).
Now, you can reboot the system and choose the first line, during the bootloader prompt.
The xen.gz kernel will be loaded with its module netbsd-XEN3PAE_DOM0.gz (NetBSD as a dom0). To keep enough RAM for guest operating systems, I have set 128MB of memory, which would be enough, in my opinion.
Next time, I will explain how to install guest operating systems (also known as domU, in Xen vocabulary). The procedure is different, depending of the guest operating system (NetBSD, Debian Linux, FreeBSD, OpenBSD ... etc).
For exemple, netbsd-INSTALL_XEN3PAE_DOMU.gz and netbsd-XEN3PAE_DOMU.gz files are NetBSD kernels as a domU. The first one is only needed when we will make a default NetBSD installation as a domU.