#/bin/sh # # $NetBSD: zfsroot.rc,v 1.1 2020/02/22 09:53:47 roy Exp $ # ZFS on Root boot strapper # 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 dk0, 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 echo echo "Starting ZFS on root boot strapper" # 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)" modmnt=/mnt echo "Copying needed kernel modules from $bootdev:$modpath" case "$bootdev" in *=*|"/"*) ;; *) bootdev="/dev/$bootdev";; esac /sbin/mount -o ro "$bootdev" "$modmnt" /sbin/mount -t tmpfs none /stand for m in solaris zfs; do p="$modpath/$m" if [ ! -e "$modmnt/$p/$m.kmod" ]; then echo "$modmnt/$p/$m.kmod not found!" >&2 continue fi echo " $m.kmod" /bin/mkdir -p "$p" /bin/cp "$modmnt/$p/$m.kmod" "$p" done # zpool list will load the needed modules, then we can dispose of the mounts. /sbin/zpool list >/dev/null 2>&1 /sbin/umount /stand /sbin/umount "$modmnt" echo echo "Importing $rpool, mounting and pivoting" # If we can mount the ZFS root partition to /altroot # then chroot to it and start /etc/rc if /sbin/zpool import -f -N "$rpool" && \ /sbin/mount -t zfs "$rpool/$rroot" /altroot; then # This ensures that mountall mounts all ZFS mounts set to automount. if [ ! -e /altroot/etc/zfs/zpool.cache ]; then echo >/altroot/etc/zfs/zpool.cache fi /sbin/sysctl -w init.root=/altroot fi