Skip to content

Commit 57b5572

Browse files
committed
zfsbootmenu: remove legacy root= usage/design
ZFSBootMenu has danced around `$root` for a few years now, as a holdover from very early design decisions picked up from Dracut. We don't actually _need_ to tie ourselves to that variable - and in fact, a lot of the early startup process can be simplified by no longer trying to stuff so much logic into it. To that end, the legacy but undocumented support for `root=zfsbootmenu:POOL=pool` has been completely removed. `root` on the ZBM KCL is no longer honored. `zbm.prefer` with the documented syntax is now the only way to tell ZFSBootMenu which pool should be preferentially used in the boot process. Accordingly, the global `zbm_prefer_pool` variable is now set when a pool should be preferred, and the accompanying `zbm_require_pool` variable is used to indicate how firm that pool requirement is. One quirk of this is that a pool name of `zfsbootmenu` can now actually be a value that `zbm.prefer` will respect/honor.
1 parent 22032ed commit 57b5572

File tree

4 files changed

+32
-54
lines changed

4 files changed

+32
-54
lines changed

zfsbootmenu/lib/zfsbootmenu-core.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ match_hostid() {
154154
state*)
155155
state="${line#state: }"
156156
# shellcheck disable=SC2154
157-
if [ "${state}" == "ONLINE" ] && [ -n "${pool}" ] && [ "${pool}" != "${root}" ]; then
157+
if [ "${state}" == "ONLINE" ] && [ -n "${pool}" ] && [ "${pool}" != "${zbm_prefer_pool}" ]; then
158158
importable+=("${pool}")
159159
pool=""
160160
fi

zfsbootmenu/libexec/zfsbootmenu-init

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,9 @@ fi
105105
tput clear
106106
/libexec/zfsbootmenu-run-hooks "early-setup.d"
107107

108-
# Prefer a specific pool when checking for a bootfs value
109-
# shellcheck disable=SC2154
110-
if [ "${root}" = "zfsbootmenu" ]; then
111-
boot_pool=
112-
else
113-
boot_pool="${root}"
114-
fi
115-
116108
# If a boot pool is specified, that will be tried first
117-
try_pool="${boot_pool}"
109+
# shellcheck disable=SC2154
110+
try_pool="${zbm_prefer_pool}"
118111
zbm_import_attempt=0
119112

120113
while true; do
@@ -126,7 +119,7 @@ while true; do
126119

127120
# shellcheck disable=SC2154
128121
if check_for_pools; then
129-
if [ "${zbm_require_bpool}" = "only" ]; then
122+
if [ "${zbm_require_pool}" = "only" ]; then
130123
zdebug "only importing ${try_pool}"
131124
break
132125
elif [ -n "${try_pool}" ]; then
@@ -148,15 +141,15 @@ while true; do
148141
echo -n "$spl_hostid" > "${BASE}/spl_hostid"
149142

150143
# If match_hostid succeeds, it has imported *a* pool...
151-
if [ -n "${try_pool}" ] && [ "${zbm_require_bpool}" = "only" ]; then
152-
# In "only" bpool mode, the import was the sole pool desired; nothing more to do
144+
if [ -n "${try_pool}" ] && [ "${zbm_require_pool}" = "only" ]; then
145+
# In "only" pool mode, the import was the sole pool desired; nothing more to do
153146
break
154147
else
155148
# Otherwise, try one more pass to pick up other pools matching this hostid
156149
try_pool=""
157150
continue
158151
fi
159-
elif [ -n "${try_pool}" ] && [ -z "${zbm_require_bpool}" ]; then
152+
elif [ -n "${try_pool}" ] && [ -z "${zbm_require_pool}" ]; then
160153
# If a specific pool was tried unsuccessfully but is not a requirement,
161154
# allow another pass to try any other importable pools
162155
try_pool=""
@@ -186,6 +179,7 @@ while IFS=$'\t' read -r _pool _health; do
186179
zerror "prohibiting read/write operations on ${_pool}"
187180
fi
188181
done <<<"$( zpool list -H -o name,health )"
182+
unset _pool _health
189183

190184
zdebug && zdebug "$( zreport )"
191185

@@ -205,17 +199,19 @@ if [ "${unsupported}" -ne 0 ]; then
205199
timed_prompt -m "$( colorize red 'Unsupported features detected')" \
206200
-m "$( colorize red 'Upgrade ZFS modules in ZFSBootMenu with generate-zbm')"
207201
fi
202+
unset unsupported
208203

