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

Hi, Mr. Dexter...

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 210: Your questions, part I

2017-09-06

Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines A Reimplementation Of Netbsd Using a Microkernel Minix author Andy Tanenbaum writes in Part 1 of a-reimplementation-of-netbsd-using-a-microkernel Based on the MINIX 3 microkernel, we have constructed a system that to the user looks a great deal like NetBSD. It uses pkgsrc,...

Episode 209: Signals: gotta catch ‘em all

2017-08-30

Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines Trip Report: FreeBSD in China at COPU and LinuxCon This trip report is from Deb Goodkin, the Executive Director of the FreeBSD Foundation. She travelled to China in May 2017 to promote FreeBSD, meet with companies, and participate in discussions around Open...

Episode 208: Faces of Open Source

2017-08-23

Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines LLVM, Clang and compiler-rt support enhancements In the last month I started with upstream of the code for sanitizers: the common layer and ubsan. I worked also on the elimination of unexpected failures in LLVM and Clang. I've managed to...

Episode 207: Bridge over the river Cam

2017-08-16

Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines BSDCam recap The 2017 Cambridge DevSummit took place from 2-4 August 2017. The event took place over three days including a formal dinner at St John's College, and was attended by 55 registered developers and guests. Prior to the start of...