Skip to content

Commit 29a1049

Browse files
ahesfordzdykstra
andcommitted
Deprecate KCL in /etc/default/{zfsbootmenu,grub}
ZBM will complain when reading kernel command-line parameters from /etc/default/{zfsbootmenu,grub} within a BE rather than from the ZFS property org.zfsbootmenu:commandline. By default, the contents of these files will be migrated to a ZFS property on the BE after the warning is shown. This will happen once for each BE that provides a configuration file and no property. The file /etc/default/zfsbootmenu will be removed from the BE if that was the source for the KCL; /etc/default/grub is never removed. By pressing Esc, the user can ignore the deprecation warning without attempting to migrate the KCL configuration. This allows ZBM to operate as before. When the warning is ignored, ZBM will export an environment variable and write to /etc/zfsbootmenu.conf in the initramfs to suppress subsequent warnings until the next reboot. Co-authored-by: Andrew J. Hesford <[email protected]> Co-authored-by: Zach Dykstra <[email protected]>
1 parent c2a1bee commit 29a1049

File tree

2 files changed

+78
-34
lines changed

2 files changed

+78
-34
lines changed

90zfsbootmenu/zfsbootmenu-lib.sh

Lines changed: 76 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,10 +1041,13 @@ find_be_kernels() {
10411041
done
10421042
done
10431043
done
1044-
10451044
done
10461045

1046+
# No further need for the mount
1047+
umount "${mnt}"
1048+
10471049
defaults="$( select_kernel "${fs}" )"
1050+
10481051
# shellcheck disable=SC2034
10491052
IFS=' ' read -r def_fs def_kernel def_initramfs <<<"${defaults}"
10501053

@@ -1053,19 +1056,16 @@ find_be_kernels() {
10531056
# If no default kernel is found, there are no kernels; leave the BE
10541057
# directory in the same state it would be in had no /boot existed
10551058
if [ -z "${def_kernel}" ]; then
1056-
umount "${mnt}"
10571059
zdebug "no default kernel found for ${fs}"
10581060
rm -f "${kernel_records}" "${def_kernel_file}"
10591061
return 1
10601062
fi
1061-
zdebug "default kernel set to ${def_kernel}"
10621063

1064+
zdebug "default kernel set to ${def_kernel}"
10631065
echo "${def_kernel##*/}" > "${def_kernel_file}"
10641066

1065-
# Pre-load cmdline arguments, possibly from files on the mount
1066-
preload_be_cmdline "${fs}" "${mnt}"
1067-
1068-
umount "${mnt}"
1067+
# Pre-load cmdline arguments, possibly from files in the environment
1068+
preload_be_cmdline "${fs}"
10691069
return 0
10701070
}
10711071

@@ -1242,50 +1242,93 @@ read_kcl_prop() {
12421242
}
12431243

12441244
# arg1: ZFS filesystem
1245-
# arg2: path for a mounted filesystem
12461245
# prints: nothing
12471246
# returns: 0 on success
12481247

12491248
preload_be_cmdline() {
1250-
local zfsbe_mnt zfsbe_fs zfsbe_args args_file
1251-
1252-
zfsbe_fs="${1}"
1253-
if [ -z "${zfsbe_fs}" ]; then
1254-
zerror "zfsbe_fs is undefined"
1255-
return 1
1256-
fi
1257-
zdebug "zfsbe_fs set to ${zfsbe_fs}"
1249+
local fs mnt args args_file deprecated need_rw zsout
12581250

1259-
zfsbe_mnt="${2}"
1260-
if [ -z "${zfsbe_mnt}" ]; then
1261-
zerror "zfsbe_mnt is undefined"
1251+
fs="${1}"
1252+
if [ -z "${fs}" ]; then
1253+
zerror "fs is undefined"
12621254
return 1
12631255
fi
1264-
zdebug "zfsbe_mnt set to ${zfsbe_mnt}"
1256+
zdebug "fs set to ${fs}"
12651257

1266-
args_file="${BASE}/${zfsbe_fs}/cmdline"
1258+
args_file="${BASE}/${fs}/cmdline"
12671259

1268-
if zfsbe_args="$( read_kcl_prop "${zfsbe_fs}" )" && [ -n "${zfsbe_args}" ]; then
1260+
if args="$( read_kcl_prop "${fs}" )" && [ -n "${args}" ]; then
12691261
zdebug "using org.zfsbootmenu:commandline"
1270-
echo "${zfsbe_args}" > "${args_file}"
1271-
return
1262+
echo "${args}" > "${args_file}"
1263+
return 0
12721264
fi
12731265

1274-
if [ -n "${zfsbe_mnt}" ] && [ -r "${zfsbe_mnt}/etc/default/zfsbootmenu" ]; then
1275-
zdebug "using ${zfsbe_mnt}/etc/default/zfsbootmenu"
1276-
head -1 "${zfsbe_mnt}/etc/default/zfsbootmenu" | tr -d '\n' > "${args_file}"
1277-
return
1266+
# Mount R/O to check for config files
1267+
if ! mnt="$( mount_zfs "${fs}" )"; then
1268+
zerror "unable to mount ${fs}"
1269+
return 1
12781270
fi
12791271

1280-
if [ -n "${zfsbe_mnt}" ] && [ -r "${zfsbe_mnt}/etc/default/grub" ]; then
1281-
zdebug "using ${zfsbe_mnt}/etc/default/grub"
1272+
if [ -r "${mnt}/etc/default/zfsbootmenu" ]; then
1273+
zdebug "using ${mnt}/etc/default/zfsbootmenu"
1274+
head -1 "${mnt}/etc/default/zfsbootmenu" | tr -d '\n' > "${args_file}"
1275+
deprecated="/etc/default/zfsbootmenu"
1276+
elif [ -r "${mnt}/etc/default/grub" ]; then
1277+
zdebug "using ${mnt}/etc/default/grub"
12821278
echo "$(
12831279
# shellcheck disable=SC1090,SC1091
1284-
. "${zfsbe_mnt}/etc/default/grub" ;
1280+
. "${mnt}/etc/default/grub" ;
12851281
echo "${GRUB_CMDLINE_LINUX_DEFAULT}"
12861282
)" > "${args_file}"
1287-
return
1283+
deprecated="/etc/default/grub"
12881284
fi
1285+
1286+
# Always unmount, pool must be writable to perform migration
1287+
umount "${mnt}" || return 1
1288+
1289+
if [ "${deprecated}" = "/etc/default/zfsbootmenu" ]; then
1290+
# Need an R/W mount to remove deprecated config
1291+
need_rw="yes"
1292+
elif [ -z "${deprecated}" ] || [ -n "${zbm_ignore_kcl_deprecation}" ]; then
1293+
# Nothing is deprecated, so there is nothing to do
1294+
return 0
1295+
fi
1296+
1297+
# It is not an error if user declines automatic migration
1298+
if ! color=green delay=60 prompt="Will attempt migration in %0.2d seconds" \
1299+
timed_prompt "Using KCL from ${deprecated} on ${fs}" \
1300+
"This behavior is DEPRECATED and will be removed soon" "" \
1301+
"KCL should be migrated to an org.zfsbootmenu:commandline property" "" \
1302+
"[RETURN] to migrate" "[ESCAPE] to ignore "; then
1303+
# Suppress repeated messages
1304+
export zbm_ignore_kcl_deprecation=1
1305+
echo 'export zbm_ignore_kcl_deprecation="1"' >> /etc/zfsbootmenu.conf
1306+
return 0
1307+
fi
1308+
1309+
zdebug "migrating ${deprecated} to org.zfsbootmenu:commandline"
1310+
1311+
# Pool must be writable to set property and remove config
1312+
set_rw_pool "${fs%%/*}" || return 1
1313+
CLEAR_SCREEN=1 load_key "${fs}"
1314+
1315+
if ! mnt="$( allow_rw="${need_rw}" mount_zfs "${fs}" )"; then
1316+
zerror "unable to mount ${fs}"
1317+
return 1
1318+
fi
1319+
1320+
read -r args < "${args_file}"
1321+
1322+
if ! zsout="$( zfs set org.zfsbootmenu:commandline="${args}" "${fs}" 2>&1 )"; then
1323+
zerror "Unable to migrate ${deprecated} to org.zfsbootmenu:commandline: ${zsout}"
1324+
elif [ "${deprecated}" = "/etc/default/zfsbootmenu" ] ; then
1325+
zdebug "removing ${deprecated} from ${fs}"
1326+
rm "${mnt}${deprecated}" >/dev/null 2>&1
1327+
else
1328+
zdebug "not removing ${deprecated} from ${fs}"
1329+
fi
1330+
1331+
umount "${mnt}"
12891332
}
12901333

