Skip to main content.

Tracking and cross-compiling -CURRENT (NetBSD)

2014-03-05

Live demo in BSD Now Episode 027 | Originally written by TJ for bsdnow.tv | Last updated: 2014/03/05

NOTE: the author/maintainer of the tutorial(s) is no longer with the show, so the information below may be outdated or incorrect.

In most of the BSDs, there are different branches (or "versions") of the OS that you can use. Often times in addition to the normal releases, there is a development version with the latest features. In addition to the formal releases, NetBSD provides development snapshots and access to the latest code that will be in future versions. Let's get started by checking out the latest source via CVS and setting up a few directories.

# cd /usr
# cvs -d anoncvs@anoncvs.netbsd.org:/cvsroot co -P src
# mkdir -p /usr/obj
# cd src

One of the coolest features of NetBSD is how easy it is to cross-compile (even on another OS)! We'll be using the amazing build.sh script and, for this example, I'm going to build NetBSD on FreeBSD. Adjust "-m amd64" flag to the architecture you want and the "-j 24" flag to the number of CPUs you have. This example is using the GENERIC kernel.

# ./build.sh -m amd64 -O /usr/obj -j 24 tools kernel=GENERIC modules distribution sets

===> build.sh command:    ./build.sh -m amd64 -O /usr/obj -j 24 tools kernel modules distribution sets
===> build.sh started:    Sat Feb 22 17:02:12 EST 2014
===> NetBSD version:      6.99.32
===> MACHINE:             amd64
===> MACHINE_ARCH:        x86_64
===> Build platform:      FreeBSD 9.2-RELEASE amd64
===> HOST_SH:             /bin/sh
===> No $TOOLDIR/bin/nbmake, needs building.
===> Bootstrapping nbmake
checking for sh... /bin/sh
[...]

That's cool and all, but we're assuming you're already on a NetBSD system and want to upgrade your install to -CURRENT. After the build process finishes, you should see something like:

===> Built sets to /usr/obj/releasedir/amd64/binary/sets
===> build.sh ended:      Sat Feb 22 23:37:47 UTC 2014
===> Summary of results:
         build.sh command:    ./build.sh -m amd64 -O /usr/obj -j 24 tools kernel modules distribution sets
         build.sh started:    Sat Feb 22 22:52:16 UTC 2014
         NetBSD version:      6.99.32
         MACHINE:             amd64
         MACHINE_ARCH:        x86_64
         Build platform:      FreeBSD 9.2-RELEASE amd64
         HOST_SH:             /bin/sh
         No $TOOLDIR/bin/nbmake, needs building.
         Bootstrapping nbmake
         MAKECONF file:       /etc/mk.conf (File not found)
         TOOLDIR path:        /usr/obj/tooldir.FreeBSD-9.2-RELEASE-amd64
         DESTDIR path:        /usr/obj/destdir.amd64
         RELEASEDIR path:     /usr/obj/releasedir
         Created /usr/obj/tooldir.FreeBSD-9.2-RELEASE-amd64/bin/nbmake
         Updated makewrapper: /usr/obj/tooldir.FreeBSD-9.2-RELEASE-amd64/bin/nbmake-amd64
         Tools built to /usr/obj/tooldir.FreeBSD-9.2-RELEASE-amd64
         Building kernel:     GENERIC
         Build directory:     /usr/obj/sys/arch/amd64/compile/GENERIC
         Kernels built from GENERIC:
          /usr/obj/sys/arch/amd64/compile/GENERIC/netbsd
         Building kernel modules for NetBSD/amd64 6.99.32
         Successful build of kernel modules for NetBSD/amd64 6.99.32
         Successful make distribution
         Building sets from pre-populated /usr/obj/destdir.amd64
         Built sets to /usr/obj/releasedir/amd64/binary/sets
         build.sh ended:      Sat Feb 22 23:37:47 UTC 2014
===> .

Next we need to install the new kernel.

# cd /usr/obj/sys/compile/arch/amd64/compile/GENERIC
# make install
# shutdown -r now

Once the machine comes back up, we'll install the updated userland.

# cd /usr/src
# ./build.sh -O /usr/obj install=/

There will be some post-install instructions printed after that. Be sure to follow them carefully. One last

# shutdown -r now

