]> git.proxmox.com Git - mirror_zfs.git/blob - contrib/dracut/90zfs/module-setup.sh.in
528abe42957ba1759aa012cdd3720f37387cf929
[mirror_zfs.git] / contrib / dracut / 90zfs / module-setup.sh.in
1 #!/usr/bin/env bash
2 # shellcheck disable=SC2154
3
4 check() {
5 # We depend on udev-rules being loaded
6 [ "${1}" = "-d" ] && return 0
7
8 # Verify the zfs tool chain
9 for tool in "zgenhostid" "zpool" "zfs" "mount.zfs"; do
10 command -v "${tool}" >/dev/null || return 1
11 done
12 }
13
14 depends() {
15 echo udev-rules
16 }
17
18 installkernel() {
19 instmods -c zfs
20 }
21
22 install() {
23 inst_rules 90-zfs.rules 69-vdev.rules 60-zvol.rules
24
25 inst_multiple \
26 zgenhostid \
27 zfs \
28 zpool \
29 mount.zfs \
30 hostid \
31 grep \
32 awk \
33 tr \
34 cut \
35 head ||
36 { dfatal "Failed to install essential binaries"; exit 1; }
37
38 # Adapted from https://github.com/zbm-dev/zfsbootmenu
39 if ! ldd "$(command -v zpool)" | grep -qF 'libgcc_s.so'; then
40 # On systems with gcc-config (Gentoo, Funtoo, etc.), use it to find libgcc_s
41 if command -v gcc-config >/dev/null; then
42 inst_simple "/usr/lib/gcc/$(s=$(gcc-config -c); echo "${s%-*}/${s##*-}")/libgcc_s.so.1" ||
43 { dfatal "Unable to install libgcc_s.so"; exit 1; }
44 # Otherwise, use dracut's library installation function to find the right one
45 elif ! inst_libdir_file "libgcc_s.so*"; then
46 # If all else fails, just try looking for some gcc arch directory
47 inst_simple /usr/lib/gcc/*/*/libgcc_s.so* ||
48 { dfatal "Unable to install libgcc_s.so"; exit 1; }
49 fi
50 fi
51
52 inst_hook cmdline 95 "${moddir}/parse-zfs.sh"
53 if [ -n "${systemdutildir}" ]; then
54 inst_script "${moddir}/zfs-generator.sh" "${systemdutildir}/system-generators/dracut-zfs-generator"
55 fi
56 inst_hook pre-mount 90 "${moddir}/zfs-load-key.sh"
57 inst_hook mount 98 "${moddir}/mount-zfs.sh"
58 inst_hook cleanup 99 "${moddir}/zfs-needshutdown.sh"
59 inst_hook shutdown 20 "${moddir}/export-zfs.sh"
60
61 inst_script "${moddir}/zfs-lib.sh" "/lib/dracut-zfs-lib.sh"
62
63 # -H ensures they are marked host-only
64 # -o ensures there is no error upon absence of these files
65 inst_multiple -o -H \
66 "@sysconfdir@/zfs/zpool.cache" \
67 "@sysconfdir@/zfs/vdev_id.conf"
68
69 # Synchronize initramfs and system hostid
70 if ! inst_simple -H @sysconfdir@/hostid; then
71 if HOSTID="$(hostid 2>/dev/null)" && [ "${HOSTID}" != "00000000" ]; then
72 zgenhostid -o "${initdir}@sysconfdir@/hostid" "${HOSTID}"
73 mark_hostonly @sysconfdir@/hostid
74 fi
75 fi
76
77 if dracut_module_included "systemd"; then
78 inst_simple "${systemdsystemunitdir}/zfs-import.target"
79 systemctl -q --root "${initdir}" add-wants initrd.target zfs-import.target
80
81 inst_simple "${moddir}/zfs-env-bootfs.service" "${systemdsystemunitdir}/zfs-env-bootfs.service"
82 systemctl -q --root "${initdir}" add-wants zfs-import.target zfs-env-bootfs.service
83
84 # Add user-provided unit overrides:
85 # - /etc/systemd/system/${_service}
86 # - /etc/systemd/system/${_service}.d/overrides.conf
87 # -H ensures they are marked host-only
88 # -o ensures there is no error upon absence of these files
89 inst_multiple -o -H \
90 "${systemdsystemconfdir}/zfs-import.target" \
91 "${systemdsystemconfdir}/zfs-import.target.d/"*.conf
92
93 for _service in \
94 "zfs-import-scan.service" \
95 "zfs-import-cache.service"; do
96 inst_simple "${systemdsystemunitdir}/${_service}"
97 systemctl -q --root "${initdir}" add-wants zfs-import.target "${_service}"
98
99 # Add user-provided unit overrides:
100 # - /etc/systemd/system/${_service}
101 # - /etc/systemd/system/${_service}.d/overrides.conf
102 # -H ensures they are marked host-only
103 # -o ensures there is no error upon absence of these files
104 inst_multiple -o -H \
105 "${systemdsystemconfdir}/${_service}" \
106 "${systemdsystemconfdir}/${_service}.d/"*.conf
107
108 done
109
110 for _service in \
111 "zfs-snapshot-bootfs.service" \
112 "zfs-rollback-bootfs.service"; do
113 inst_simple "${moddir}/${_service}" "${systemdsystemunitdir}/${_service}"
114 systemctl -q --root "${initdir}" add-wants initrd.target "${_service}"
115
116 # Add user-provided unit overrides:
117 # - /etc/systemd/system/${_service}
118 # - /etc/systemd/system/${_service}.d/overrides.conf
119 # -H ensures they are marked host-only
120 # -o ensures there is no error upon absence of these files
121 inst_multiple -o -H \
122 "${systemdsystemconfdir}/${_service}" \
123 "${systemdsystemconfdir}/${_service}.d/"*.conf
124 done
125
126 inst_simple "${moddir}/import-opts-generator.sh" "${systemdutildir}/system-environment-generators/zfs-import-opts.sh"
127 fi
128 }