12911334
# arg1: key(and associated value) to suppress from KCL
@@ -1560,7 +1603,7 @@ timed_prompt() {
15601603

15611604
[ $# -gt 0 ] || return
15621605
[ -n "${delay}" ] || delay="30"
1563-
[ -n "${prompt}" ] || prompt="Press [RETURN] or wait %0.2d seconds to continue"
1606+
[ -n "${prompt}" ] || prompt="Press [RETURN] or wait %0.${#delay}d seconds to continue"
15641607

15651608
[ "${delay}" -eq 0 ] && return
15661609

90zfsbootmenu/zfsbootmenu-preinit.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ mkdir -p "${BASE}"
2323

2424
# shellcheck disable=SC2154
2525
cat >> "/etc/zfsbootmenu.conf" <<EOF
26-
# Added by zfsbootmenu-preinit.sh
26+
# BEGIN additions by zfsbootmenu-preinit.sh
2727
export BASE="/zfsbootmenu"
2828
export endian="${endian}"
2929
export spl_hostid="${spl_hostid}"
@@ -37,6 +37,7 @@ export zbm_sort="${zbm_sort}"
3737
export zbm_set_hostid="${zbm_set_hostid}"
3838
export zbm_import_delay="${zbm_import_delay}"
3939
export control_term="${control_term}"
40+
# END additions by zfsbootmenu-preinit.sh
4041
EOF
4142

4243
getcmdline > "${BASE}/zbm.cmdline"

0 commit comments

Comments
 (0)