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