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 19:02:08 +00: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 12:02:11 +00:00
|
|
|
# shellcheck disable=SC2154
|
2018-01-18 18:20:34 +00:00
|
|
|
|
2018-02-08 02:31:54 +00:00
|
|
|
# only run this on systemd systems, we handle the decrypt in mount-zfs.sh in the mount hook otherwise
|
2021-01-21 20:59:24 +00:00
|
|
|
[ -e /bin/systemctl ] || [ -e /usr/bin/systemctl ] || return 0
|
2018-02-08 02:31:54 +00:00
|
|
|
|
2018-01-18 18:20:34 +00:00
|
|
|
# This script only gets executed on systemd systems, see mount-zfs.sh for non-systemd systems
|
|
|
|
|
|
|
|
# import the libs now that we know the pool imported
|
|
|
|
[ -f /lib/dracut-lib.sh ] && dracutlib=/lib/dracut-lib.sh
|
|
|
|
[ -f /usr/lib/dracut/modules.d/99base/dracut-lib.sh ] && dracutlib=/usr/lib/dracut/modules.d/99base/dracut-lib.sh
|
2018-02-22 01:54:54 +00:00
|
|
|
# shellcheck source=./lib-zfs.sh.in
|
2018-01-18 18:20:34 +00:00
|
|
|
. "$dracutlib"
|
|
|
|
|
|
|
|
# load the kernel command line vars
|
2018-02-22 01:54:54 +00:00
|
|
|
[ -z "$root" ] && root="$(getarg root=)"
|
2018-01-18 18:20:34 +00:00
|
|
|
# If root is not ZFS= or zfs: or rootfstype is not zfs then we are not supposed to handle it.
|
2018-02-22 01:54:54 +00:00
|
|
|
[ "${root##zfs:}" = "${root}" ] && [ "${root##ZFS=}" = "${root}" ] && [ "$rootfstype" != "zfs" ] && exit 0
|
2018-01-18 18:20:34 +00:00
|
|
|
|
|
|
|
# There is a race between the zpool import and the pre-mount hooks, so we wait for a pool to be imported
|
2020-11-12 22:06:24 +00:00
|
|
|
while [ "$(zpool list -H)" = "" ]; do
|
|
|
|
systemctl is-failed --quiet zfs-import-cache.service zfs-import-scan.service && exit 1
|
2018-01-18 18:20:34 +00:00
|
|
|
sleep 0.1s
|
|
|
|
done
|
|
|
|
|
|
|
|
# run this after import as zfs-import-cache/scan service is confirmed good
|
2019-10-01 19:54:27 +00:00
|
|
|
# we do not overwrite the ${root} variable, but create a new one, BOOTFS, to hold the dataset
|
2018-02-22 01:54:54 +00:00
|
|
|
if [ "${root}" = "zfs:AUTO" ] ; then
|
2019-10-01 19:54:27 +00:00
|
|
|
BOOTFS="$(zpool list -H -o bootfs | awk '$1 != "-" {print; exit}')"
|
2018-01-18 18:20:34 +00:00
|
|
|
else
|
2019-10-01 19:54:27 +00:00
|
|
|
BOOTFS="${root##zfs:}"
|
2019-10-30 21:38:41 +00:00
|
|
|
BOOTFS="${BOOTFS##ZFS=}"
|
2018-01-18 18:20:34 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# if pool encryption is active and the zfs command understands '-o encryption'
|
2021-05-23 16:04:14 +00:00
|
|
|
if [ "$(zpool list -H -o feature@encryption "${BOOTFS%%/*}")" = 'active' ]; then
|
2018-02-20 18:13:20 +00:00
|
|
|
# if the root dataset has encryption enabled
|
2020-11-12 22:06:24 +00:00
|
|
|
ENCRYPTIONROOT="$(zfs get -H -o value encryptionroot "${BOOTFS}")"
|
2018-02-20 18:13:20 +00:00
|
|
|
if ! [ "${ENCRYPTIONROOT}" = "-" ]; then
|
2019-11-08 22:34:07 +00:00
|
|
|
KEYSTATUS="$(zfs get -H -o value keystatus "${ENCRYPTIONROOT}")"
|
|
|
|
# continue only if the key needs to be loaded
|
|
|
|
[ "$KEYSTATUS" = "unavailable" ] || exit 0
|
2021-05-23 14:39:58 +00:00
|
|
|
|
|
|
|
KEYLOCATION="$(zfs get -H -o value keylocation "${ENCRYPTIONROOT}")"
|
2021-05-23 20:09:35 +00:00
|
|
|
case "${KEYLOCATION%%://*}" in
|
|
|
|
prompt)
|
|
|
|
for _ in 1 2 3; do
|
|
|
|
systemd-ask-password "Encrypted ZFS password for ${BOOTFS}" --no-tty | zfs load-key "${ENCRYPTIONROOT}" && break
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
http*)
|
2021-05-13 04:21:35 +00:00
|
|
|
systemctl start network-online.target
|
2021-05-23 20:09:35 +00:00
|
|
|
zfs load-key "${ENCRYPTIONROOT}"
|
|
|
|
;;
|
|
|
|
file)
|
|
|
|
KEYFILE="${KEYLOCATION#file://}"
|
|
|
|
[ -r "${KEYFILE}" ] || udevadm settle
|
|
|
|
[ -r "${KEYFILE}" ] || {
|
|
|
|
info "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 "Key ${KEYFILE} for ${ENCRYPTIONROOT} hasn't appeared. Trying anyway."
|
|
|
|
zfs load-key "${ENCRYPTIONROOT}"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
zfs load-key "${ENCRYPTIONROOT}"
|
|
|
|
;;
|
|
|
|
esac
|
2018-01-18 18:20:34 +00:00
|
|
|
fi
|
|
|
|
fi
|