freebsd-nq/libexec/rc/rc.d/zfsbe
Toomas Soome e307eb94ae loader: zfs should support bootonce an nextboot
bootonce feature is temporary, one time boot, activated by
"bectl activate -t BE", "bectl activate -T BE" will reset the bootonce flag.

By default, the bootonce setting is reset on attempt to boot and the next
boot will use previously active BE.

By setting zfs_bootonce_activate="YES" in rc.conf, the bootonce BE will
be set permanently active.

bootonce dataset name is recorded in boot pool labels, bootenv area.

in case of nextboot, the nextboot_enable boolean variable is recorded in
freebsd:nvstore nvlist, also stored in boot pool label bootenv area.
On boot, the loader will process /boot/nextboot.conf if nextboot_enable
is "YES", and will set nextboot_enable to "NO", preventing /boot/nextboot.conf
processing on next boot.

bootonce and nextboot features are usable in both UEFI and BIOS boot.

To use bootonce/nextboot features, the boot loader needs to be updated on disk;
if loader.efi is stored on ESP, then ESP needs to be updated and
for BIOS boot, stage2 (zfsboot or gptzfsboot) needs to be updated
(gpart or other tools).

At this time, only lua loader is updated.

Sponsored by:	Netflix, Klara Inc.
Differential Revision:	https://reviews.freebsd.org/D25512
2020-09-21 09:01:10 +00:00

90 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: zfsbe
# REQUIRE: mountcritlocal
# Handle boot environment subordinate filesystems
# that may have canmount property set to noauto.
# For these filesystems mountpoint relative to /
# must be the same as their dataset name relative
# to BE root dataset.
. /etc/rc.subr
name="zfsbe"
rcvar="zfs_enable"
start_cmd="be_start"
stop_cmd="be_stop"
required_modules="zfs"
mount_subordinate()
{
local _be
_be=$1
zfs list -rH -o mountpoint,name,canmount,mounted -s mountpoint -t filesystem $_be | \
while read _mp _name _canmount _mounted ; do
# skip filesystems that must not be mounted
[ "$_canmount" = "off" ] && continue
# skip filesystems that are already mounted
[ "$_mounted" = "yes" ] && continue
case "$_mp" in
"none" | "legacy" | "/" | "/$_be")
# do nothing for filesystems with unset or legacy mountpoint
# or those that would be mounted over /
;;
"/$_be/"*)
# filesystems with mountpoint relative to BE
mount -t zfs $_name ${_mp#/$_be}
;;
*)
# filesystems with mountpoint elsewhere
zfs mount $_name
;;
esac
done
}
activate_bootonce()
{
local _dev
local _bootonce
local _be
_dev=$1
_be=${_dev##*/}
_bootonce="`kenv -q zfs-bootonce`"
if [ "$_bootonce" = "zfs:${_dev}:" ] ; then
bectl activate $_be
fi
}
be_start()
{
if [ `$SYSCTL_N security.jail.jailed` -eq 1 ]; then
:
else
mount -p | while read _dev _mp _type _rest; do
[ $_mp = "/" ] || continue
if [ $_type = "zfs" ] ; then
mount_subordinate $_dev
if checkyesno zfs_bootonce_activate; then
activate_bootonce $_dev
fi
fi
break
done
fi
}
be_stop()
{
}
load_rc_config $name
run_rc_command "$1"