]> git.proxmox.com Git - zfsonlinux.git/blob - zfs-debian-pve/tree/zfs-initramfs/usr/share/initramfs-tools/hooks/zfs
zfs-initrd: create /etc/mtab
[zfsonlinux.git] / zfs-debian-pve / tree / zfs-initramfs / usr / share / initramfs-tools / hooks / zfs
1 #!/bin/sh
2 #
3 # Add ZoL filesystem capabilities to an initrd, usually for a native OpenZFS 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
13 # These prerequisites are provided by the base system.
14 COPY_EXEC_LIST="$COPY_EXEC_LIST /bin/hostname /sbin/blkid"
15
16 # Explicitly specify all kernel modules because automatic dependency resolution
17 # is unreliable on many systems.
18 MANUAL_ADD_MODULES_LIST="zlib_deflate spl zavl zcommon znvpair zunicode zfs"
19
20 # Generic result code.
21 RC=0
22
23 case $1 in
24 prereqs)
25 echo "$PREREQ"
26 exit 0
27 ;;
28 esac
29
30 for ii in $COPY_EXEC_LIST
31 do
32 if [ ! -x "$ii" ]
33 then
34 echo "Error: $ii is not executable."
35 RC=2
36 fi
37 done
38
39 if [ "$RC" -ne 0 ]
40 then
41 exit "$RC"
42 fi
43
44 . /usr/share/initramfs-tools/hook-functions
45
46 mkdir -p "$DESTDIR/etc/"
47
48 # zpool requires /etc/mtab
49 ln -sf "/proc/mounts" "$DESTDIR/etc/mtab"
50
51 # ZDB uses pthreads for some functions, but the library dependency is not
52 # automatically detected. The `find` utility and extended `cp` options are
53 # used here because libgcc_s.so could be in a subdirectory of /lib for
54 # multi-arch installations.
55 cp --target-directory="$DESTDIR" --parents $(find /lib -type f -name libgcc_s.so.1)
56
57 for ii in $COPY_EXEC_LIST
58 do
59 copy_exec "$ii"
60 done
61
62 for ii in $MANUAL_ADD_MODULES_LIST
63 do
64 manual_add_modules "$ii"
65 done
66
67 if [ -f "/etc/hostname" ]
68 then
69 cp -p "/etc/hostname" "$DESTDIR/etc/"
70 else
71 hostname >"$DESTDIR/etc/hostname"
72 fi
73
74 # ZoL 0.6.3 deprecated the hostid check.
75 if [ -f /etc/hostid ]
76 then
77 cp -p /etc/hostid "$DESTDIR/etc/hostid"
78 fi