Skip to content

Commit 2783e58

Browse files
committed
module-setup.sh: catch installation failures, warn or fail as appropriate
1 parent 5801e00 commit 2783e58

File tree

2 files changed

+90
-49
lines changed

2 files changed

+90
-49
lines changed

90zfsbootmenu/module-setup.sh

Lines changed: 80 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,7 @@
22
# vim: softtabstop=2 shiftwidth=2 expandtab
33

44
check() {
5-
# We depend on udev-rules being loaded
6-
[ "${1}" = "-d" ] && return 0
7-
8-
# Verify the zfs tool chain
9-
for tool in "/usr/bin/zpool" "/usr/bin/zfs" "/usr/bin/mount.zfs" ; do
10-
test -x "$tool" || return 1
11-
done
12-
# Verify grep exists
13-
command -v grep >/dev/null 2>&1 || return 1
14-
5+
# Do not include this module by default; it must be requested
156
return 255
167
}
178

@@ -34,8 +25,7 @@ installkernel() {
3425
"spl"
3526
)
3627

37-
for mod in "${required_modules[@]}"
38-
do
28+
for mod in "${required_modules[@]}"; do
3929
if ! instmods -c "${mod}" ; then
4030
dfatal "Required kernel module '${mod}' is missing, aborting image creation!"
4131
exit 1
@@ -47,59 +37,105 @@ installkernel() {
4737
"zlib_inflate"
4838
)
4939

50-
for mod in "${optional_modules[@]}"
51-
do
40+
for mod in "${optional_modules[@]}"; do
5241
instmods "${mod}"
5342
done
5443
}
5544

