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