209204
# Attempt to find the bootfs property
210205
# shellcheck disable=SC2086
211-
while read -r line; do
212-
if [ "${line}" = "-" ]; then
206+
while read -r _bootfs; do
207+
if [ "${_bootfs}" = "-" ]; then
213208
BOOTFS=
214209
else
215-
BOOTFS="${line}"
210+
BOOTFS="${_bootfs}"
216211
break
217212
fi
218-
done <<<"$( zpool list -H -o bootfs ${boot_pool} )"
213+
done <<<"$( zpool list -H -o bootfs "${zbm_prefer_pool:---}" )"
214+
unset _bootfs
219215

220216
if [ -n "${BOOTFS}" ]; then
221217
export BOOTFS

zfsbootmenu/pre-init/zfsbootmenu-parse-commandline.sh

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,6 @@ else
199199
zinfo "disabling automatic replacement of spl_hostid"
200200
fi
201201

202-
# rewrite root=
203-
if prefer=$( get_zbm_arg zbm.prefer ) ; then
204-
root="zfsbootmenu:POOL=${prefer}"
205-
fi
206-
207202
if kcl_override=$( get_zbm_arg zbm.kcl_override ) ; then
208203
# Remove the leading / trailing quote to "unpack" this argument
209204
kcl_override="${kcl_override#\"}"
@@ -224,46 +219,33 @@ if kcl_override=$( get_zbm_arg zbm.kcl_override ) ; then
224219
zinfo "overriding all BE KCLs with: '$( kcl_assemble < "${BASE}/cmdline" )'"
225220
fi
226221

227-
wait_for_zfs=0
228-
case "${root}" in
229-
zfsbootmenu:POOL=*)
230-
# Prefer a specific pool for bootfs value, root=zfsbootmenu:POOL=zroot
231-
root="${root#zfsbootmenu:POOL=}"
232-
# shellcheck disable=SC2034
233-
rootok=1
234-
wait_for_zfs=1
235-
236-
zinfo "preferring ${root} for bootfs"
237-
;;
238-
*)
239-
root="zfsbootmenu"
240-
# shellcheck disable=SC2034
241-
rootok=1
242-
wait_for_zfs=1
243-
244-
zinfo "enabling menu after udev settles"
245-
;;
246-
esac
222+
zbm_prefer_pool=
223+
if zbm_prefer_pool=$( get_zbm_arg zbm.prefer ) ; then
224+
# shellcheck disable=SC2034
225+
zbm_prefer_pool="${zbm_prefer_pool%%/*}"
226+
zinfo "preferring ${zbm_prefer_pool} for bootfs"
227+
fi
247228

248229
# pool! : this pool must be imported before all others
249230
# pool!!: this pool, and no others, must be imported
250231

251232
# shellcheck disable=SC2034
252-
case "${root}" in
233+
case "${zbm_prefer_pool}" in
253234
*!!)
254-
zbm_require_bpool="only"
255-
root="${root%!!}"
235+
zbm_require_pool="only"
236+
zbm_prefer_pool="${zbm_prefer_pool%!!}"
256237
;;
257238
*!)
258-
zbm_require_bpool="yes"
259-
root="${root%!}"
239+
zbm_require_pool="yes"
240+
zbm_prefer_pool="${zbm_prefer_pool%!}"
260241
;;
261242
*)
262-
zbm_require_bpool=""
243+
zbm_require_pool=""
263244
;;
264245
esac
265246

266247
# Make sure Dracut is happy that we have a root
267-
if [ ${wait_for_zfs} -eq 1 ]; then
268-
ln -s /dev/null /dev/root 2>/dev/null
269-
fi
248+
249+
# shellcheck disable=SC2034
250+
rootok=1
251+
ln -s /dev/null /dev/root 2>/dev/null

zfsbootmenu/pre-init/zfsbootmenu-preinit.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export spl_hostid="${spl_hostid}"
2626
export import_policy="${import_policy}"
2727
export menu_timeout="${menu_timeout}"
2828
export loglevel="${loglevel}"
29-
export root="${root}"
30-
export zbm_require_bpool="${zbm_require_bpool}"
29+
export zbm_prefer_pool="${zbm_prefer_pool}"
30+
export zbm_require_pool="${zbm_require_pool}"
3131
export default_hostid=00bab10c
3232
export zbm_sort="${zbm_sort}"
3333
export zbm_set_hostid="${zbm_set_hostid}"

0 commit comments

Comments
 (0)