5645
install() {
57-
inst_rules /usr/lib/udev/rules.d/90-zfs.rules
58-
inst_rules /usr/lib/udev/rules.d/69-vdev.rules
59-
inst_rules /usr/lib/udev/rules.d/60-zvol.rules
60-
dracut_install hostid
61-
dracut_install /usr/bin/zfs
62-
dracut_install /usr/bin/zpool
46+
local _rule _exec _ret
47+
48+
local udev_rules=(
49+
"/usr/lib/udev/rules.d/90-zfs.rules"
50+
"/usr/lib/udev/rules.d/69-vdev.rules"
51+
"/usr/lib/udev/rules.d/60-zvol.rules"
52+
)
53+
54+
for _rule in "${udev_rules[@]}"; do
55+
if ! inst_rules "${_rule}"; then
56+
dfatal "failed to install udev rule '${_rule}'"
57+
exit 1
58+
fi
59+
done
60+
61+
local essential_execs=(
62+
"/usr/lib/udev/vdev_id"
63+
"/usr/lib/udev/zvol_id"
64+
"zfs"
65+
"zpool"
66+
"hostid"
67+
"mount"
68+
"mount.zfs"
69+
"kexec"
70+
"mkdir"
71+
"tput"
72+
"basename"
73+
"head"
74+
"mktemp"
75+
"sort"
76+
"sed"
77+
"grep"
78+
"tail"
79+
"tr"
80+
"tac"
81+
"blkid"
82+
)
83+
84+
for _exec in "${essential_execs[@]}"; do
85+
if ! dracut_install "${_exec}"; then
86+
dfatal "failed to install essential executable '${_exec}'"
87+
exit 1
88+
fi
89+
done
90+
91+
# sk can be used as a substitute for fzf
92+
if ! dracut_install fzf && ! dracut_install sk; then
93+
dfatal "failed to install fzf or sk"
94+
exit 1
95+
fi
96+
97+
# BE clones will work (silently and less efficiently) without mbuffer
98+
if ! dracut_install mbuffer; then
99+
dwarning "mbuffer not found; ZFSBootMenu cannot show progress during BE clones"
100+
fi
101+
63102
# Workaround for zfsonlinux/zfs#4749 by ensuring libgcc_s.so(.1) is included
103+
_ret=0
64104
if ldd /usr/bin/zpool | grep -qF 'libgcc_s.so'; then
65105
# Dracut will have already tracked and included it
66-
:;
106+
:
67107
elif command -v gcc-config >/dev/null 2>&1; then
68108
# On systems with gcc-config (Gentoo, Funtoo, etc.):
69109
# Use the current profile to resolve the appropriate path
70110
dracut_install "/usr/lib/gcc/$(s=$(gcc-config -c); echo "${s%-*}/${s##*-}")/libgcc_s.so.1"
111+
_ret=$?
71112
elif [[ -n "$(ls /usr/lib/libgcc_s.so* 2>/dev/null)" ]]; then
72113
# Try a simple path first
73114
dracut_install /usr/lib/libgcc_s.so*
115+
_ret=$?
74116
else
75117
# Fallback: Guess the path and include all matches
76118
dracut_install /usr/lib/gcc/*/*/libgcc_s.so*
119+
_ret=$?
120+
fi
121+
122+
if [ ${_ret} -ne 0 ]; then
123+
dfatal "Unable to install libgcc_s.so"
124+
exit 1
77125
fi
78-
dracut_install /usr/bin/mount.zfs
79-
dracut_install /usr/lib/udev/vdev_id
80-
dracut_install /usr/lib/udev/zvol_id
81-
dracut_install tac
82-
dracut_install basename
83-
dracut_install head
84-
dracut_install kexec
85-
dracut_install fzf
86-
dracut_install mktemp
87-
dracut_install sort
88-
dracut_install sed
89-
dracut_install grep
90-
dracut_install tput
91-
dracut_install mount
92-
dracut_install mkdir
93-
dracut_install tail
94-
dracut_install mbuffer
95-
dracut_install tr
96126

127+
_ret=0
97128
# shellcheck disable=SC2154
98-
inst_simple "${moddir}/zfsbootmenu-lib.sh" "/lib/zfsbootmenu-lib.sh"
99-
inst_simple "${moddir}/zfsbootmenu-preview.sh" "/bin/zfsbootmenu-preview.sh"
100-
inst_simple "${moddir}/zfs-chroot" "/bin/zfs-chroot"
101-
inst_hook cmdline 95 "${moddir}/zfsbootmenu-parse-commandline.sh"
102-
inst_hook pre-mount 90 "${moddir}/zfsbootmenu.sh"
129+
inst_simple "${moddir}/zfsbootmenu-lib.sh" "/lib/zfsbootmenu-lib.sh" || _ret=$?
130+
inst_simple "${moddir}/zfsbootmenu-preview.sh" "/bin/zfsbootmenu-preview.sh" || _ret=$?
131+
inst_simple "${moddir}/zfs-chroot" "/bin/zfs-chroot" || _ret=$?
132+
inst_hook cmdline 95 "${moddir}/zfsbootmenu-parse-commandline.sh" || _ret=$?
133+
inst_hook pre-mount 90 "${moddir}/zfsbootmenu.sh" || _ret=$?
134+
135+
if [ ${_ret} -ne 0 ]; then
136+
dfatal "Unable to install core ZFSBootMenu functions"
137+
exit 1
138+
fi
103139

104140
if [ -e /etc/zfs/zpool.cache ]; then
105141
inst /etc/zfs/zpool.cache

90zfsbootmenu/zfsbootmenu-lib.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ kexec_kernel() {
195195
# returns: 0 on success
196196

197197
duplicate_snapshot() {
198-
local selected target
198+
local selected target recv_args
199199

200200
selected="${1}"
201201
target="${2}"
@@ -210,11 +210,14 @@ duplicate_snapshot() {
210210
key_wrapper "${pool}"
211211
CLEAR_SCREEN=1
212212

213-
zfs send "${selected}" | mbuffer \
214-
| zfs recv -u -o canmount=noauto -o mountpoint=/ "${target}"
213+
recv_args=( "-u" "-o" "canmount=noauto" "-o" "mountpoint=/" "${target}" )
215214

216-
# Just forward return code from duplication operation
217-
return $?
215+
if command -v mbuffer >/dev/null 2>&1; then
216+
# Buffer the exchange when possible
217+
zfs send "${selected}" | mbuffer | zfs recv "${recv_args[@]}"
218+
else
219+
zfs send "${selected}" | zfs recv "${recv_args[@]}"
220+
fi
218221
}
219222

220223
# arg1: snapshot name
@@ -597,7 +600,9 @@ has_resume_device() {
597600

598601
set_rw_pool() {
599602
local pool
603+
600604
pool="${1}"
605+
[ -n "${pool}" ] || return 1
601606

602607
# Nothing to do if the pool is not read-only
603608
[ "x$( zpool get -H -o value readonly "${pool}" )" = "xon" ] || return 0

0 commit comments

Comments
 (0)