]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/openzfs/contrib/dracut/90zfs/module-setup.sh.in
Update OpenZFS to 2.0.0-rc3-gfc5966
[FreeBSD/FreeBSD.git] / sys / contrib / openzfs / contrib / dracut / 90zfs / module-setup.sh.in
1 #!/usr/bin/env bash
2
3 check() {
4         # We depend on udev-rules being loaded
5         [ "${1}" = "-d" ] && return 0
6
7         # Verify the zfs tool chain
8         for tool in "@bindir@/zgenhostid" "@sbindir@/zpool" "@sbindir@/zfs" "@mounthelperdir@/mount.zfs" ; do
9                 test -x "$tool" || return 1
10         done
11         # Verify grep exists
12         which grep >/dev/null 2>&1 || return 1
13
14         return 0
15 }
16
17 depends() {
18         echo udev-rules
19         return 0
20 }
21
22 installkernel() {
23         instmods zfs
24         instmods zcommon
25         instmods znvpair
26         instmods zavl
27         instmods zunicode
28         instmods zlua
29         instmods icp
30         instmods spl
31         instmods zlib_deflate
32         instmods zlib_inflate
33 }
34
35 install() {
36         inst_rules @udevruledir@/90-zfs.rules
37         inst_rules @udevruledir@/69-vdev.rules
38         inst_rules @udevruledir@/60-zvol.rules
39         dracut_install hostid
40         dracut_install grep
41         dracut_install @bindir@/zgenhostid
42         dracut_install @sbindir@/zfs
43         dracut_install @sbindir@/zpool
44         # Workaround for https://github.com/openzfs/zfs/issues/4749 by
45         # ensuring libgcc_s.so(.1) is included
46         if [[ -n "$(ldd @sbindir@/zpool | grep -F 'libgcc_s.so')" ]]; then
47                 # Dracut will have already tracked and included it
48                 :;
49         elif command -v gcc-config 2>&1 1>/dev/null; then
50                 # On systems with gcc-config (Gentoo, Funtoo, etc.):
51                 # Use the current profile to resolve the appropriate path
52                 dracut_install "/usr/lib/gcc/$(s=$(gcc-config -c); echo ${s%-*}/${s##*-})/libgcc_s.so.1"
53         elif [[ -n "$(ls /usr/lib/libgcc_s.so* 2>/dev/null)" ]]; then
54                 # Try a simple path first
55                 dracut_install /usr/lib/libgcc_s.so*
56         else
57                 # Fallback: Guess the path and include all matches
58                 dracut_install /usr/lib/gcc/*/*/libgcc_s.so*
59         fi
60         dracut_install @mounthelperdir@/mount.zfs
61         dracut_install @udevdir@/vdev_id
62         dracut_install awk
63         dracut_install basename
64         dracut_install cut
65         dracut_install head
66         dracut_install @udevdir@/zvol_id
67         inst_hook cmdline 95 "${moddir}/parse-zfs.sh"
68         if [ -n "$systemdutildir" ] ; then
69                 inst_script "${moddir}/zfs-generator.sh" "$systemdutildir"/system-generators/dracut-zfs-generator
70         fi
71         inst_hook pre-mount 90 "${moddir}/zfs-load-key.sh"
72         inst_hook mount 98 "${moddir}/mount-zfs.sh"
73         inst_hook cleanup 99 "${moddir}/zfs-needshutdown.sh"
74         inst_hook shutdown 20 "${moddir}/export-zfs.sh"
75
76         inst_simple "${moddir}/zfs-lib.sh" "/lib/dracut-zfs-lib.sh"
77         if [ -e @sysconfdir@/zfs/zpool.cache ]; then
78                 inst @sysconfdir@/zfs/zpool.cache
79                 type mark_hostonly >/dev/null 2>&1 && mark_hostonly @sysconfdir@/zfs/zpool.cache
80         fi
81
82         if [ -e @sysconfdir@/zfs/vdev_id.conf ]; then
83                 inst @sysconfdir@/zfs/vdev_id.conf
84                 type mark_hostonly >/dev/null 2>&1 && mark_hostonly @sysconfdir@/zfs/vdev_id.conf
85         fi
86
87         # Synchronize initramfs and system hostid
88         zgenhostid -o "${initdir}/etc/hostid" "$(hostid)"
89
90         if dracut_module_included "systemd"; then
91                 mkdir -p "${initdir}/$systemdsystemunitdir/zfs-import.target.wants"
92                 for _item in scan cache ; do
93                         dracut_install @systemdunitdir@/zfs-import-$_item.service
94                         if ! [ -L "${initdir}/$systemdsystemunitdir/zfs-import.target.wants"/zfs-import-$_item.service ]; then
95                                 ln -s ../zfs-import-$_item.service "${initdir}/$systemdsystemunitdir/zfs-import.target.wants"/zfs-import-$_item.service
96                                 type mark_hostonly >/dev/null 2>&1 && mark_hostonly @systemdunitdir@/zfs-import-$_item.service
97                         fi
98                 done
99                 inst "${moddir}"/zfs-env-bootfs.service "${systemdsystemunitdir}"/zfs-env-bootfs.service
100                 ln -s ../zfs-env-bootfs.service "${initdir}/${systemdsystemunitdir}/zfs-import.target.wants"/zfs-env-bootfs.service
101                 type mark_hostonly >/dev/null 2>&1 && mark_hostonly @systemdunitdir@/zfs-env-bootfs.service
102                 dracut_install systemd-ask-password
103                 dracut_install systemd-tty-ask-password-agent
104                 mkdir -p "${initdir}/$systemdsystemunitdir/initrd.target.wants"
105                 dracut_install @systemdunitdir@/zfs-import.target
106                 if ! [ -L "${initdir}/$systemdsystemunitdir/initrd.target.wants"/zfs-import.target ]; then
107                         ln -s ../zfs-import.target "${initdir}/$systemdsystemunitdir/initrd.target.wants"/zfs-import.target
108                         type mark_hostonly >/dev/null 2>&1 && mark_hostonly @systemdunitdir@/zfs-import.target
109                 fi
110                 for _service in zfs-snapshot-bootfs.service zfs-rollback-bootfs.service ; do
111                         inst "${moddir}"/$_service "${systemdsystemunitdir}"/$_service
112                         if ! [ -L "${initdir}/$systemdsystemunitdir/initrd.target.wants"/$_service ]; then
113                                 ln -s ../$_service "${initdir}/$systemdsystemunitdir/initrd.target.wants"/$_service
114                         fi
115                 done
116         fi
117 }