Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
ee62c17
Start of a hostid alignment helper
zdykstra Feb 21, 2021
4d1f43a
Fix read-only errors
zdykstra Feb 21, 2021
8002c0a
Only operate on a single BE at a time
zdykstra Feb 21, 2021
cfca80e
Rewrite org.zfsbootmenu:commandline
zdykstra Feb 21, 2021
abaad18
Silence shellcheck error
zdykstra Feb 21, 2021
99aaa67
Only write temporary commandline if needed
zdykstra Feb 21, 2021
5ebec9c
/etc/hostid is read on demand
zdykstra Feb 21, 2021
6e00c2c
Add match_hostid chameleon function
zdykstra Feb 21, 2021
7d50d65
prefer pool set on kcl
zdykstra Feb 21, 2021
baa858d
Fail to shell if we changing our hostid fails
zdykstra Feb 21, 2021
96285eb
Return imported pool, throw error
zdykstra Feb 21, 2021
1323da8
Support busybox grep
zdykstra Feb 21, 2021
5facb64
Prohibit r/w on matched hostid pool imports
zdykstra Feb 21, 2021
0e47704
Huge hack to rewrite spl_hostid on KCL of bootfs
zdykstra Feb 21, 2021
84c4f61
Integrate kcl supressor, import_policy with force_import, automatic s…
zdykstra Feb 22, 2021
3f76096
document match_hostid, allow r/w ops on pool imported via matched hostid
zdykstra Feb 22, 2021
ad185b5
Check for empty hostid when scraping a pool import
zdykstra Feb 22, 2021
8b0cf23
Fix whitespacing
zdykstra Feb 22, 2021
73b678d
Fix whitespacing
zdykstra Feb 22, 2021
6c0c547
Attempt to import everything again after cloning a discovered hostid
zdykstra Feb 22, 2021
3f6cde1
dracut log functions use the daemon facility
zdykstra Feb 22, 2021
5efdeb5
Rearrange import loop
ahesford Feb 22, 2021
c862e84
Always import readonly and disable mounts when scrping hostid
ahesford Feb 22, 2021
7d7408b
Make sure $spl_hostid and /etc/hostid match on startup
zdykstra Feb 22, 2021
df17d75
Default to legacy import behavior, suppress spl_hostid, rewrite spl.s…
zdykstra Feb 23, 2021
adf20f7
Purge this branches namesake
zdykstra Feb 23, 2021
b9cfb72
Fix typo in log message
ahesford Feb 23, 2021
e63bcd8
Fall back to matched hostid in kcl rewrite when spl_hostid is not in …
ahesford Feb 23, 2021
3006bc7
Rename import_policy=legacy to strict
zdykstra Feb 23, 2021
c4e996b
Try harder to get the right hostid when forcing the KCL
ahesford Feb 23, 2021
347d372
Improve logging with get_spl_hostid
ahesford Feb 23, 2021
8fb2860
Make hostid writes aware of endianness
ahesford Feb 24, 2021
cbc0bc3
Move hostid writes to zfsbootmenu-countdown where zfsbootmenu-lib is …
ahesford Feb 24, 2021
2c309ef
Determine LE/BE at creation time, load at startup
zdykstra Feb 24, 2021
187c64b
Make every attempt to import boot_pool first, then anything else we can
zdykstra Feb 24, 2021
e69fead
Make every attempt to import boot_pool first, then anything else we can
zdykstra Feb 25, 2021
ba4b564
WIP: import loop restructure
ahesford Feb 25, 2021
aabd349
Fix check_for_pools, shellcheck
zdykstra Feb 25, 2021
446ad84
Add zbm.prefer=<pool> shorthand
zdykstra Feb 25, 2021
b6601e6
Fall back to writing spl_hostid when spl.spl_hostid=0 would be used
ahesford Feb 25, 2021
d95b264
First pass at updating zfsbootmenu documentation
zdykstra Feb 25, 2021
07b8fcb
Second pass at zfsbootmenu.7.pod
ahesford Feb 25, 2021
2f3ad9d
Add warning flag, set min log level to warn, warn on hostid matched i…
zdykstra Feb 25, 2021
2711843
Pass 3 on zfsbootmenu.7.pod
ahesford Feb 25, 2021
fbc1e91
Move to a new line to clarify the scope of 'this option'
zdykstra Feb 25, 2021
c66e2ee
Change log hotkey text to be more generic
zdykstra Feb 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion 90zfsbootmenu/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ install() {
"ps"
"env"
"chmod"
"od"
)

