2 # shellcheck disable=SC2034,SC2154
4 .
/lib
/dracut-zfs-lib.sh
6 decode_root_args ||
return 0
8 GENERATOR_FILE
=/run
/systemd
/generator
/sysroot.mount
9 GENERATOR_EXTENSION
=/run
/systemd
/generator
/sysroot.mount.d
/zfs-enhancement.conf
11 if [ -e "$GENERATOR_FILE" ] && [ -e "$GENERATOR_EXTENSION" ]; then
12 # We're under systemd and dracut-zfs-generator ran to completion.
13 info
"ZFS: Delegating root mount to sysroot.mount at al."
15 # We now prevent Dracut from running this thing again.
16 rm -f "$hookdir"/mount
/*zfs
*
20 info
"ZFS: No sysroot.mount exists or zfs-generator did not extend it."
21 info
"ZFS: Mounting root with the traditional mount-zfs.sh instead."
23 # ask_for_password tries prompt cmd
25 # Wraps around plymouth ask-for-password and adds fallback to tty password ask
26 # if plymouth is not present.
35 # Prompt for password with plymouth, if installed and running.
36 if plymouth
--ping 2>/dev
/null
; then
37 plymouth ask-for-password \
38 --prompt "$prompt" --number-of-tries="$tries" | \
43 while [ "$i" -le "$tries" ]; do
44 printf "%s [%i/%i]:" "$prompt" "$i" "$tries" >&2
45 eval "$cmd" && ret
=0 && break
54 [ "$ret" -ne 0 ] && echo "Wrong password" >&2
59 # Delay until all required block devices are present.
60 modprobe zfs
2>/dev
/null
66 if [ "${root}" = "zfs:AUTO" ] ; then
67 if ! ZFS_DATASET
="$(zpool get -Ho value bootfs | grep -m1 -vFx -)"; then
68 # shellcheck disable=SC2086
69 zpool import
-N -a ${ZPOOL_IMPORT_OPTS}
70 if ! ZFS_DATASET
="$(zpool get -Ho value bootfs | grep -m1 -vFx -)"; then
71 warn
"ZFS: No bootfs attribute found in importable pools."
78 info
"ZFS: Using ${ZFS_DATASET} as root."
81 ZFS_DATASET
="${ZFS_DATASET:-${root}}"
82 ZFS_POOL
="${ZFS_DATASET%%/*}"
85 if ! zpool get
-Ho value name
"${ZFS_POOL}" > /dev
/null
2>&1; then
86 info
"ZFS: Importing pool ${ZFS_POOL}..."
87 # shellcheck disable=SC2086
88 if ! zpool import
-N ${ZPOOL_IMPORT_OPTS} "${ZFS_POOL}"; then
89 warn
"ZFS: Unable to import pool ${ZFS_POOL}"
95 # Load keys if we can or if we need to
96 # TODO: for_relevant_root_children like in zfs-load-key.sh.in
97 if [ "$(zpool get -Ho value feature@encryption "${ZFS_POOL}")" = 'active' ]; then
98 # if the root dataset has encryption enabled
99 ENCRYPTIONROOT
="$(zfs get -Ho value encryptionroot "${ZFS_DATASET}")"
100 if ! [ "${ENCRYPTIONROOT}" = "-" ]; then
101 KEYSTATUS
="$(zfs get -Ho value keystatus "${ENCRYPTIONROOT}")"
102 # if the key needs to be loaded
103 if [ "$KEYSTATUS" = "unavailable" ]; then
107 "Encrypted ZFS password for ${ENCRYPTIONROOT}: " \
108 "zfs load-key '${ENCRYPTIONROOT}'"
113 # Let us tell the initrd to run on shutdown.
114 # We have a shutdown hook to run
115 # because we imported the pool.
116 info
"ZFS: Mounting dataset ${ZFS_DATASET}..."
117 if ! mount_dataset
"${ZFS_DATASET}"; then