]>
Commit | Line | Data |
---|---|---|
dda702fd | 1 | #!/usr/bin/env bash |
6fc30992 | 2 | # shellcheck disable=SC2154 |
fde4ce99 ZB |
3 | |
4 | check() { | |
1ef5e829 | 5 | # We depend on udev-rules being loaded |
eda3d4e1 | 6 | [ "${1}" = "-d" ] && return 0 |
fde4ce99 | 7 | |
1ef5e829 | 8 | # Verify the zfs tool chain |
5eae5a88 SJ |
9 | for tool in "zgenhostid" "zpool" "zfs" "mount.zfs"; do |
10 | command -v "${tool}" >/dev/null || return 1 | |
d402c18d | 11 | done |
fde4ce99 ZB |
12 | } |
13 | ||
14 | depends() { | |
1ef5e829 | 15 | echo udev-rules |
fde4ce99 ZB |
16 | } |
17 | ||
18 | installkernel() { | |
7f5a01bd | 19 | instmods -c zfs |
fde4ce99 ZB |
20 | } |
21 | ||
22 | install() { | |
ed66eafd | 23 | inst_rules 90-zfs.rules 69-vdev.rules 60-zvol.rules |
5eae5a88 | 24 | |
7f5a01bd | 25 | inst_multiple \ |
ed66eafd SJ |
26 | zgenhostid \ |
27 | zfs \ | |
28 | zpool \ | |
29 | mount.zfs \ | |
44b0380a SJ |
30 | hostid \ |
31 | grep \ | |
32 | awk \ | |
33 | tr \ | |
34 | cut \ | |
7f5a01bd SJ |
35 | head || |
36 | { dfatal "Failed to install essential binaries"; exit 1; } | |
5eae5a88 SJ |
37 | |
38 | # Adapted from https://github.com/zbm-dev/zfsbootmenu | |
5eae5a88 | 39 | if ! ldd "$(command -v zpool)" | grep -qF 'libgcc_s.so'; then |
7f5a01bd | 40 | # On systems with gcc-config (Gentoo, Funtoo, etc.), use it to find libgcc_s |
5eae5a88 SJ |
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" || | |
7f5a01bd SJ |
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 | |
5eae5a88 | 47 | inst_simple /usr/lib/gcc/*/*/libgcc_s.so* || |
7f5a01bd SJ |
48 | { dfatal "Unable to install libgcc_s.so"; exit 1; } |
49 | fi | |
50 | fi | |
51 | ||
eda3d4e1 | 52 | inst_hook cmdline 95 "${moddir}/parse-zfs.sh" |
5eae5a88 SJ |
53 | if [ -n "${systemdutildir}" ]; then |
54 | inst_script "${moddir}/zfs-generator.sh" "${systemdutildir}/system-generators/dracut-zfs-generator" | |
a5a37022 | 55 | fi |
7da8f8d8 | 56 | inst_hook pre-mount 90 "${moddir}/zfs-load-key.sh" |
d402c18d | 57 | inst_hook mount 98 "${moddir}/mount-zfs.sh" |
f8e87e20 | 58 | inst_hook cleanup 99 "${moddir}/zfs-needshutdown.sh" |
7e8a2d0b | 59 | inst_hook shutdown 20 "${moddir}/export-zfs.sh" |
e8753fb4 | 60 | |
5eae5a88 | 61 | inst_script "${moddir}/zfs-lib.sh" "/lib/dracut-zfs-lib.sh" |
b9676003 | 62 | |
5eae5a88 SJ |
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" | |
1543b20a | 68 | |
e8753fb4 | 69 | # Synchronize initramfs and system hostid |
5eae5a88 SJ |
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 | |
24c12b48 | 75 | fi |
a5a37022 MT |
76 | |
77 | if dracut_module_included "systemd"; then | |
5eae5a88 SJ |
78 | inst_simple "${systemdsystemunitdir}/zfs-import.target" |
79 | systemctl -q --root "${initdir}" add-wants initrd.target zfs-import.target | |
eec5ba11 | 80 | |
5eae5a88 SJ |
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 | |
eec5ba11 | 83 | |
59ca6e2a VO |
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 | ||
5eae5a88 SJ |
93 | for _service in \ |
94 | "zfs-import-scan.service" \ | |
b17663f5 | 95 | "zfs-import-cache.service"; do |
5eae5a88 SJ |
96 | inst_simple "${systemdsystemunitdir}/${_service}" |
97 | systemctl -q --root "${initdir}" add-wants zfs-import.target "${_service}" | |
b10f73f7 | 98 | |
59ca6e2a VO |
99 | # Add user-provided unit overrides: |
100 | # - /etc/systemd/system/${_service} | |
101 | # - /etc/systemd/system/${_service}.d/overrides.conf | |
b10f73f7 VO |
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 | ||
5eae5a88 | 108 | done |
eec5ba11 | 109 | |
5eae5a88 SJ |
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}" | |
fdc59cf5 VO |
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 | |
9052e3d7 | 124 | done |
eec5ba11 | 125 | |
5eae5a88 | 126 | inst_simple "${moddir}/import-opts-generator.sh" "${systemdutildir}/system-environment-generators/zfs-import-opts.sh" |
a5a37022 | 127 | fi |
fde4ce99 | 128 | } |