home | codereading | contact | math | misc | patches | tech


Compiling NetBSD

First, it is necessary to download the NetBSD sources as specified in the Chapter 29 of the NetBSD Guide. It was choosen to use the NetBSD 2.1 sources of the sources CD. Then, it was mounted using the vnconfig(8) command by root.

It was mounted in /mnt/source. The working directory is /disk/build/usr/src (X in /disk/build/usr/xsrc). Following the section 29.3.1 of the NetBSD Guide the files in xset/*.tgz were uncompressed with tar(1) passing the -C flag:

$ cd /mnt/source/sets
$ for file in *.tgz; do
>     echo $
>     tar zxf $file -C /disk/build/
> done

After uncompressing, I cd to the src/ dir (/disk/build/) and chroot the current directory:

$ chroot .

Then, I cd usr/src and run the following script:

$ ./build.sh -u kernel=GENERIC

This script compiles the kernel and the necessary tools that are used in the compiling process.

Note

The -m <architeture> arguments are necessary to specify the architeture we want to build NetBSD for, but in this case, I skip it, and the system was built for the i386 arquiteture.

It is also possible to compile kernel using a customized kernel configuration. So the command above would change and there would be more commands to run. The details are in the the NetBSD Guide, in the session about the creating the kernel configuration file.

The next step is to build the toolchain, userland and the X Window System:

$ ./build.sh -U -x -u build

Now, it is important to export the TOOLDIR, BSDOBJDIR and RELEASEDIR variables as described in the report, to prevent the release building process to compile everything again.

There is the file /usr/src/BUILDING which explains how the BUILDING process work and the main arguments that can be passed to the build.sh script. According to that file, it is necessary to run the following command in order to make a release:

$ ./build.sh -U -u release

It will compile all the kernels needed and will finish with a report.

The release is made. The iso image is ready to be burned

But, unfortunatelly, I forgot to pass the -x flag to the build.sh so it didn't build X. Have to run it again passing the -x flag:

$ ./build.sh -U -u -x release

Now it is necessary to export the variables DESTDIR and RELEASEDIR:

$ export DESTDIR=/usr/src/obj.i386/destdir.i386
$ export RELEASEDIR=/usr/src/obj.i386/releasedir

And cd /usr/src/etc and run the following command:

$ make iso-image

An iso image is recorded. If you want to check its content before burning, mount it using the vnconfig(8) command to configure a device and use this device to mount the iso image with the mount(8) command.

Compiling NetBSD kernel modules

Kernel modules compilation looks not to be documented anywhere beyond mail-lists.

To compile them, just as in this NetBSD current-users mailing list thread:

$ NETBSD_SRC=<your NetBSD src root>
$ TOOLDIR=<tooldir of the NetBSD build system>
$ cd ${NETBSD_SRC}/sys/modules
$ make -m ${NETBSD_SRC}/share/mk/ TOOLDIR=${TOOLDIR}