]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/dracut/90zfs/module-setup.sh.in
dracut: 90zfs: module-setup: try /lib*/libgcc_s.so*, relax /u/l/gcc path
[FreeBSD/FreeBSD.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 "@sbindir@/zgenhostid" "@sbindir@/zpool" "@sbindir@/zfs" "@mounthelperdir@/mount.zfs" ; do
10                 test -x "$tool" || return 1
11         done
12
13         return 0
14 }
15
16 depends() {
17         echo udev-rules
18         return 0
19 }
20
21 installkernel() {
22         instmods zfs
23         instmods zcommon
24         instmods znvpair
25         instmods zavl
26         instmods zunicode
27         instmods zlua
28         instmods icp
29         instmods spl
30         instmods zlib_deflate
31         instmods zlib_inflate
32 }
33
34 install() {
35         inst_rules @udevruledir@/90-zfs.rules
36         inst_rules @udevruledir@/69-vdev.rules
37         inst_rules @udevruledir@/60-zvol.rules
38         dracut_install hostid
39         dracut_install grep
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
47                 :;
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
51                 s="$(gcc-config -c)"
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
57                 # SUSE
58                 dracut_install /lib*/libgcc_s.so*
59         else
60                 # Fallback: Guess the path and include all matches
61                 dracut_install /usr/lib*/gcc/**/libgcc_s.so*
62         fi
63         dracut_install @mounthelperdir@/mount.zfs
64         dracut_install @udevdir@/vdev_id
65         dracut_install awk
66         dracut_install basename
67         dracut_install cut
68         dracut_install head
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
73         fi
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"
78
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
83         fi
84
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
88         fi
89
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
97         fi
98
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
106                         fi
107                 done
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
118                 fi
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
123                         fi
124                 done
125         fi
126 }