2 # shellcheck disable=SC2154
5 # We depend on udev-rules being loaded
6 [ "${1}" = "-d" ] && return 0
8 # Verify the zfs tool chain
9 for tool in "@sbindir@/zgenhostid" "@sbindir@/zpool" "@sbindir@/zfs" "@mounthelperdir@/mount.zfs" ; do
10 test -x "$tool" || return 1
35 inst_rules @udevruledir@/90-zfs.rules
36 inst_rules @udevruledir@/69-vdev.rules
37 inst_rules @udevruledir@/60-zvol.rules
40 dracut_install @sbindir@/zgenhostid
41 dracut_install @sbindir@/zfs
42 dracut_install @sbindir@/zpool
43 # Workaround for https://github.com/openzfs/zfs/issues/4749 by
44 # ensuring libgcc_s.so(.1) is included
45 if ldd @sbindir@/zpool | grep -qF 'libgcc_s.so'; then
46 # Dracut will have already tracked and included it
48 elif command -v gcc-config >/dev/null 2>&1; then
49 # On systems with gcc-config (Gentoo, Funtoo, etc.):
50 # Use the current profile to resolve the appropriate path
52 dracut_install "/usr/lib/gcc/${s%-*}/${s##*-}/libgcc_s.so"*
53 elif [ "$(echo /usr/lib/libgcc_s.so*)" != "/usr/lib/libgcc_s.so*" ]; then
54 # Try a simple path first
55 dracut_install /usr/lib/libgcc_s.so*
56 elif [ "$(echo /lib*/libgcc_s.so*)" != "/lib*/libgcc_s.so*" ]; then
58 dracut_install /lib*/libgcc_s.so*
60 # Fallback: Guess the path and include all matches
61 dracut_install /usr/lib*/gcc/**/libgcc_s.so*
63 dracut_install @mounthelperdir@/mount.zfs
64 dracut_install @udevdir@/vdev_id
66 dracut_install basename
69 dracut_install @udevdir@/zvol_id
70 inst_hook cmdline 95 "${moddir}/parse-zfs.sh"
71 if [ -n "$systemdutildir" ] ; then
72 inst_script "${moddir}/zfs-generator.sh" "$systemdutildir"/system-generators/dracut-zfs-generator
74 inst_hook pre-mount 90 "${moddir}/zfs-load-key.sh"
75 inst_hook mount 98 "${moddir}/mount-zfs.sh"
76 inst_hook cleanup 99 "${moddir}/zfs-needshutdown.sh"
77 inst_hook shutdown 20 "${moddir}/export-zfs.sh"
79 inst_simple "${moddir}/zfs-lib.sh" "/lib/dracut-zfs-lib.sh"
80 if [ -e @sysconfdir@/zfs/zpool.cache ]; then
81 inst @sysconfdir@/zfs/zpool.cache
82 type mark_hostonly >/dev/null 2>&1 && mark_hostonly @sysconfdir@/zfs/zpool.cache
85 if [ -e @sysconfdir@/zfs/vdev_id.conf ]; then
86 inst @sysconfdir@/zfs/vdev_id.conf
87 type mark_hostonly >/dev/null 2>&1 && mark_hostonly @sysconfdir@/zfs/vdev_id.conf
90 # Synchronize initramfs and system hostid
91 if [ -f @sysconfdir@/hostid ]; then
92 inst @sysconfdir@/hostid
93 type mark_hostonly >/dev/null 2>&1 && mark_hostonly @sysconfdir@/hostid
94 elif HOSTID="$(hostid 2>/dev/null)" && [ "${HOSTID}" != "00000000" ]; then
95 zgenhostid -o "${initdir}@sysconfdir@/hostid" "${HOSTID}"
96 type mark_hostonly >/dev/null 2>&1 && mark_hostonly @sysconfdir@/hostid
99 if dracut_module_included "systemd"; then
100 mkdir -p "${initdir}/$systemdsystemunitdir/zfs-import.target.wants"
101 for _item in scan cache ; do
102 dracut_install @systemdunitdir@/zfs-import-$_item.service
103 if ! [ -L "${initdir}/$systemdsystemunitdir/zfs-import.target.wants"/zfs-import-$_item.service ]; then
104 ln -s ../zfs-import-$_item.service "${initdir}/$systemdsystemunitdir/zfs-import.target.wants"/zfs-import-$_item.service
105 type mark_hostonly >/dev/null 2>&1 && mark_hostonly @systemdunitdir@/zfs-import-$_item.service
108 inst "${moddir}"/zfs-env-bootfs.service "${systemdsystemunitdir}"/zfs-env-bootfs.service
109 ln -s ../zfs-env-bootfs.service "${initdir}/${systemdsystemunitdir}/zfs-import.target.wants"/zfs-env-bootfs.service
110 type mark_hostonly >/dev/null 2>&1 && mark_hostonly @systemdunitdir@/zfs-env-bootfs.service
111 dracut_install systemd-ask-password
112 dracut_install systemd-tty-ask-password-agent
113 mkdir -p "${initdir}/$systemdsystemunitdir/initrd.target.wants"
114 dracut_install @systemdunitdir@/zfs-import.target
115 if ! [ -L "${initdir}/$systemdsystemunitdir/initrd.target.wants"/zfs-import.target ]; then
116 ln -s ../zfs-import.target "${initdir}/$systemdsystemunitdir/initrd.target.wants"/zfs-import.target
117 type mark_hostonly >/dev/null 2>&1 && mark_hostonly @systemdunitdir@/zfs-import.target
119 for _service in zfs-snapshot-bootfs.service zfs-rollback-bootfs.service ; do
120 inst "${moddir}"/$_service "${systemdsystemunitdir}"/$_service
121 if ! [ -L "${initdir}/$systemdsystemunitdir/initrd.target.wants"/$_service ]; then
122 ln -s ../$_service "${initdir}/$systemdsystemunitdir/initrd.target.wants"/$_service