]> git.proxmox.com Git - mirror_zfs.git/blame - contrib/dracut/90zfs/module-setup.sh.in
autoconf: use include directives instead of recursing down contrib
[mirror_zfs.git] / contrib / dracut / 90zfs / module-setup.sh.in
CommitLineData
dda702fd 1#!/usr/bin/env bash
6fc30992 2# shellcheck disable=SC2154
fde4ce99
ZB
3
4check() {
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
14depends() {
1ef5e829 15 echo udev-rules
fde4ce99
ZB
16}
17
18installkernel() {
7f5a01bd 19 instmods -c zfs
fde4ce99
ZB
20}
21
22install() {
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
5eae5a88
SJ
84 for _service in \
85 "zfs-import-scan.service" \
86 "zfs-import-cache.service" \
87 "zfs-load-module.service"; do
88 inst_simple "${systemdsystemunitdir}/${_service}"
89 systemctl -q --root "${initdir}" add-wants zfs-import.target "${_service}"
90 done
eec5ba11 91
5eae5a88
SJ
92 for _service in \
93 "zfs-snapshot-bootfs.service" \
94 "zfs-rollback-bootfs.service"; do
95 inst_simple "${moddir}/${_service}" "${systemdsystemunitdir}/${_service}"
96 systemctl -q --root "${initdir}" add-wants initrd.target "${_service}"
9052e3d7 97 done
eec5ba11 98
5eae5a88 99 inst_simple "${moddir}/import-opts-generator.sh" "${systemdutildir}/system-environment-generators/zfs-import-opts.sh"
a5a37022 100 fi
fde4ce99 101}