How to build NetBSD DomU on Linux

From Xen

Why build NetBSD DomU on Linux ?

It is easy to do.

It could be very practical - in daily use or just for evaluating the last NetBSD.

There are many situations peoples need this.

If you still (or plan to) use or to customize your NetBSD DomU this script is a easy way to get a current or release (stable) NetBSD installation CD (iso image), install sets for different installation types (by DOS, PXE network boot, floppies etc) and a full distribution tree for your production server Xen DomU.

why build your own NetBSD XEN DOMU ?

The official XEN_DOMU build from NetBSD is not suitable for bigger server installations - but NetBSD is a very perfect server operating system.

This distribution includes a specialized NetBSD kernel (XEN3_DOMU_NIELS) - optimized for high load servers and many users on the DomU.

You can further edit the kernel config if you want to suite more of your special needs.

build netbsd easy

This script is a easy way to take a look into the latest NetBSD for peoples wich are new to netbsd or to build you own current or release (stable) NetBSD Xen DomU server distribution.

This script should be usable under (m)any linux or other unix os.

A lot of peoples runs a linux host within their network to provide and distribute many different open source distributions and builds for different machines. Most Xen hosts (Dom0) are linux based currently and many Xen admins provides a shared / automated pool of DomU installations and distributions from their Xen Dom0 to their DomUs.

This script makes it easy to get and handle NetBSD for Xen installations and updates too.


This script should work out of the box with default configuration.

However, if you want to change config options feel free to do it in the config section of the script.

customize your netbsd XEN DOMU kernel

You can customize your XEN DOMU kernel if you want.

For this just uncomment these two lines before you run the script

## uncomment the following two lines in case you will make your own kernel config

i want no i386 netbsd (cross building)?

No prob, just change the ./ machine option MARCH (default is i386) to your target arch or machine as required.(not tested yet, sorry)

running the script

You should be on a shell (root is not necessary).

Download [javascript:void(0);/*1297163288231*/] and / or Copy this script "" - i.e. to somewhere within your home directory.

Just run it by


The script creates a directory netbsd within your current home directory.

The whole build would be done under this directory.

# -- build a complete, current and, or any
#    NetBSD distribution and a ready to use install CD/DVD  image, the
#    is know to work on Linux/*BSD :)
# features:
#    - includes GENERIC netbsd kernel
#    - includes a customized XEN DOMU kernel
#    - optimized XEN DOMU for high load internet servers
#    - includes or excludes X11
# (expected to run under each linux distribution and, or most unixes)
# Author: Niels Dettenbach <>,
#    v1.0rc2, Licensed under the GPL
# Modified: Balwinder S Dheeman <>
#    v1.0rc3, Refined the code, Updated mirrors list
## --- Local Configuration (Edit, if needed)
# target path of the netbsd build
#build within home directory (~/NetBSD-domU/)
# select editor, if you want to further edit and, or review the kernel
# confiuration files, or comment the following line out ;)
# select a CVS host      # Master, IPv6  # Belgium  # France, IPv6  # Germany, IPv6  # Japan  # Romania  # Sweden # US, IPv6
# target machine
# select NetBSD release, change this to select a particular netbsd
# release or branch builds a stable NetBSD 4.0 (latest stable)
#RELEASE=netbsd-4-0-RELEASE     # Latest in 4.0
#RELEASE=netbsd-4-0-1-RELEASE   # Oct 14, 2008
#RELEASE=netbsd-5-0-RELEASE     # Latest in 5.0
#RELEASE=netbsd-5-0-1-RELEASE   # Aug 02, 2009
RELEASE=netbsd-5-0-2-RELEASE    # Feb 12, 2010
# NetBSD current (devel branch)
if [ 0 -eq 1 ]; then
echo "==> Preparing builddir $BUILDPATH/NetBSD-domU..."
mkdir -p $BUILDPATH/NetBSD-domU
mkdir -p kernel obj release src tools xsrc
# get extra kernel config for XEN DOMU internet servers
cd $BUILDPATH/NetBSD-domU/kernel
if [ ! -f XEN2_DOMU_NIELS ]; then
    echo "==> Downloading kernel/XEN2_DOMU_NIELS..."
if [ ! -f XEN3_DOMU_NIELS ]; then
    echo "==> Downloading kernel/XEN3_DOMU_NIELS..."
if [ -n "$MEDITOR" ]; then
# cvs checkpout the current cvs sources
export CVSROOT=anoncvs@$CVSHOST:/cvsroot
export CVS_RSH=ssh
if [ ! -d src/CVS ]; then
    echo "==> Checking out src..."
    cvs co -r $RELEASE -P src || exit $?
    echo "==> Updating src..."
    cd src && cvs up -Pd || exit $?
if [ ! -d xsrc/CVS ]; then
    echo "==> Checking out xsrc..."
    cvs co -r $RELEASE -P xsrc || exit $?
    echo "==> Updating out xsrc..."
    cd xsrc && cvs up -Pd || exit $?
# link in custom kernel config
    echo "==> Symlinking kernel/XEN[23]_DOMU_NIELS..."
ln -fs $BUILDPATH/NetBSD-domU/kernel/XEN2_DOMU_NIELS \
ln -fs $BUILDPATH/NetBSD-domU/kernel/XEN3_DOMU_NIELS \
# run, see $BUILDPATH/NetBSD-domU/src/BUILDING for details about
# all the nice options
echo "==> Running src/"
cd $BUILDPATH/NetBSD-domU/src
sh -m $MARCH -O ../obj -T ../tools -X ../xsrc/ -R ../release -j2 -U \
    -u -r tools kernel=XEN3_DOMU_NIELS release releasekernel=XEN3_DOMU_NIELS \
    iso-image || exit $?
# show all generated kernels
echo "==> Listing generated kernels..."
cd $BUILDPATH/NetBSD-domU/release/$MARCH/binary/kernel/
pwd && ls -alh
# show all generated sets
echo "==> Listing generated insatll sets..."
cd $BUILDPATH/NetBSD-domU/release/$MARCH/binary/sets/
pwd && ls -alh
# show the install CD images
echo "==> Listing generated CD images (iso)..."
cd $BUILDPATH/NetBSD-domU/release/$MARCH/installation/cdrom
pwd && ls -alh
cd $BUILDPATH/NetBSD-domU/release/iso
pwd && ls -alh
# that's all
echo "==> Congratulations!"
echo "Burn a CD-ROM or boot from ISO and have fun with NetBSD-dom0 and domU!"
echo "Install notes $BUILDPATH/NetBSD-domU/release/$MARCH/INSTALL.\*"

If the script does his job as expected you should see something like:

-r--r--r-- 1 niels users 165M 23. Sep 13:13 i386cd.iso

This is your NetBSD installation ISO image - burn it to a CD or use it within virtualisation (Xen, VMware, Virtualbox etc.) or mount it locally (as a virtual cdrom) by:

mount -o loop /home/'your username'/netbsd/release/iso/i386cd.iso /mnt/cdrom