#!/bin/sh # $Makronix$ # License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree. # # kernel-install.sh -- put a built kernel where the running system boots from # # usage: tools/kernel-install.sh # # `make install' (installworld) installs the sets and no kernel. This is the # kernel half of it, the way src/BUILDING and mxupgrade(8) do it: the old # kernel stays as /netbsd.old, and on an encrypted installation (/cgdboot in # fstab) the boot loader starts the kernel from that small partition, so the # same copy goes there with netbsd.old kept (mxupgrade.sh does the same # after sysupgrade). The system is not restarted. # # POSIX sh. set -eu k=${1:?usage: kernel-install.sh } CGDBOOT=${MXUPGRADE_CGDBOOT:-/cgdboot} [ -f "$k" ] || { echo "kernel-install: $k is not a file" >&2; exit 1; } [ "$(uname -s)" = NetBSD ] || { echo "kernel-install: NetBSD only" >&2; exit 1; } echo "kernel-install: $k -> /netbsd (old one: /netbsd.old)" [ ! -f /netbsd ] || cp -p /netbsd /netbsd.old cp -p "$k" /netbsd.new mv -f /netbsd.new /netbsd if grep -q "[[:space:]]$CGDBOOT[[:space:]]" /etc/fstab 2>/dev/null; then echo "kernel-install: boot partition $CGDBOOT" mount "$CGDBOOT" [ ! -f "$CGDBOOT/netbsd" ] || cp -p "$CGDBOOT/netbsd" "$CGDBOOT/netbsd.old" cp -p /netbsd "$CGDBOOT/netbsd" umount "$CGDBOOT" fi echo "kernel-install: done; reboot to run it (shutdown -r now)"