NetBSD and Xen




Some days ago, I read something about Xen, which is a virtual machine monitor for x86 hardware. Ok, I know Linux vServers and FreeBSD Jails, which are not working with my NetBSD machines. Thus I tried it.



Xen supports multiple guest operating systems on a single machine. Each guest OS (in Xen called 'domain') requires a modified Kernel which supports Xen, to access the physical hardware. The normal bootloader will be replaced with grub, which can load the Xen kernel along witch the guest kernel foer the first domain (domain0). The first domain can access all physical hardware and administrate other domains. I wanted to use NetBSD as domain0 and as unprivileged domain. But it's also possible to use FreeBSD, Linux and Plan9. So I have the chance to install a FreeBSD inside my NetBSD box, for testing etc. First we need to setup our host system (domain0), which can be done with a normal NetBSD installation (I used 3.0). See http://www.netbsd.org/guide/en/chap-inst.html for more details. Keep in mind, that you need own partitions for Xen. It's also possible to use large files and map them with vnd. First of all, we need some packages.
# cd /usr/pkgsrc/sysutils/grub # make install # cd /usr/pkgsrc/sysutils/xentools20 # make install # cd /usr/pkgsrc/sysutils/xenkernel20 # make install
Don't forget to copy /usr/pkg/xen-kernel/xen.gz to /. Now we've all the needed packages and we can install grub.
# grub-install /dev/wd0d
This can take a while, so get a new cup of coffee :-) Now we can configure grub, to load the Xen kernel. You can do this by editing the file /grub/menu.lst
default=0 timeout=10 serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1 terminal --timeout=10 vga console title Xen 2.0 / NetBSD 3 (hda0, vga) root(hd0,0) kernel (hd0,a)/xen.gz dom0_mem=65536 module (hd0,a)/netbsd-XEN0 root=/dev/hda1 ro console=tty0 title NetBSD 3.0 root (hd0,a) kernel --type=netbsd /netbsd-GENERIC
Don't reboot, until you got the kernels! ;-) You can find them on the NetBSD CD in binary/kernel. Copy netbsd-GENERIC, netbsd-INSTALL_XENU, netbsd-XEN0 and netbsd-XENU to / and gunzip them. Now you can reboot and grub should appear. As you can see, the Xen kernel is booting, which is loading netbsd-XEN0. Next we have to configure our network, to permit our guest OSes an access via bridge. This can be done in /etc/ifconfig.bridge0, I'm using a Realtek card (rtk0).
create !brconfig bridge0 add rtk0 !brconfig bridge0 up
And make some scripts executeable...
# chmod +x /etc/ifconfig.bridge0 # chmod +x /usr/pkg/etc/xen/network # chmod +x /usr/pkg/etc/xen/vif-bridge
Configure rc system and start xend
# cd /dev && sh MAKEDEV xen # cp /usr/pkg/share/examples/rc.d/xend* /usr/pkg/etc/rc.d/ # echo "xend=YES" >> /etc/rc.conf # /usr/pkg/etc/rc.d/xend start
When xend is started you can check the system with
# xm list Name Id Mem(MB) CPU State Time(s) Console Domain-0 0 63 0 r---- 1145.0
This will list all active Xen domains, and we are only seeing our domain0. So it's time to install another. First we need a startup script for initial configuration.
kernel = "/netbsd-INSTALL_XENU" memory = 128 name = "setup" cpu = -1 nics = 1 vif = [bridge=bridge0' ] disk = [ 'phy:/dev/cd0a,cd0a,r', 'phy:/dev/wd0h,wd0d,w' ] root = "/dev/wd0d"
You can save the file, for example as /usr/pkg/etc/xen/setup. Now we need the NetBSD CD-ROM to install our unprivileged domain.
# xm create -c /usr/pkg/etc/xen/setup
This will create a new domain and load a NetBSD kernel in it. The option -c is telling Xen to switch to a virtual console. Now you can see, that a "computer" is booting, it's the NetBSD CD-ROM. NetBSD can now be installed in the virtual machine, but there are some things you should know:
  • your disklabel has now the name xbd0d, not wd0h
  • your DVD/CD-ROM is now xbd1d
  • you will not see the dialogues about your partitions and slices
After the installation you can shutdown the virtual machine with halt -p. To change to your domain0 system use CTRL-]. Now it's time to make a new configuration for our new system. Create a file /usr/pkg/etc/xen/test
kernel = "/netbsd-XENU" memory = 128 name = "test" cpu = -1 nics = 1 vif = [ 'bridge=bridge0' ] disk = [ 'phy:/dev/wd0h,wd0d,w' ] root = "/dev/wd0d"
To boot the domain use
xm create -c /usr/pkg/etc/xen/test
Last but not least, we have to do some configuration in /etc/rc.conf
powerd=YES xendomains="test"
The tag xendomains will start all given domains at boot time. You have to seperate the domains with a whitespace. Some xen commands:
  • xend start - initialize Xen tools
  • xm list - list all running domains
  • xm console - switch to domain
  • xm shutdown - shutdown domain
  • xend stop - stop all domain


15. Mai, 2006

Kommentar hinzufügen