|
3 | 3 | # Add OpenZFS filesystem capabilities to an initrd, usually for a native ZFS root.
|
4 | 4 | #
|
5 | 5 |
|
6 |
| -# This hook installs udev rules for OpenZFS. |
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 @initconfdir@/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 |
| -COPY_EXEC_LIST="$COPY_EXEC_LIST $(which systemd-ask-password)" |
25 |
| - |
26 |
| -# Explicitly specify all kernel modules because automatic dependency resolution |
27 |
| -# is unreliable on many systems. |
28 |
| -BASE_MODULES="zlib_deflate spl zavl zcommon znvpair zunicode zlua zfs icp" |
29 |
| -CRPT_MODULES="sun-ccm sun-gcm sun-ctr" |
30 |
| -MANUAL_ADD_MODULES_LIST="$BASE_MODULES" |
31 |
| - |
32 |
| -# Generic result code. |
33 |
| -RC=0 |
| 6 | +if [ "$1" = "prereqs" ]; then |
| 7 | + echo "udev" |
| 8 | + exit |
| 9 | +fi |
34 | 10 |
|
35 |
| -case $1 in |
36 |
| -prereqs) |
37 |
| - echo "$PREREQ" |
38 |
| - exit 0 |
39 |
| - ;; |
40 |
| -esac |
| 11 | +. /usr/share/initramfs-tools/hook-functions |
41 | 12 |
|
42 |
| -for ii in $COPY_EXEC_LIST |
43 |
| -do |
44 |
| - if [ ! -x "$ii" ] |
45 |
| - then |
46 |
| - echo "Error: $ii is not executable." |
47 |
| - RC=2 |
48 |
| - fi |
| 13 | +for req in "@sbindir@/zpool" "@sbindir@/zfs" "@mounthelperdir@/mount.zfs"; do |
| 14 | + copy_exec "$req" || { |
| 15 | + echo "$req not available!" >&2 |
| 16 | + exit 2 |
| 17 | + } |
49 | 18 | done
|
50 | 19 |
|
51 |
| -if [ "$RC" -ne 0 ] |
52 |
| -then |
53 |
| - exit "$RC" |
| 20 | +copy_exec "@sbindir@/zdb" |
| 21 | +copy_exec "@udevdir@/vdev_id" |
| 22 | +copy_exec "@udevdir@/zvol_id" |
| 23 | +if command -v systemd-ask-password > /dev/null; then |
| 24 | + copy_exec "$(command -v systemd-ask-password)" |
54 | 25 | fi
|
55 | 26 |
|
56 |
| -. /usr/share/initramfs-tools/hook-functions |
57 |
| - |
58 |
| -mkdir -p "$DESTDIR/etc/" |
59 |
| - |
60 |
| -# ZDB uses pthreads for some functions, but the library dependency is not |
61 |
| -# automatically detected. The `find` utility and extended `cp` options are |
62 |
| -# used here because libgcc_s.so could be in a subdirectory of /lib for |
63 |
| -# multi-arch installations. |
64 |
| -cp --target-directory="$DESTDIR" --parents $(find /lib/ -type f -name libgcc_s.so.1) |
| 27 | +# We use pthreads, but i-t from buster doesn't automatically |
| 28 | +# copy this indirect dependency: this can be removed when buster finally dies. |
| 29 | +for libgcc in $(find /lib/ -type f -name libgcc_s.so.[1-9]); do |
| 30 | + copy_exec "$libgcc" |
| 31 | +done |
65 | 32 |
|
66 |
| -if [ @LIBFETCH_DYNAMIC@ != 0 ] |
67 |
| -then |
68 |
| - for l in $(find /lib/ -name @LIBFETCH_SONAME@) |
69 |
| - do |
70 |
| - copy_exec "$l" |
| 33 | +if [ @LIBFETCH_DYNAMIC@ != 0 ]; then |
| 34 | + for libfetch in $(find /lib/ -name @LIBFETCH_SONAME@); do |
| 35 | + copy_exec "$libfetch" |
71 | 36 | done
|
72 | 37 | fi
|
73 | 38 |
|
74 |
| -for ii in $COPY_EXEC_LIST |
75 |
| -do |
76 |
| - copy_exec "$ii" |
77 |
| -done |
| 39 | +copy_file config "/etc/hostid" |
| 40 | +copy_file cache "@sysconfdir@/zfs/zpool.cache" |
| 41 | +copy_file config "@initconfdir@/zfs" |
| 42 | +copy_file config "@sysconfdir@/zfs/zfs-functions" |
| 43 | +copy_file config "@sysconfdir@/zfs/vdev_id.conf" |
| 44 | +copy_file rule "@udevruledir@/60-zvol.rules" |
| 45 | +copy_file rule "@udevruledir@/69-vdev.rules" |
78 | 46 |
|
79 |
| -for ii in $COPY_FILE_LIST |
80 |
| -do |
81 |
| - dir=$(dirname "$ii") |
82 |
| - [ -d "$dir" ] && mkdir -p "$DESTDIR/$dir" |
83 |
| - [ -f "$ii" ] && cp -p "$ii" "$DESTDIR/$ii" |
84 |
| -done |
| 47 | +manual_add_modules zfs |
85 | 48 |
|
86 |
| -for ii in $MANUAL_ADD_MODULES_LIST |
87 |
| -do |
88 |
| - manual_add_modules "$ii" |
89 |
| -done |
90 |
| - |
91 |
| -if [ -f "/etc/hostname" ] |
92 |
| -then |
93 |
| - cp -p "/etc/hostname" "$DESTDIR/etc/" |
| 49 | +if [ -f "/etc/hostname" ]; then |
| 50 | + copy_file config "/etc/hostname" |
94 | 51 | else
|
95 |
| - hostname >"$DESTDIR/etc/hostname" |
| 52 | + hostname="$(mktemp -t hostname.XXXXXXXXXX)" |
| 53 | + hostname > "$hostname" |
| 54 | + copy_file config "$hostname" "/etc/hostname" |
| 55 | + rm -f "$hostname" |
96 | 56 | fi
|
97 |
| - |
98 |
| -for ii in zfs zfs.conf spl spl.conf |
99 |
| -do |
100 |
| - if [ -f "/etc/modprobe.d/$ii" ]; then |
101 |
| - if [ ! -d "$DESTDIR/etc/modprobe.d" ]; then |
102 |
| - mkdir -p $DESTDIR/etc/modprobe.d |
103 |
| - fi |
104 |
| - cp -p "/etc/modprobe.d/$ii" $DESTDIR/etc/modprobe.d/ |
105 |
| - fi |
106 |
| -done |
107 |
| - |
108 |
| -# With pull request #1476 (not yet merged) comes a verbose warning |
109 |
| -# if /usr/bin/net doesn't exist or isn't executable. Just create |
110 |
| -# a dummy... |
111 |
| -[ ! -d "$DESTDIR/usr/bin" ] && mkdir -p "$DESTDIR/usr/bin" |
112 |
| -if [ ! -x "$DESTDIR/usr/bin/net" ]; then |
113 |
| - touch "$DESTDIR/usr/bin/net" |
114 |
| - chmod +x "$DESTDIR/usr/bin/net" |
115 |
| -fi |
116 |
| - |
117 |
| -exit 0 |
0 commit comments