NetBSD CURRENT - hpaluch/hpaluch.github.io GitHub Wiki

Using NetBSD CURRENT

NetBSD CURRENT is latest development branch of NetBSD.

Warning: Work in Progress...

We will mostly follow: https://www.netbsd.org/docs/current/index.html

Starting with RELEASE

It is standard practice that we will install first official stable release first as starting point. In my case (Aug 17, 2025) it is NetBSD 10.1, from:

I use VM under KVM:

  • 6 CPUs
  • 12GB RAM
  • 60GB disk space, type: VirtIO (=BLK), IDE CD-ROM
  • NIC VirtIO
  • Chipset: i440fx
  • Firmware: BIOS

Installation:

  • I prefer MBR partition table
  • option: "Use entire disk"
  • use "Default sizes for NetBSD"
  • next "Partition sizes OK"
  • use "BIOS console"
  • (d) Custom installation
  • select: Kernel (GENERIC), Kernel modules, Base, Configuration files, Compiler tools (not default!), optionally: Manual pages, Misc, Revoery tools, Text processing tools

After setting password do at least

  • Configure network (if you did not install system from network)
  • Enable sshd
  • Add a user

Install at least following sets (these will be overwritten with SNAPSHOT):

  • base
  • comp

After reboot login to system and check your kernel version:

$ uname -v

NetBSD 10.1 (GENERIC) #0: Mon Dec 16 13:08:11 UTC 2024  [email protected]:/usr/src/sys/arch/amd64/compile/GENERIC

Upgrading to SNAPSHOT

Next we will upgrade kernel (first!, because new userland may not work with old kernel) and then userland (base, comp and in special way etc) to SNAPSHOT.

Now we will follow "Updating an existing system from a current snapshot" from https://www.netbsd.org/docs/current/index.html to upgrade to SNAPSHOT:

WARNING! Safer way to upgrade is to:

  • download SNAPSHOT ISO or IMG
  • boot it
  • select "Upgrade system"
  • it eliminates risk that some critical component (sshd, tmux, shell) will crash in the middle of upgrade. For example PAM modules cause troubles, because they are lazy-loaded on login (and their installed version will be more recent and sometimes incompatible with old running binaries)

Become root and download required files (so we can use path from guide):

su - # we are 

I created script download-snapshot.sh with contents:

!/bin/sh
set -xeuo pipefail
cd $(dirname $0)
ts=20250817020456Z # update to your snapshot date
echo base comp etc kern-GENERIC modules | 
   xargs -n 1 -I % ftp https://nycdn.netbsd.org/pub/NetBSD-daily/HEAD/$ts/amd64/binary/sets/%.tar.xz
exit 0

Execute it with:

chmod +x ./download-snapshot.sh
./download-snapshot.sh

Now we will install kernel following manual (but updated .tgz to .tar.xz). I created script /root/install-kernel.sh with contents:

#!/bin/sh
set -xeuo pipefail
cd $(dirname $0)
tar -zxpf ~/kern-GENERIC.tar.xz
ln -fh /netbsd /netbsd.old
cp netbsd /netbsd.new
ln -fh /netbsd.new /netbsd
exit 0

And execute it:

chmod +x install-kernel.sh

Verify that kernel versions are as expected:

$ file /netbsd*

/netbsd:     ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, for NetBSD 11.99.1, not stripped
/netbsd.new: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, for NetBSD 11.99.1, not stripped
/netbsd.old: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, for NetBSD 10.1, not stripped

Before reboot we have to update bootblocks (sometimes new kernel will simply not boot with old bootlbocks).

WARNING! Instructions below works only with traditional disklabel on MBR partition (BIOS only mode).

First we have to find root-filesystem device on disklabel slice a:

$ df /

Filesystem      1K-blocks         Used        Avail %Cap Mounted on
/dev/ld0a        48795114      1252094     45103266   2% /

So block device is /dev/ld0a. Corresponding char (so called "raw") device is with r prefix: /dev/rld0a:

$ dumpfs /dev/rld0a | sed -n 1,3p

file system: /dev/rld0a
format	FFSv2
endian	little-endian

So we can now use FFSv2 bootlbock (from guide):

