2 # shellcheck disable=SC2016,SC1004,SC2154
4 grep -wq debug
/proc
/cmdline
&& debug
=1
5 [ -n "$debug" ] && echo "zfs-generator: starting" >> /dev
/kmsg
8 [ -n "$GENERATOR_DIR" ] ||
{
9 echo "zfs-generator: no generator directory specified, exiting" >> /dev
/kmsg
13 # shellcheck source=zfs-lib.sh.in
14 .
/lib
/dracut-zfs-lib.sh
15 decode_root_args ||
exit 0
17 [ -z "${rootflags}" ] && rootflags
=$
(getarg rootflags
=)
18 case ",${rootflags}," in
20 ,,) rootflags
=zfsutil
;;
21 *) rootflags
="zfsutil,${rootflags}" ;;
24 [ -n "$debug" ] && echo "zfs-generator: writing extension for sysroot.mount to $GENERATOR_DIR/sysroot.mount.d/zfs-enhancement.conf" >> /dev
/kmsg
27 mkdir
-p "$GENERATOR_DIR"/sysroot.mount.d
"$GENERATOR_DIR"/initrd-root-fs.target.requires
"$GENERATOR_DIR"/dracut-pre-mount.service.d
30 echo "Before=initrd-root-fs.target"
31 echo "After=zfs-import.target"
34 if [ "${root}" = "zfs:AUTO" ]; then
35 echo "PassEnvironment=BOOTFS"
41 echo "Options=${rootflags}"
42 } > "$GENERATOR_DIR"/sysroot.mount.d
/zfs-enhancement.conf
43 ln -fs ..
/sysroot.mount
"$GENERATOR_DIR"/initrd-root-fs.target.requires
/sysroot.mount
46 if [ "${root}" = "zfs:AUTO" ]; then
49 echo "Before=initrd-root-fs.target"
50 echo "After=sysroot.mount"
51 echo "DefaultDependencies=no"
55 echo "PassEnvironment=BOOTFS"
56 echo "ExecStart=/bin/sh -c '" ' \
57 . /lib/dracut-zfs-lib.sh; \
58 _zfs_nonroot_necessities_cb() { \
59 zfs mount | grep -m1 -q "^$1 " && return 0; \
60 echo "Mounting $1 on /sysroot$2"; \
61 mount -o zfsutil -t zfs "$1" "/sysroot$2"; \
63 for_relevant_root_children "${BOOTFS}" _zfs_nonroot_necessities_cb;' \
65 } > "$GENERATOR_DIR"/zfs-nonroot-necessities.service
66 ln -fs ..
/zfs-nonroot-necessities.service
"$GENERATOR_DIR"/initrd-root-fs.target.requires
/zfs-nonroot-necessities.service
68 # We can solve this statically at generation time, so do!
72 unit
="$(systemd-escape --suffix=mount -p "/sysroot
${mpnt}")"
76 echo "Before=initrd-root-fs.target"
77 echo "After=sysroot.mount"
80 echo "Where=/sysroot${mpnt}"
83 echo "Options=zfsutil"
84 } > "$GENERATOR_DIR/${unit}"
85 ln -fs ..
/"${unit}" "$GENERATOR_DIR"/initrd-root-fs.target.requires
/"${unit}"
88 for_relevant_root_children
"${root}" _zfs_generator_cb
94 echo "After=zfs-import.target"
95 } > "$GENERATOR_DIR"/dracut-pre-mount.service.d
/zfs-enhancement.conf
97 [ -n "$debug" ] && echo "zfs-generator: finished" >> /dev
/kmsg