for _exec in "${essential_execs[@]}"; do
Expand Down Expand Up @@ -202,6 +203,20 @@ install() {
type mark_hostonly >/dev/null 2>&1 && mark_hostonly /etc/zfs/vdev_id.conf
fi

# Determine platform endianness, defaulting to le
ival="$( echo -n 3 | od -tx2 -N2 -An | tr -d '[:space:]' )"
if [ "x${ival}" = "x3300" ]; then
endian="be"
else
if [ "x${ival}" != "x0033" ]; then
warn "unable to determine platform endianness; assuming little-endian"
fi
endian="le"
fi

# shellcheck disable=SC2154
echo -n "${endian}" > "${initdir}/etc/byte-order"

# Try to synchronize hostid between host and ZFSBootMenu
#
# DEPRECATION NOTICE: on musl systems, zfs < 2.0 produced a bad hostid in
Expand All @@ -222,7 +237,11 @@ install() {
if [ -z "${NEWZFS}" ]; then
# In zfs < 2.0, zgenhostid does not provide necessary behavior
# shellcheck disable=SC2154
echo -ne "\\x${HOSTID:6:2}\\x${HOSTID:4:2}\\x${HOSTID:2:2}\\x${HOSTID:0:2}" > "${initdir}/etc/hostid"
if [ "${endian}" = "be" ] ; then
echo -ne "\\x${HOSTID:0:2}\\x${HOSTID:2:2}\\x${HOSTID:4:2}\\x${HOSTID:6:2}" > "${initdir}/etc/hostid"
else
echo -ne "\\x${HOSTID:6:2}\\x${HOSTID:4:2}\\x${HOSTID:2:2}\\x${HOSTID:0:2}" > "${initdir}/etc/hostid"
fi
elif [ "${HOSTID}" != "00000000" ]; then
# In zfs >= 2.0, zgenhostid writes the output, but only with nonzero hostid
# shellcheck disable=SC2154
Expand Down
105 changes: 72 additions & 33 deletions 90zfsbootmenu/zfsbootmenu-countdown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,15 @@ fi

mkdir -p "${BASE}"

# Attempt to import all pools read-only
read_write='' all_pools=yes import_pool

# Make sure at least one pool can be imported; if not,
# drop to an emergency shell to allow the user to attempt recovery
import_success=0
while true; do
while IFS=$'\t' read -r _pool _health; do
[ -n "${_pool}" ] || continue

import_success=1
if [ "${_health}" != "ONLINE" ]; then
echo "${_pool}" >> "${BASE}/degraded"
fi
done <<<"$( zpool list -H -o name,health )"

if [ "${import_success}" -ne 1 ]; then
emergency_shell "unable to successfully import a pool"
else
zdebug "$(
echo "zpool list" ; \
zpool list
)"
zdebug "$(
echo "zfs list -o name,mountpoint,encroot,keystatus,keylocation,org.zfsbootmenu:keysource" ;\
zfs list -o name,mountpoint,encroot,keystatus,keylocation,org.zfsbootmenu:keysource
)"
break
fi
done
# Write out a default or overridden hostid
if [ -n "${spl_hostid}" ] ; then
zinfo "ZFSBootMenu: writing /etc/hostid from command line: ${spl_hostid}"
write_hostid "${spl_hostid}"
elif [ ! -e /etc/hostid ]; then
zinfo "ZFSBootMenu: no hostid found on kernel command line or /etc/hostid"
zinfo "ZFSBootMenu: defaulting hostid to 00000000"
write_hostid 0
fi

# Prefer a specific pool when checking for a bootfs value
# shellcheck disable=SC2154
Expand All @@ -52,11 +31,71 @@ else
boot_pool="${root}"
fi

# Make sure the preferred pool was imported
if [ -n "${boot_pool}" ] && ! zpool list -H -o name "${boot_pool}" >/dev/null 2>&1; then
emergency_shell "\nCannot import requested pool '${boot_pool}'\nType 'exit' to try booting anyway"
# Do a dedicated pass for the preferred pool if one was provided
if [ -n "${boot_pool}" ]; then
first_pass=0
else
first_pass=1
fi

while true; do
if [ "${first_pass}" -eq 0 ]; then
# Try the preferred pool, exactly once
zdebug "attempting to import preferred pool ${boot_pool}"
try_pool="${boot_pool}"
else
try_pool=""
fi

first_pass=1

read_write='' import_pool "${try_pool}"

# shellcheck disable=SC2154
if check_for_pools; then
if [ -n "${try_pool}" ]; then
# If a single pool was requested and imported, try again for the others
continue
else
# Otherwise, all possible pools were imported, nothing more to try
break
fi
elif [ "${import_policy}" == "hostid" ] && poolmatch="$( match_hostid "${try_pool}" )"; then
zdebug "match_hostid returned: ${poolmatch}"

spl_hostid="${poolmatch##*;}"

export spl_hostid

# Store the hostid to use for for KCL overrides
echo -n "$spl_hostid" > "${BASE}/spl_hostid"

# Retry the cycle with a matched hostid
continue
fi

# Allow the user to attempt recovery
emergency_shell "unable to successfully import a pool"
done

# restrict read-write access to any unhealthy pools
while IFS=$'\t' read -r _pool _health; do
if [ "${_health}" != "ONLINE" ]; then
echo "${_pool}" >> "${BASE}/degraded"
zerror "prohibiting read/write operations on ${_pool}"
fi
done <<<"$( zpool list -H -o name,health )"

zdebug "$(
echo "zpool list" ; \
zpool list
)"

zdebug "$(
echo "zfs list -o name,mountpoint,encroot,keystatus,keylocation,org.zfsbootmenu:keysource" ;\
zfs list -o name,mountpoint,encroot,keystatus,keylocation,org.zfsbootmenu:keysource
)"

unsupported=0
while IFS=$'\t' read -r _pool _property; do
if [[ "${_property}" =~ "unsupported@" ]]; then
Expand Down
4 changes: 3 additions & 1 deletion 90zfsbootmenu/zfsbootmenu-exec.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/bin/bash
# vim: softtabstop=2 shiftwidth=2 expandtab

export endian
export spl_hostid
export force_import
export import_policy
export menu_timeout
export loglevel
export root
export zbm_sort
export zbm_set_hostid

# Disable all kernel messages to the console
echo 0 > /proc/sys/kernel/printk
Expand Down
Loading