2002-05-24 04:06:03 +00:00
|
|
|
#! /bin/sh
|
|
|
|
#
|
2017-11-27 15:37:16 +00:00
|
|
|
# SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
#
|
2012-02-07 14:06:30 +00:00
|
|
|
# Copyright (c) 2002 Gordon Tetlow. All rights reserved.
|
2012-01-31 15:32:05 +00:00
|
|
|
# Copyright (c) 2012 Sandvine Incorporated. All rights reserved.
|
2002-05-24 04:06:03 +00:00
|
|
|
#
|
2012-02-07 14:06:30 +00:00
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
# SUCH DAMAGE.
|
|
|
|
#
|
2002-05-24 04:06:03 +00:00
|
|
|
# $FreeBSD$
|
|
|
|
|
2016-04-10 01:25:12 +00:00
|
|
|
append="NO"
|
2002-05-24 04:06:03 +00:00
|
|
|
delete="NO"
|
2012-01-31 15:32:05 +00:00
|
|
|
kenv=
|
2002-05-24 04:06:03 +00:00
|
|
|
force="NO"
|
|
|
|
nextboot_file="/boot/nextboot.conf"
|
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
|
|
|
zfs=
|
2002-05-24 04:06:03 +00:00
|
|
|
|
2012-01-31 15:32:05 +00:00
|
|
|
add_kenv()
|
|
|
|
{
|
|
|
|
local var value
|
|
|
|
|
|
|
|
var=$1
|
|
|
|
# strip literal quotes if passed in
|
|
|
|
value=${2%\"*}
|
|
|
|
value=${value#*\"}
|
|
|
|
|
|
|
|
if [ -n "${kenv}" ]; then
|
|
|
|
kenv="${kenv}
|
|
|
|
"
|
|
|
|
fi
|
|
|
|
kenv="${kenv}${var}=\"${value}\""
|
|
|
|
}
|
|
|
|
|
2002-05-24 04:06:03 +00:00
|
|
|
display_usage() {
|
2016-04-10 01:25:12 +00:00
|
|
|
cat <<-EOF
|
2016-04-14 18:03:55 +00:00
|
|
|
Usage: nextboot [-af] [-e variable=value] [-k kernel] [-o options]
|
2016-04-10 01:25:12 +00:00
|
|
|
nextboot -D
|
|
|
|
EOF
|
2002-05-24 04:06:03 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 01:25:12 +00:00
|
|
|
while getopts "aDe:fk:o:" argument ; do
|
2006-01-18 04:48:45 +00:00
|
|
|
case "${argument}" in
|
2016-04-10 01:25:12 +00:00
|
|
|
a)
|
|
|
|
append="YES"
|
|
|
|
;;
|
2006-01-18 04:48:45 +00:00
|
|
|
D)
|
2002-05-24 04:06:03 +00:00
|
|
|
delete="YES"
|
|
|
|
;;
|
2012-01-31 15:32:05 +00:00
|
|
|
e)
|
|
|
|
var=${OPTARG%%=*}
|
|
|
|
value=${OPTARG#*=}
|
|
|
|
if [ -z "$var" -o -z "$value" ]; then
|
|
|
|
display_usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
add_kenv "$var" "$value"
|
|
|
|
;;
|
2006-01-18 04:48:45 +00:00
|
|
|
f)
|
2002-05-24 04:06:03 +00:00
|
|
|
force="YES"
|
|
|
|
;;
|
2006-01-18 04:48:45 +00:00
|
|
|
k)
|
|
|
|
kernel="${OPTARG}"
|
2012-01-31 15:32:05 +00:00
|
|
|
add_kenv kernel "$kernel"
|
2002-05-24 04:06:03 +00:00
|
|
|
;;
|
2006-01-18 04:48:45 +00:00
|
|
|
o)
|
2012-01-31 15:32:05 +00:00
|
|
|
add_kenv kernel_options "${OPTARG}"
|
2002-05-24 04:06:03 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
display_usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ ${delete} = "YES" ]; then
|
|
|
|
rm -f ${nextboot_file}
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2012-01-31 15:32:05 +00:00
|
|
|
if [ -z "${kenv}" ]; then
|
2002-05-24 04:06:03 +00:00
|
|
|
display_usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2012-01-31 15:32:05 +00:00
|
|
|
if [ -n "${kernel}" -a ${force} = "NO" -a ! -d /boot/${kernel} ]; then
|
2002-05-24 04:06:03 +00:00
|
|
|
echo "Error: /boot/${kernel} doesn't exist. Use -f to override."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
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
|
|
|
zfs=$(df -Tn "/boot/" 2>/dev/null | while read _fs _type _other ; do
|
2010-09-17 09:50:36 +00:00
|
|
|
[ "zfs" = "${_type}" ] || continue
|
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
|
|
|
echo "${_fs%/ROOT/*}"
|
|
|
|
done)
|
2010-09-17 09:50:36 +00:00
|
|
|
|
2016-04-10 01:25:12 +00:00
|
|
|
set -e
|
|
|
|
|
|
|
|
nextboot_tmp=$(mktemp $(dirname ${nextboot_file})/nextboot.XXXXXX)
|
|
|
|
|
2020-09-23 17:04:27 +00:00
|
|
|
if [ -n "${zfs}" ]; then
|
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
|
|
|
zfsbootcfg -z ${zfs} -n freebsd:nvstore -k nextboot_enable -v YES
|
|
|
|
cat >> ${nextboot_tmp} << EOF
|
|
|
|
$kenv
|
|
|
|
EOF
|
|
|
|
else
|
2016-04-10 01:25:12 +00:00
|
|
|
cat >> ${nextboot_tmp} << EOF
|
2002-05-24 04:06:03 +00:00
|
|
|
nextboot_enable="YES"
|
2012-01-31 15:32:05 +00:00
|
|
|
$kenv
|
2002-05-24 04:06:03 +00:00
|
|
|
EOF
|
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
|
|
|
fi
|
2016-04-10 01:25:12 +00:00
|
|
|
|
|
|
|
fsync ${nextboot_tmp}
|
|
|
|
|
|
|
|
mv ${nextboot_tmp} ${nextboot_file}
|