dracut: use /bin/sh instead of bash as the intepreter
Despite that dracut has a hard dependency on bash,
its modules doesn't, dracut only has a hard dependency on bash for
module-setup (on a fully usable machine). Inside initramfs, dracut
allows users choose from a list of handful other shells, e.g. bash,
busybox, dash, mkfsh.
In fact, my local machine's initramfs is being built with dash,
and it's functional for a very long time.
Before 64025fa3a (Silence 'make checkbashisms', 2020-08-20), we also
allows our users to have that right, too.
Let's fix the problem 'make checkbashisms' reported and allows our users
to have that right, again.
For 'plymouth' case, let's simply run the command inside the if instead
of checking for the existence of command before running it, because the
status is also failture if plymouth is unavailable.
While we're at it, let's remove an unnecessary fork for grep in
zfs-generator.sh.in and its following complicated 'if elif fi' with
a simple 'case ... esac'.
To support this change, also exclude 90zfs from "make checkbashisms"
because the current CI infrastructure ships an old version of
"checkbashisms", which complains about "command -v", while the current
latest "checkbashisms" thinks it's fine. In the near future, we can
revert that change to "Makefile.am" when CI infrastructure is updated.
Reviewed-by: Gabriel A. Devenyi <gdevenyi@gmail.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com>
Closes #11244
2020-11-28 22:02:08 +03:00
|
|
|
#!/bin/sh
|
Trim excess shellcheck annotations. Widen to all non-Korn scripts
Before, make shellcheck checked
scripts/{commitcheck,make_gitrev,man-dates,paxcheck,zfs-helpers,zfs,
zfs-tests,zimport,zloop}.sh
cmd/zed/zed.d/{{all-debug,all-syslog,data-notify,generic-notify,
resilver_finish-start-scrub,scrub_finish-notify,
statechange-led,statechange-notify,trim_finish-notify,
zed-functions}.sh,history_event-zfs-list-cacher.sh.in}
cmd/zpool/zpool.d/{dm-deps,iostat,lsblk,media,ses,smart,upath}
now it also checks
contrib/dracut/{02zfsexpandknowledge/module-setup,
90zfs/{export-zfs,parse-zfs,zfs-needshutdown,
zfs-load-key,zfs-lib,module-setup,
mount-zfs,zfs-generator}}.sh.in
cmd/zed/zed.d/{pool_import-led,vdev_attach-led,
resilver_finish-notify,vdev_clear-led}.sh
contrib/initramfs/{zfsunlock,hooks/zfs.in,scripts/local-top/zfs}
tests/zfs-tests/tests/perf/scripts/prefetch_io.sh
scripts/common.sh.in
contrib/bpftrace/zfs-trace.sh
autogen.sh
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #12042
2021-05-14 15:02:11 +03:00
|
|
|
# shellcheck disable=SC2154
|
2018-01-18 21:20:34 +03:00
|
|
|
|
2018-02-08 05:31:54 +03:00
|
|
|
# only run this on systemd systems, we handle the decrypt in mount-zfs.sh in the mount hook otherwise
|
2021-01-21 23:59:24 +03:00
|
|
|
[ -e /bin/systemctl ] || [ -e /usr/bin/systemctl ] || return 0
|
2018-02-08 05:31:54 +03:00
|
|
|
|
2022-04-04 23:45:58 +03:00
|
|
|
# shellcheck source=zfs-lib.sh.in
|
|
|
|
. /lib/dracut-zfs-lib.sh
|
2018-01-18 21:20:34 +03:00
|
|
|
|
2022-04-04 23:45:58 +03:00
|
|
|
decode_root_args || return 0
|
2018-01-18 21:20:34 +03:00
|
|
|
|
|
|
|
# There is a race between the zpool import and the pre-mount hooks, so we wait for a pool to be imported
|
2022-04-04 23:45:58 +03:00
|
|
|
while ! systemctl is-active --quiet zfs-import.target; do
|
|
|
|
systemctl is-failed --quiet zfs-import-cache.service zfs-import-scan.service && return 1
|
2018-01-18 21:20:34 +03:00
|
|
|
sleep 0.1s
|
|
|
|
done
|
|
|
|
|
2022-04-04 23:45:58 +03:00
|
|
|
BOOTFS="$root"
|
|
|
|
if [ "$BOOTFS" = "zfs:AUTO" ]; then
|
|
|
|
BOOTFS="$(zpool get -Ho value bootfs | grep -m1 -vFx -)"
|
2018-01-18 21:20:34 +03:00
|
|
|
fi
|
|
|
|
|
2022-04-04 23:52:43 +03:00
|
|
|
[ "$(zpool get -Ho value feature@encryption "${BOOTFS%%/*}")" = 'active' ] || return 0
|
|
|
|
|
2022-04-05 00:39:18 +03:00
|
|
|
_load_key_cb() {
|
|
|
|
dataset="$1"
|
|
|
|
|
|
|
|
ENCRYPTIONROOT="$(zfs get -Ho value encryptionroot "${dataset}")"
|
|
|
|
[ "${ENCRYPTIONROOT}" = "-" ] && return 0
|
|
|
|
|
|
|
|
[ "$(zfs get -Ho value keystatus "${ENCRYPTIONROOT}")" = "unavailable" ] || return 0
|
|
|
|
|
|
|
|
KEYLOCATION="$(zfs get -Ho value keylocation "${ENCRYPTIONROOT}")"
|
|
|
|
case "${KEYLOCATION%%://*}" in
|
|
|
|
prompt)
|
|
|
|
for _ in 1 2 3; do
|
2023-01-05 23:07:43 +03:00
|
|
|
systemd-ask-password --timeout=0 --no-tty "Encrypted ZFS password for ${dataset}" | zfs load-key "${ENCRYPTIONROOT}" && break
|
2022-04-04 23:52:43 +03:00
|
|
|
done
|
2022-04-05 00:39:18 +03:00
|
|
|
;;
|
|
|
|
http*)
|
|
|
|
systemctl start network-online.target
|
|
|
|
zfs load-key "${ENCRYPTIONROOT}"
|
|
|
|
;;
|
|
|
|
file)
|
|
|
|
KEYFILE="${KEYLOCATION#file://}"
|
|
|
|
[ -r "${KEYFILE}" ] || udevadm settle
|
|
|
|
[ -r "${KEYFILE}" ] || {
|
|
|
|
info "ZFS: Waiting for key ${KEYFILE} for ${ENCRYPTIONROOT}..."
|
|
|
|
for _ in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
|
|
|
|
sleep 0.5s
|
|
|
|
[ -r "${KEYFILE}" ] && break
|
|
|
|
done
|
|
|
|
}
|
|
|
|
[ -r "${KEYFILE}" ] || warn "ZFS: Key ${KEYFILE} for ${ENCRYPTIONROOT} hasn't appeared. Trying anyway."
|
|
|
|
zfs load-key "${ENCRYPTIONROOT}"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
zfs load-key "${ENCRYPTIONROOT}"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
_load_key_cb "$BOOTFS"
|
|
|
|
for_relevant_root_children "$BOOTFS" _load_key_cb
|