]> git.proxmox.com Git - mirror_zfs-debian.git/blob - contrib/initramfs/hooks/zfs
26aaa6e186f0d59f6611533b7f29088323e70cfd
[mirror_zfs-debian.git] / contrib / initramfs / hooks / zfs
1 #!/bin/sh
2 #
3 # Add ZoL filesystem capabilities to an initrd, usually for a native ZFS root.
4 #
5
6 # This hook installs udev rules for ZoL.
7 PREREQ="zdev"
8
9 # These prerequisites are provided by the zfsutils package. The zdb utility is
10 # not strictly required, but it can be useful at the initramfs recovery prompt.
11 COPY_EXEC_LIST="/sbin/zdb /sbin/zpool /sbin/zfs /sbin/mount.zfs"
12 COPY_EXEC_LIST="$COPY_EXEC_LIST /usr/bin/dirname /lib/udev/vdev_id"
13 COPY_FILE_LIST="/etc/hostid /etc/zfs/zpool.cache /etc/default/zfs"
14 COPY_FILE_LIST="$COPY_FILE_LIST /etc/zfs/zfs-functions /etc/zfs/vdev_id.conf"
15 COPY_FILE_LIST="$COPY_FILE_LIST /lib/udev/rules.d/69-vdev.rules"
16
17 # These prerequisites are provided by the base system.
18 COPY_EXEC_LIST="$COPY_EXEC_LIST /bin/hostname /sbin/blkid"
19
20 # Explicitly specify all kernel modules because automatic dependency resolution
21 # is unreliable on many systems.
22 BASE_MODULES="zlib_deflate spl zavl zcommon znvpair zunicode zfs icp"
23 CRPT_MODULES="sun-ccm sun-gcm sun-ctr"
24 MANUAL_ADD_MODULES_LIST="$BASE_MODULES"
25
26 # Generic result code.
27 RC=0
28
29 case $1 in
30 prereqs)
31 echo "$PREREQ"
32 exit 0
33 ;;
34 esac
35
36 for ii in $COPY_EXEC_LIST
37 do
38 if [ ! -x "$ii" ]
39 then
40 echo "Error: $ii is not executable."
41 RC=2
42 fi
43 done
44
45 if [ "$RC" -ne 0 ]
46 then
47 exit "$RC"
48 fi
49
50 . /usr/share/initramfs-tools/hook-functions
51
52 mkdir -p "$DESTDIR/etc/"
53
54 # ZDB uses pthreads for some functions, but the library dependency is not
55 # automatically detected. The `find` utility and extended `cp` options are
56 # used here because libgcc_s.so could be in a subdirectory of /lib for
57 # multi-arch installations.
58 cp --target-directory="$DESTDIR" --parents $(find /lib/ -type f -name libgcc_s.so.1)
59
60 for ii in $COPY_EXEC_LIST
61 do
62 copy_exec "$ii"
63 done
64
65 for ii in $COPY_FILE_LIST
66 do
67 dir=$(dirname "$ii")
68 [ -d "$dir" ] && mkdir -p "$DESTDIR/$dir"
69 [ -f "$ii" ] && cp -p "$ii" "$DESTDIR/$ii"
70 done
71
72 for ii in $MANUAL_ADD_MODULES_LIST
73 do
74 manual_add_modules "$ii"
75 done
76
77 if [ -f "/etc/hostname" ]
78 then
79 cp -p "/etc/hostname" "$DESTDIR/etc/"
80 else
81 hostname >"$DESTDIR/etc/hostname"
82 fi
83
84 for ii in zfs zfs.conf spl spl.conf
85 do
86 if [ -f "/etc/modprobe.d/$ii" ]; then
87 if [ ! -d "$DESTDIR/etc/modprobe.d" ]; then
88 mkdir -p $DESTDIR/etc/modprobe.d
89 fi
90 cp -p "/etc/modprobe.d/$ii" $DESTDIR/etc/modprobe.d/
91 fi
92 done
93
94 # With pull request #1476 (not yet merged) comes a verbose warning
95 # if /usr/bin/net doesn't exist or isn't executable. Just create
96 # a dummy...
97 [ ! -d "$DESTDIR/usr/bin" ] && mkdir -p "$DESTDIR/usr/bin"
98 if [ ! -x "$DESTDIR/usr/bin/net" ]; then
99 touch "$DESTDIR/usr/bin/net"
100 chmod +x "$DESTDIR/usr/bin/net"
101 fi
102
103 exit 0