zfsroot.rc revision 1.2
11.1Sroy#/bin/sh
21.1Sroy#
31.2Sroy#	$NetBSD: zfsroot.rc,v 1.2 2020/02/23 05:15:54 roy Exp $
41.2Sroy
51.2Sroyecho "Starting root on ZFS boot strapper"
61.2Sroy
71.2Sroy# Abort on any error
81.2Sroyset -e
91.1Sroy
101.1Sroy# Configurable - define the ZFS root pool and ROOT.
111.1Sroy# XXX Can these be set in boot.cfg?
121.1Sroy# Assumption - the root pool is set to legacy mount.
131.1Sroyrpool=rpool
141.1Sroyrroot=ROOT
151.1Sroy
161.1Sroy# Assumption - the boot device is named boot.
171.2Sroy# Could use /dev/dk0, /dev/wd0a, etc instead.
181.1Sroy# XXX Can be exposed by sysctl kern.boot_device?
191.1Sroybootdev="NAME=boot"
201.1Sroy
211.1Sroy# Setup some stuff incase things go south and we drop to the shell
221.1Sroyexport HOME=/
231.1Sroyexport PATH=/sbin:/bin:/usr/sbin:/usr/bin
241.1Sroyumask 022
251.1Sroy
261.1Sroy# Avoid having the solaris and zfs modules in ramdisk directly.
271.1Sroy# Means we don't need to update the ramdisk with the kernel modules
281.1Sroy# or load them from boot.cfg so it's less pain for the user.
291.1Sroy#bootdev="$(/sbin/sysctl -n kern.boot_device)"
301.1Sroymodpath="$(/sbin/sysctl -n kern.module.path)"
311.2Sroyecho "Loading needed kernel modules from $bootdev:$modpath"
321.2Sroy/sbin/mount -o ro "$bootdev" /mnt
331.1Sroyfor m in solaris zfs; do
341.2Sroy	/sbin/modload "/mnt/$modpath/$m/$m.kmod"
351.1Sroydone
361.2Sroy/sbin/umount /mnt
371.2Sroy
381.2Sroy# FIXME XXX Sometimes zpool import gets SIGBUS
391.2Sroy# Ensure that we are in a writable directory to try and capture a coredump
401.2Sroy# Not that we actually get a coredump ....
411.2Sroycd /tmp
421.2Sroy
431.2Sroyecho "Importing $rpool"
441.2Sroy/sbin/zpool import -f -N "$rpool"
451.2Sroy
461.2Sroyecho "Mounting $rpool/$rroot to /altroot"
471.2Sroy/sbin/mount -t zfs "$rpool/$rroot" /altroot;
481.2Sroy
491.2Sroy# This ensures that rc.d/mountall mounts all ZFS mounts set to automount.
501.2Sroyif [ ! -e /altroot/etc/zfs/zpool.cache ]; then
511.2Sroy	echo >/altroot/etc/zfs/zpool.cache
521.1Sroyfi
531.2Sroy
541.2Sroyecho "Pivoting to /altroot, welcome to root on ZFS"
551.2Sroy/sbin/sysctl -w init.root=/altroot
56