Compiling the NetBSD kernel

Heads-up

assuming stable building -current

We want to keep the tools there – no need to rebuild them each time

find sys/arch/amd64/conf/
time ./build.sh -T /root/tools -O /root/obj -j 16 tools
time ./build.sh -T /root/tools -O /root/obj -j 16 kernel=XEN3_DOMU

http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/arch/amd64/conf/XEN3_DOMU http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/arch/amd64/conf/XEN3_DOMU?rev=HEAD

Introduction

Make sure you have enough RAM (at least 2GB I would say, but 8GB is probably preferable), and eventually increase the number of vcpus.

Fetching the source

Fetching a release

cd /usr/
mirror=ftp.ee.netbsd.org
#mirror=ftp.fr.netbsd.org

ftp -a ftp://$mirror/pub/NetBSD/NetBSD-9.0/source/sets/syssrc.tgz
progress -zf syssrc.tgz tar xf -

Fetching current

cd /usr/
export CVSROOT="anoncvs@anoncvs.fr.NetBSD.org:/cvsroot"
export CVS_RSH="ssh"
cvs -q -z9 checkout src

cd /usr/src/
cvs -q -z9 up -dP

Tweak the kernel

kernel=ALTQ
#kernel=INSTALLMULTI
#kernel=GENERICMULTI
#kernel=SMALLPLUS

cd /usr/src/sys/arch/`uname -m`/conf/
cp -pi GENERIC $kernel
#cp -pi XEN3_DOMU $kernel

Take the chance to disable securelevel -1

vi $kernel

#options        INSECURE

Make it Multiboot-compliant

options MULTIBOOT

Enable ALTQ

#sample from netbsd-8
options         ALTQ            # Manipulate network interfaces' output queues
options         ALTQ_BLUE       # Stochastic Fair Blue
options         ALTQ_CBQ        # Class-Based Queueing
options         ALTQ_CDNR       # Diffserv Traffic Conditioner
options         ALTQ_FIFOQ      # First-In First-Out Queue 
options         ALTQ_FLOWVALVE  # RED/flow-valve (red-penalty-box)
options         ALTQ_HFSC       # Hierarchical Fair Service Curve
options         ALTQ_LOCALQ     # Local queueing discipline
options         ALTQ_PRIQ       # Priority Queueing 
options         ALTQ_RED        # Random Early Detection
options         ALTQ_RIO        # RED with IN/OUT
options         ALTQ_WFQ        # Weighted Fair Queueing

And in case this is bare-metal and not a XEN nor serial console

grep WSCOL /usr/src/sys/dev/wscons/wsdisplayvar.h

options         WS_KERNEL_FG=WSCOL_BROWN
#options         WS_KERNEL_FG=WSCOL_RED

Build your kernel

diff -Naur GENERIC $kernel > $kernel.diff

ls -lhF ../compile/$kernel/
rm -rf ../compile/$kernel/

config $kernel
#/usr/tooldir/bin/nbconfig GENERIC_XENHVM

cd ../compile/$kernel/
dmesg | grep -E [v]?cpu
time make -j16 depend >/dev/null && echo DEPEND
#/usr/tooldir/bin/nbmake

#make clean
time make -j16 > /root/$kernel.log && echo BUILT
#/usr/tooldir/bin/nbmake
#238.26s

Bare-metal,

mv /netbsd /netbsd.old
cp /usr/src/sys/arch/`uname -m`/compile/$kernel/netbsd /
shutdown -r now

XEN host,

scp bsdbuild:/usr/src/sys/arch/amd64/compile/ALTQNPF/netbsd netbsd.altqnpf
scp bsdbuild:/usr/src/sys/arch/amd64/compile/GENERICMULTI/netbsd netbsd.genericmulti

XEN guest,

shutdown -p now

and change its settings to point to the new kernel,

kernel = "/data/kernels/netbsd8/altqnpf"

At system startup, watch the console and check,

dmesg | grep ^NetBSD
uname -a

Troubleshooting

make[1]: don't know how to make absvdi2.c. Stop

==> either use config -s or put your sources folder in the default location (/usr/src)

Tweak examples

    #cp -pi INSTALL_SMALL $kernel
    #cat >> $kernel <<-EOF
    #nfe*    at pci? dev ? function ?        # NVIDIA nForce Ethernet
    #EOF

Trash

Enabling NPF,

    pseudo-device   npf                     # NPF packet filter

    options         NPF_EXT_LOG
    options         NPF_EXT_NORMALISE
    options         BPFJIT
    options         SLJIT

References


Nethence | Pub | Lab | Pbraun | SNE Russia