Subject: Xen HowTo - the first part
To: None <port-xen@netbsd.org>
From: Michael Kukat <michael@unixiron.org>
List: port-xen
Date: 12/10/2004 11:02:53
Hello,

as promised, i'll try to compile some kind of HowTo here if i get through the
Xen/NetBSD topic. So here my first things which might be interesting for
everyone playing around:

1) Files and the function...
I think, here is really a lot of misunderstanding, as the files aren't really
documented with their function. Following files are known to me:

xen12load - the bootloader, this is just needed for the Xen (the Linux-based
top level component) to be able to boot a NetBSD kernel. So you just need this
for Domain0. Used in a module statement in grub configuration
xen12netbsd - Mentioned in Christians setup directions for setting up Domain0
with NetBSD. This is the kernel compiled from the kernel source
(sys/arch/xen), config file "XEN", needs DOM0OPS. At least needs them to
create new domains and so.
xen-1.2.gz - Xen itself, createn by pkgsrc/sysutils/xen12
xen-1.2-fixed.gz - some fixed version of this (?)
xen-1.2-fixed-ide.gz - fixed version with more IDE drivers (?)
The above 3 files are _NOT_ NetBSD kernels, as i initially thought. So, you
don't get console messages from them when booting in some domain :)

Besides this, there are NetBSD kernels on the Xen Website. At least i read of
them. Forget them, they do _NOTHING_. The only chance to get working NetBSD
kernels for Xen seems to be compiling them yourself. Look at sys/arch/xen in
-current or 2.0 release. You can compile such a kernel with your usual i386
installation.

xen12load - interesting stuff. I just checked out cvsweb for this, as i got
trouble compiling it from 2.0 release. Look here:
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/arch/xen/stand/xen12load/xenload.h
There is some patch for u16, u32 and u64 used somewhere. I used 2.0 release
and did a similar patch yesterday to get this fixed and to get xen12load
built. It _DOESN'T_ compile with a 2.0 release kernel source. There you should
at least replace the xenload.h from CVS. Then, just go to
sys/arch/xen/stand/xen12load, type make, and copy the resulting xen12load to
/grub, where all the other stuff resides.

Installation made easy:

2 Ways to play around:

1) Try to run NetBSD in an unprivileged domain to play around.
I don't tell you how to set up all your Xen stuff, i personally just created
partition and stuff after booting the Demo CD and copied the full Demo CD onto
this partition. This is described in the Xen docs.
From here, you can set up an NFS server to boot NetBSD, use your built kernel,
prepare your root filesystem, and fire up everything. See Christians first
Message, "getting started" for reference about this.

2) Try to run NetBSD in Domain0
Install NetBSD/i386 (2.0 or some RC) to you box as usual. This will be your
Domain0 setup later, but in the first place it shall be just a working NetBSD
installation. Also put the kernel source and pkgsrc in there.
Make kernels, sysutils/xen12, sysutils/grub, sysutils/xentools12 and drop in
everything to /grub like described by Christian somewhere in this list. Now
you can just fire up your Xen / NetBSD thingie and play around.

So for for theory. Currently, my known problems (and so my reasons why not
writing a full documentation about this :) are:

- In several places, the size of NetBSD kernel must be a multiple of 4. To get
sure, or if you run in strange problems, do the following:
ls -l netbsd to get the size of the kernel (netbsd stands for any kernel name
here)
echo $((<size>%4)) to get modulo 4 of the kernel size (replace <size> with the
value from ls -l)
dd if=/dev/zero bs=1 count=<len> >>netbsd
to pad the kernel. replace <len> with the output of the above echo statement
and netbsd with the name of the kernel you are working on.

- I didn't get grub to boot my old NetBSD kernel directly. Workaround: insert
some NetBSD installation disk/CD, boot off it, abort the countdown and boot
your kernel with this bootloader. If for some reason you don't get this
working, just enter "boot -a", so the install kernel is booted and asks you
for the root fs, where you enter "wd0a" or anything else matching your setup.

- Currently i have the problem of NetBSD not really booting, but standing
latest at "copying in /sbin/init" or so, eating up all CPU (you see this in
vmware eating all your host CPU time or the fans of some machines, especially
notebooks, starting to move hot air out). So, currently it is absolutely
unusable for me. I tried both ways mentioned above, and i tried xen-1.2.gz
from pkgsrc and xen-1.2-fixed-ide.gz from ftp.netbsd.org. Always the same
effect. Currently, this is a complete showstopper, as i now don't know where
to hunt further. Any hints?

And some generic stuff:

"Xen" is the top level component talking to your hardware. This is some piece
of code based on a Linux kernel. In NetBSD you see this as "xen-1.2.gz",
"xen-1.2-fixed.gz" or "xen-1.2-fixed-ide.gz". This component has to be bootet
in the first place if you want to use Xen. It provides some abstraction layer
to control your hardware, so every OS image below this needs to have special
"drivers" to talk to your hardware.
"xen12load" is the bootloader module which Xen needs if you want to run NetBSD
in Domain0, booted via Grub.
On to of this, you can put one of the following:
- NetBSD Kernel from sys/arch/xen, config XEN as Domain 0 kernel (can control
domains)
- NetBSD Kernel from sys/arch/xen, config GENERIC as any domain (can't control
domains)
- a custom NetBSD kernel from sys/arch/xen
- a Linux kernel built for xen support
- Windows XP or 2K modified to run under Xen (currently not available for the
public)
- Anything else providing "drivers" to run in a Xen VM (aka domain).

Those drivers are needed for at least the following components:
- User interface components (VGA adapters, serial ports, keyboard, mouse)
- Block devices (CD-ROM, hard disks, these can be virtual)
- Xen Console interface (read out by xen_read_console)
- Network interface

Everything else you need to know can be read in the Xen papers/documentation.
It might be a good point to start playing around with the DemoCD to get
familiar with Xen. I started with copying the DemoCD to local hard disk (okay,
in vmware ;), creating virtual block devices for 4 domains on 4 parts of a
single disk partition and have 4 Linuxes running with NFS-mounted /usr and
blockdev-based root FS. On top of this, i tried to get NetBSD running as a
first step.

So, i hope, all this clears up some things and reduces the pain for the
readers in trying to get things running. Maybe my pain of the last days has
some positive side effect with this :)

I'll continue fiddling now!

...Michael

-- 
http://www.unixiron.org/    Home Powered by: (Net|Open|Free)BSD IRIX NonStop-UX
Solaris AIX HP-UX Tru64 MUNIX Ultrix VMS SINIX Dolphin_Unix OpenStep MacOS A/UX