Skip to content

Commit 65a1a33

Browse files
committed
Loop the emergency shell when initial pool imports fail
Originally, ZFSBootMenu would drop to an emergency shell once if the initial `zpool import -aN` failed to yield a usable pool, then terminate when the user quit the shell. This required the user attempt to make the pool importable and then reboot to allow ZFSBootMenu to try again. With this change, the pool health check and drop to emergency_shell are looped until a usable pool is identified. This allows the user to manually import a pool if possible, then type `exit` to allow ZFSBootMenu to attempt to proceed without an intervening reboot.
1 parent fc4c396 commit 65a1a33

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

90zfsbootmenu/zfsbootmenu.sh

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,25 @@ fi
6060
# Attempt to import all pools read-only
6161
read_write='' all_pools=yes import_pool
6262

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

67-
import_success=1
68-
if [ "${_health}" != "ONLINE" ]; then
69-
echo "${_pool}" >> "${BASE}/degraded"
70-
fi
71-
done <<<"$( zpool list -H -o name,health )"
70+
import_success=1
71+
if [ "${_health}" != "ONLINE" ]; then
72+
echo "${_pool}" >> "${BASE}/degraded"
73+
fi
74+
done <<<"$( zpool list -H -o name,health )"
7275

73-
if [ "${import_success}" -ne 1 ]; then
74-
emergency_shell "unable to successfully import a pool"
75-
exit
76-
fi
76+
if [ "${import_success}" -ne 1 ]; then
77+
emergency_shell "unable to successfully import a pool"
78+
else
79+
break
80+
fi
81+
done
7782

7883
# Prefer a specific pool when checking for a bootfs value
7984
# shellcheck disable=SC2154

0 commit comments

Comments
 (0)