and you're done! It's recommended that you subscribe to the current-users mailing list so nothing catches you by surprise. You should also always check /usr/src/UPDATING for special workarounds and important information. See the official documentation for more on how to run -CURRENT.

If you want to create an ISO file of a NetBSD source snapshot, run:

# cd /usr/src
# ./build.sh -m amd64 -O /usr/obj -j 24 release iso-image

make iso-image started at:  Sun Feb 23 00:29:19 UTC 2014
make iso-image finished at: Sun Feb 23 00:29:29 UTC 2014
===> Successful make iso-image
===> build.sh ended:      Sun Feb 23 00:29:29 UTC 2014
===> Summary of results:
         build.sh command:    ./build.sh -m amd64 -O /usr/obj -j 24 release iso-image
         build.sh started:    Sat Feb 22 23:47:25 UTC 2014
         NetBSD version:      6.99.32
         MACHINE:             amd64
         MACHINE_ARCH:        x86_64
         Build platform:      FreeBSD 9.2-RELEASE amd64
         HOST_SH:             /bin/sh
         MAKECONF file:       /etc/mk.conf (File not found)
         TOOLDIR path:        /usr/obj/tooldir.FreeBSD-9.2-RELEASE-amd64
         DESTDIR path:        /usr/obj/destdir.amd64
         RELEASEDIR path:     /usr/obj/releasedir
         Updated makewrapper: /usr/obj/tooldir.FreeBSD-9.2-RELEASE-amd64/bin/nbmake-amd64
         Successful make release
         Successful make iso-image
         build.sh ended:      Sun Feb 23 00:29:29 UTC 2014
===> .

Now we can check what it created:

# file /usr/obj/releasedir/images/*

NetBSD-6.99.32-amd64.iso: # ISO 9660 CD-ROM filesystem data 'NETBSD_69932' (bootable)

You can then burn the new ISO to a CD/DVD and boot from it - talk about portability! The process can even be done without root, just change /usr/obj to somewhere writable by your user and add the "-U" flag for an unprivileged build.

Latest News

New announcement

2017-05-25

We understand that Michael Dexter, Brad Davis, and George Rosamond think there should be more real news....

Two Year Anniversary

2015-08-08

We're quickly approaching our two-year anniversary, which will be on episode 105. To celebrate, we've created a unique t-shirt design, available for purchase until the end of August. Shirts will be shipped out around September 1st. Most of the proceeds will support the show, and specifically allow us to buy...

New discussion segment

2015-01-17

We're thinking about adding a new segment to the show where we discuss a topic that the listeners suggest. It's meant to be informative like a tutorial, but more of a "free discussion" format. If you have any subjects you want us to explore, or even just a good name...

How did you get into BSD?

2014-11-26

We've got a fun idea for the holidays this year: just like we ask during the interviews, we want to hear how all the viewers and listeners first got into BSD. Email us your story, either written or a video version, and we'll read and play some of them for...


Episode 243: Understanding The Scheduler

2018-04-25

This episode was brought to you by Headlines OpenBSD 6.3 released Punctual as ever, OpenBSD 6.3 has been releases with the following features/changes: > Improved HW support, including: > SMP support on OpenBSD/arm64 platforms > vmm/vmd improvements: > IEEE 802.11 wireless stack improvements > Generic network stack improvements > Installer improvements > Routing daemons and other userland network improvements > Security...

Episode 242: Linux Takes The Fastpath

2018-04-18

Direct Download:MP3 AudioVideo This episode was brought to you by Headlines TrueOS STABLE 18.03 Release The TrueOS team is pleased to announce the availability of a new STABLE release of the TrueOS project (version 18.03). This is a special release due to the security issues impacting the computing world since the beginning...

Episode 241: Bowling in the LimeLight

2018-04-11

Direct Download:MP3 AudioVideo This episode was brought to you by Headlines [Other big ZFS improvements you might have missed] 9075 Improve ZFS pool import/load process and corrupted pool recovery > One of the first tasks during the pool load process is to parse a config provided from userland that describes what devices the pool is...

Episode 240: TCP Blackbox Recording

2018-04-04

Direct Download:VideoMP3 Audio This episode was brought to you by Headlines [A number of Upstream ZFS features landed in FreeBSD this week] 9188 increase size of dbuf cache to reduce indirect block decompression With compressed ARC (6950) we use up to 25% of our CPU to decompress indirect blocks, under a workload of...