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=SC2034,SC2154
|
2011-03-18 01:18:13 +03:00
|
|
|
|
2015-02-15 22:28:42 +03:00
|
|
|
. /lib/dracut-zfs-lib.sh
|
2011-03-18 01:18:13 +03:00
|
|
|
|
2022-04-04 23:45:58 +03:00
|
|
|
decode_root_args || return 0
|
2011-07-04 21:25:31 +04:00
|
|
|
|
Use a different technique to detect whether to mount-zfs
The behavior of the Dracut module was very wrong before.
The correct behavior: initramfs should not run `zfs-mount` to completion
if the two generator files exist. If, however, one of them is missing,
it indicates one of three cases:
* The kernel command line did not specify a root ZFS file system, and
another Dracut module is already handling root mount (via systemd).
`mount-zfs` can run, but it will do nothing.
* There is no systemd to run `sysroot.mount` to begin with.
`mount-zfs` must run.
* The root parameter is zfs:AUTO, which cannot be run in sysroot.mount.
`mount-zfs` must run.
In any of these three cases, it is safe to run `zfs-mount` to completion.
`zfs-mount` must also delete itself if it determines it should not run,
or else Dracut will do the insane thing of running it over and over again.
Literally, the definition of insanity, doing the same thing that did not
work before, expecting different results. Doing that may have had a great
result before, when we had a race between devices appearing and pools
being mounted, and `mount-zfs` was tasked with the full responsibility
of importing the needed pool, but nowadays it is wrong behavior and
should be suppressed.
I deduced that self-deletion was the correct thing to do by looking at
other Dracut code, because (as we all are very fully aware of) Dracut
is entirely, ahem, "implementation-defined".
Tested-by: @wphilips
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Manuel Amador (Rudd-O) <rudd-o@rudd-o.com>
Closes #5157
Closes #5204
2016-10-06 20:26:47 +03:00
|
|
|
GENERATOR_FILE=/run/systemd/generator/sysroot.mount
|
|
|
|
GENERATOR_EXTENSION=/run/systemd/generator/sysroot.mount.d/zfs-enhancement.conf
|
|
|
|
|
2022-04-04 23:45:58 +03:00
|
|
|
if [ -e "$GENERATOR_FILE" ] && [ -e "$GENERATOR_EXTENSION" ]; then
|
|
|
|
# We're under systemd and dracut-zfs-generator ran to completion.
|
|
|
|
info "ZFS: Delegating root mount to sysroot.mount at al."
|
|
|
|
|
Use a different technique to detect whether to mount-zfs
The behavior of the Dracut module was very wrong before.
The correct behavior: initramfs should not run `zfs-mount` to completion
if the two generator files exist. If, however, one of them is missing,
it indicates one of three cases:
* The kernel command line did not specify a root ZFS file system, and
another Dracut module is already handling root mount (via systemd).
`mount-zfs` can run, but it will do nothing.
* There is no systemd to run `sysroot.mount` to begin with.
`mount-zfs` must run.
* The root parameter is zfs:AUTO, which cannot be run in sysroot.mount.
`mount-zfs` must run.
In any of these three cases, it is safe to run `zfs-mount` to completion.
`zfs-mount` must also delete itself if it determines it should not run,
or else Dracut will do the insane thing of running it over and over again.
Literally, the definition of insanity, doing the same thing that did not
work before, expecting different results. Doing that may have had a great
result before, when we had a race between devices appearing and pools
being mounted, and `mount-zfs` was tasked with the full responsibility
of importing the needed pool, but nowadays it is wrong behavior and
should be suppressed.
I deduced that self-deletion was the correct thing to do by looking at
other Dracut code, because (as we all are very fully aware of) Dracut
is entirely, ahem, "implementation-defined".
Tested-by: @wphilips
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Manuel Amador (Rudd-O) <rudd-o@rudd-o.com>
Closes #5157
Closes #5204
2016-10-06 20:26:47 +03:00
|
|
|
# We now prevent Dracut from running this thing again.
|
2022-04-04 23:45:58 +03:00
|
|
|
rm -f "$hookdir"/mount/*zfs*
|
Use a different technique to detect whether to mount-zfs
The behavior of the Dracut module was very wrong before.
The correct behavior: initramfs should not run `zfs-mount` to completion
if the two generator files exist. If, however, one of them is missing,
it indicates one of three cases:
* The kernel command line did not specify a root ZFS file system, and
another Dracut module is already handling root mount (via systemd).
`mount-zfs` can run, but it will do nothing.
* There is no systemd to run `sysroot.mount` to begin with.
`mount-zfs` must run.
* The root parameter is zfs:AUTO, which cannot be run in sysroot.mount.
`mount-zfs` must run.
In any of these three cases, it is safe to run `zfs-mount` to completion.
`zfs-mount` must also delete itself if it determines it should not run,
or else Dracut will do the insane thing of running it over and over again.
Literally, the definition of insanity, doing the same thing that did not
work before, expecting different results. Doing that may have had a great
result before, when we had a race between devices appearing and pools
being mounted, and `mount-zfs` was tasked with the full responsibility
of importing the needed pool, but nowadays it is wrong behavior and
should be suppressed.
I deduced that self-deletion was the correct thing to do by looking at
other Dracut code, because (as we all are very fully aware of) Dracut
is entirely, ahem, "implementation-defined".
Tested-by: @wphilips
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Manuel Amador (Rudd-O) <rudd-o@rudd-o.com>
Closes #5157
Closes #5204
2016-10-06 20:26:47 +03:00
|
|
|
return
|
2016-04-24 14:35:44 +03:00
|
|
|
fi
|
2022-04-04 23:45:58 +03:00
|
|
|
|
Use a different technique to detect whether to mount-zfs
The behavior of the Dracut module was very wrong before.
The correct behavior: initramfs should not run `zfs-mount` to completion
if the two generator files exist. If, however, one of them is missing,
it indicates one of three cases:
* The kernel command line did not specify a root ZFS file system, and
another Dracut module is already handling root mount (via systemd).
`mount-zfs` can run, but it will do nothing.
* There is no systemd to run `sysroot.mount` to begin with.
`mount-zfs` must run.
* The root parameter is zfs:AUTO, which cannot be run in sysroot.mount.
`mount-zfs` must run.
In any of these three cases, it is safe to run `zfs-mount` to completion.
`zfs-mount` must also delete itself if it determines it should not run,
or else Dracut will do the insane thing of running it over and over again.
Literally, the definition of insanity, doing the same thing that did not
work before, expecting different results. Doing that may have had a great
result before, when we had a race between devices appearing and pools
being mounted, and `mount-zfs` was tasked with the full responsibility
of importing the needed pool, but nowadays it is wrong behavior and
should be suppressed.
I deduced that self-deletion was the correct thing to do by looking at
other Dracut code, because (as we all are very fully aware of) Dracut
is entirely, ahem, "implementation-defined".
Tested-by: @wphilips
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Manuel Amador (Rudd-O) <rudd-o@rudd-o.com>
Closes #5157
Closes #5204
2016-10-06 20:26:47 +03:00
|
|
|
info "ZFS: No sysroot.mount exists or zfs-generator did not extend it."
|
|
|
|
info "ZFS: Mounting root with the traditional mount-zfs.sh instead."
|
2016-04-24 14:35:44 +03:00
|
|
|
|
2022-04-05 00:24:29 +03:00
|
|
|
# ask_for_password tries prompt cmd
|
|
|
|
#
|
|
|
|
# Wraps around plymouth ask-for-password and adds fallback to tty password ask
|
|
|
|
# if plymouth is not present.
|
|
|
|
ask_for_password() {
|
|
|
|
tries="$1"
|
|
|
|
prompt="$2"
|
|
|
|
cmd="$3"
|
|
|
|
|
|
|
|
{
|
|
|
|
flock -s 9
|
|
|
|
|
|
|
|
# Prompt for password with plymouth, if installed and running.
|
|
|
|
if plymouth --ping 2>/dev/null; then
|
|
|
|
plymouth ask-for-password \
|
|
|
|
--prompt "$prompt" --number-of-tries="$tries" | \
|
|
|
|
eval "$cmd"
|
|
|
|
ret=$?
|
|
|
|
else
|
|
|
|
i=1
|
|
|
|
while [ "$i" -le "$tries" ]; do
|
|
|
|
printf "%s [%i/%i]:" "$prompt" "$i" "$tries" >&2
|
|
|
|
eval "$cmd" && ret=0 && break
|
|
|
|
ret=$?
|
|
|
|
i=$((i+1))
|
|
|
|
printf '\n' >&2
|
|
|
|
done
|
|
|
|
unset i
|
|
|
|
fi
|
|
|
|
} 9>/.console_lock
|
|
|
|
|
|
|
|
[ "$ret" -ne 0 ] && echo "Wrong password" >&2
|
|
|
|
return "$ret"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-23 19:17:56 +03:00
|
|
|
# Delay until all required block devices are present.
|
2018-03-22 20:14:29 +03:00
|
|
|
modprobe zfs 2>/dev/null
|
2015-03-23 19:17:56 +03:00
|
|
|
udevadm settle
|
|
|
|
|
2022-04-04 23:45:58 +03:00
|
|
|
ZFS_DATASET=
|
|
|
|
ZFS_POOL=
|
|
|
|
|
2015-02-15 22:28:42 +03:00
|
|
|
if [ "${root}" = "zfs:AUTO" ] ; then
|
2022-04-05 00:16:59 +03:00
|
|
|
if ! ZFS_DATASET="$(zpool get -Ho value bootfs | grep -m1 -vFx -)"; then
|
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=SC2086
|
2015-02-15 22:28:42 +03:00
|
|
|
zpool import -N -a ${ZPOOL_IMPORT_OPTS}
|
2022-04-05 00:16:59 +03:00
|
|
|
if ! ZFS_DATASET="$(zpool get -Ho value bootfs | grep -m1 -vFx -)"; then
|
2015-02-15 22:28:42 +03:00
|
|
|
warn "ZFS: No bootfs attribute found in importable pools."
|
2022-02-12 16:08:02 +03:00
|
|
|
zpool export -aF
|
2015-02-15 22:28:42 +03:00
|
|
|
|
|
|
|
rootok=0
|
|
|
|
return 1
|
2011-07-25 00:46:16 +04:00
|
|
|
fi
|
2015-02-15 22:28:42 +03:00
|
|
|
fi
|
|
|
|
info "ZFS: Using ${ZFS_DATASET} as root."
|
|
|
|
fi
|
2011-07-04 21:25:31 +04:00
|
|
|
|
2022-04-04 23:45:58 +03:00
|
|
|
ZFS_DATASET="${ZFS_DATASET:-${root}}"
|
2015-02-15 22:28:42 +03:00
|
|
|
ZFS_POOL="${ZFS_DATASET%%/*}"
|
2014-10-06 15:08:33 +04:00
|
|
|
|
2022-04-05 00:24:29 +03:00
|
|
|
|
2022-06-30 01:33:38 +03:00
|
|
|
if ! zpool get -Ho value name "${ZFS_POOL}" > /dev/null 2>&1; then
|
2022-04-05 00:24:29 +03:00
|
|
|
info "ZFS: Importing pool ${ZFS_POOL}..."
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
if ! zpool import -N ${ZPOOL_IMPORT_OPTS} "${ZFS_POOL}"; then
|
|
|
|
warn "ZFS: Unable to import pool ${ZFS_POOL}"
|
|
|
|
rootok=0
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Load keys if we can or if we need to
|
2022-04-05 00:39:18 +03:00
|
|
|
# TODO: for_relevant_root_children like in zfs-load-key.sh.in
|
2022-04-05 00:24:29 +03:00
|
|
|
if [ "$(zpool get -Ho value feature@encryption "${ZFS_POOL}")" = 'active' ]; then
|
|
|
|
# if the root dataset has encryption enabled
|
|
|
|
ENCRYPTIONROOT="$(zfs get -Ho value encryptionroot "${ZFS_DATASET}")"
|
|
|
|
if ! [ "${ENCRYPTIONROOT}" = "-" ]; then
|
|
|
|
KEYSTATUS="$(zfs get -Ho value keystatus "${ENCRYPTIONROOT}")"
|
|
|
|
# if the key needs to be loaded
|
|
|
|
if [ "$KEYSTATUS" = "unavailable" ]; then
|
|
|
|
# decrypt them
|
|
|
|
ask_for_password \
|
|
|
|
5 \
|
|
|
|
"Encrypted ZFS password for ${ENCRYPTIONROOT}: " \
|
|
|
|
"zfs load-key '${ENCRYPTIONROOT}'"
|
2018-01-18 21:20:34 +03:00
|
|
|
fi
|
|
|
|
fi
|
2015-02-15 22:28:42 +03:00
|
|
|
fi
|
|
|
|
|
2022-04-05 00:24:29 +03:00
|
|
|
# Let us tell the initrd to run on shutdown.
|
|
|
|
# We have a shutdown hook to run
|
|
|
|
# because we imported the pool.
|
|
|
|
info "ZFS: Mounting dataset ${ZFS_DATASET}..."
|
|
|
|
if ! mount_dataset "${ZFS_DATASET}"; then
|
|
|
|
rootok=0
|
|
|
|
return 1
|
|
|
|
fi
|