#/bin/sh # # $NetBSD: zfsroot.rc,v 1.2 2020/02/23 05:15:54 roy Exp $ echo "Starting root on ZFS boot strapper" # Abort on any error set -e # Configurable - define the ZFS root pool and ROOT. # XXX Can these be set in boot.cfg? # Assumption - the root pool is set to legacy mount. rpool=rpool rroot=ROOT # Assumption - the boot device is named boot. # Could use /dev/dk0, /dev/wd0a, etc instead. # XXX Can be exposed by sysctl kern.boot_device? bootdev="NAME=boot" # Setup some stuff incase things go south and we drop to the shell export HOME=/ export PATH=/sbin:/bin:/usr/sbin:/usr/bin umask 022 # Avoid having the solaris and zfs modules in ramdisk directly. # Means we don't need to update the ramdisk with the kernel modules # or load them from boot.cfg so it's less pain for the user. #bootdev="$(/sbin/sysctl -n kern.boot_device)" modpath="$(/sbin/sysctl -n kern.module.path)" echo "Loading needed kernel modules from $bootdev:$modpath" /sbin/mount -o ro "$bootdev" /mnt for m in solaris zfs; do /sbin/modload "/mnt/$modpath/$m/$m.kmod" done /sbin/umount /mnt # FIXME XXX Sometimes zpool import gets SIGBUS # Ensure that we are in a writable directory to try and capture a coredump # Not that we actually get a coredump .... cd /tmp echo "Importing $rpool" /sbin/zpool import -f -N "$rpool" echo "Mounting $rpool/$rroot to /altroot" /sbin/mount -t zfs "$rpool/$rroot" /altroot; # This ensures that rc.d/mountall mounts all ZFS mounts set to automount. if [ ! -e /altroot/etc/zfs/zpool.cache ]; then echo >/altroot/etc/zfs/zpool.cache fi echo "Pivoting to /altroot, welcome to root on ZFS" /sbin/sysctl -w init.root=/altroot