tar -C /tmp -xf ~/base.tar.xz ./usr/mdec
cp /tmp/usr/mdec/boot /
installboot -v /dev/rld0a /tmp/usr/mdec/bootxx_ffsv2

  File system:         /dev/rld0a
  Primary bootstrap:   /tmp/usr/mdec/bootxx_ffsv2
  Boot options:        timeout 5, flags 0, speed 9600, ioaddr 0, console pc

Finally we have to unpack modules (in my case under /stand/amd64/11.99.1/modules:

tar -C / -xpf ~/modules.tar.xz
ls -l /stand/amd64/

  total 4
  drwxr-xr-x  3 root  wheel  512 Dec 16  2024 10.1
  drwxr-xr-x  3 root  wheel  512 Aug 17 02:04 11.99.1

Finally we can reboot to new kernel with command reboot

After reboot login and verify that you are really running on new kernel:

$ uname -v

NetBSD 11.99.1 (GENERIC) #0: Sun Aug 17 02:04:56 UTC 2025  [email protected]:/usr/src/sys/arch/amd64/compile/GENERIC

Looks good (version 11.99.1 vs. original 10.1).

Now we have to carefully upgrade basic userland (commands and compilers) to SNAPSHOT.

First overwrite system with new tarballs excluding etc - /etc/ must be handled in special way to avoid overwrite of critical data (users, groups, passwords, fstab,...):

[!WARNING] Right after unpacking base.tar.xz your system will become unstable until all steps (including next reboot will be done). For example PAM (that uses runtime loaded libraries will stop working because old instance of login or sshd is now trying loading latest PAM shared libraries).

It is therefore advised that you have local console access and that you log in as root before updating system below.

Upgrading base and comp:

tar -xpf ~/base.tar.xz
cc --version | sed 1q

  cc (nb3 20231008) 10.5.0

tar -xpf ~/comp.tar.xz
cc --version | sed 1q

  cc (nb1 20250721) 12.5.0

Notice that cc compiler version changed.

Now we have to carefully merge /etc - first removing obsolete binaries:

/usr/sbin/postinstall -s ~/etc.tar.xz check

(lot of messages)

/usr/sbin/postinstall -s ~/etc.tar.xz fix

And finally merging files in /etc:

/usr/sbin/etcupdate -s ~/etc.tar.xz

You have to use

  • d to keep old version
  • i to install (overwrite) file with new version (losing old changes)
  • m try to merge new changes

My strategy is to:

  • on files that I modified use d or m
  • otherwise use i

You should see following messages:

postinstall checks passed: ... long list ..
postinstall checks failed:
*** All done

Now you can again reboot with reboot to ensure that all services are running using latest binaries and libraries.

Upgrading SNAPSHOT to CURRENT

Now we have to checkout latest sources (CURRENT) and build and install system from them. We have to follow: https://www.netbsd.org/docs/guide/en/chap-fetch.html#chap-fetch-cvs:

# Run as NON-privileged user
# setup directories and allow full access to current user:
su
# run as root:
mkdir -p /usr/src /usr/obj /usr/tools
# replace USERNAME with your username
chown USERNAME /usr/src /usr/obj /usr/tools
exit # exit back to regular user

To fetch CVS current sources do this:

# as regular (non-root user)
cd /usr
# first checkout (will take lot of time), maybe try -z2 (?)

# later update (no need to specify -d CVSROOT, because it already exists in `/usr/src/CVS` directory)
cd /usr/src && cvs -z2 update -A -dP

So finally we can start building, following https://www.netbsd.org/docs/guide/en/chap-updating.html

tmux # recommended to avoid build abort on broken connection
# as non-root user:

cd /usr/src
./build -h # to get long help

# 1. building userland
time ./build.sh -O ../obj -T ../tools -j $(getconf NPROCESSORS_ONLN) -U distribution

  (results for 6 cores):
  4025.41 real     17175.58 user      3810.21 sys

It will start building toolchain in /usr/tools using /usr/obj for intermediate build files.

In my case that build took around 1h 10min.

Now we have to build kernel with modules, notice added (-u) to NOT rebuild toolchain (was already build in previous stage):

time ./build.sh -O ../obj -T ../tools -j $(getconf NPROCESSORS_ONLN) -u -U kernel=GENERIC modules

  (results for 6 cores):
  300.03 real      1256.86 user       315.40 sys

WARNING! Before installing kernel we should read /usr/src/UPDATING if there is needed any special action (for example reinstalling new bootblocks as shown in above text).

Now install kernel (from https://www.netbsd.org/docs/guide/en/chap-updating.html):

su -
cd /usr/src
# installing modules to /stand/CPU/VERSION:
./build.sh -O ../obj -T ../tools -U installmodules=/
# backup old kernel
mv /netbsd /netbsd.old
# install new kernel
cp  /usr/obj/sys/arch/amd64/compile/GENERIC/netbsd
file /netbsd

  /netbsd: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, for NetBSD 11.99.1, not stripped

Please note that all development kernels for future NetBSD 11 release has simply version 99.1 (so it is not possible to distinguish SNAPSHSOT for our CURRENT).

Now reboot: with reboot command

After reboot verify that kernel has date of its build and also user@HOST of your computer

uname -v

  NetBSD 11.99.1 (GENERIC) #0: Sun Aug 17 17:38:54 UTC 2025 \
   [email protected]:/usr/obj/sys/arch/amd64/compile/GENERIC

Now we will proceed to install Userland (World):

su -
cd /usr/src
./build.sh -O ../obj -T ../tools -U install=/

Before reboot we should check and fix System configuration + merge /etc - same way as we upgraded to SNAPSHOT:

/usr/sbin/postinstall -s /usr/src check

  postinstall checks failed: motd mtree obsolete
  To fix, run:
      sh /usr/sbin/postinstall -s /usr/src -d / fix motd mtree obsolete

/usr/sbin/postinstall -s /usr/src -d / fix 
# should report empty list of failed:

  postinstall fixes failed: (empty)

Now merge /etc:

/usr/sbin/etcupdate -s /usr/src

Again you have choices:

  • d keep old file intact
  • i overwrite old file with new file (losing old changes)
  • m merge changes

For

  • /etc/mtree* files I use i (overwrite)
  • /etc/master.passwd d (keep old) unless there is new system account
  • /etc/motd - i
  • /etc/rc.conf - d

On Remove /tmp/temproot? answer y

Have small Oops:

...
postinstall checks failed: motd
To fix, run:
    sh /usr/sbin/postinstall -s /usr/src -d / fix motd

(there were errors anyway)

I fixed it manually with:

$ cp /usr/src/etc/motd.current /etc/motd

Now reboot with reboot to ensure that all system is using latest binaries and libraries...

Option: Upgrading using installation media.

  • it is safest option

  • after all above builds (distribution, kernel, modules) you can create installation media and sets with:

    cd /usr/src
    # append (-x) if you you build X11 in previous steps
    time ./build.sh -O ../obj -T ../tools -U -u release
    
      (TODO: use more parallel jobs)
      4898.78 real      3836.82 user      1005.91 sys  
    
  • you can find boot.iso as:

    ../obj/releasedir/amd64/installation/cdrom/boot.iso
    

    Problem: installation sets are not included in ISO (only separate so you need some FTP/HTTP/NFS server to install them).

  • to build ISO/IMG media with sets, run this (from https://www.netbsd.org/docs/guide/en/chap-inst-media.html):

  • Warning! I rather rebuilding everything in home directory to ensure consistent results:

  • as non-privileged user:

  • I created build script build-image.sh with contents:

    #!/bin/sh
    set -xeuo pipefail
    rm -rf ~/obj
    cd /usr/src
    for i in tools release install-image; do
            time ./build.sh -U -u -j $(getconf NPROCESSORS_ONLN) -m amd64 -O ~/obj $i
    done
    exit 0
    
  • and run it.

  • found these images:

    $ cd && find obj/ -name '*.iso' -o -name '*.img'
    
    obj/distrib/amd64/cdroms/bootcd/efiboot.img
    obj/distrib/amd64/cdroms/bootcd/boot.iso
    obj/distrib/amd64/cdroms/bootcd-com/efiboot.img
    obj/distrib/amd64/cdroms/bootcd-com/boot-com.iso
    obj/distrib/amd64/installimage/NetBSD-11.99.1-amd64-install.img
    obj/distrib/amd64/installimage-bios/NetBSD-11.99.1-amd64-bios-install.img
    obj/releasedir/amd64/installation/cdrom/boot-com.iso
    obj/releasedir/amd64/installation/cdrom/boot.iso
    
  • TODO: Sort it out (what image does what).

TODO: Update CURRENT (from existing CURRENT)

TODO: CVS Update

TODO: Clean obj,tools

...

Resources