Skip to content

Commit

Permalink
Move udev initrd hooks into zfsutils to mount zdev-based pools at boot
Browse files Browse the repository at this point in the history
@todo: Add commit message.

Closes: dajhorn/pkg-zfs#39
Closes: openzfs/zfs#811
  • Loading branch information
pdf authored and dajhorn committed Sep 10, 2012
1 parent e82f58f commit ca3e482
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 28 deletions.
29 changes: 1 addition & 28 deletions debian/tree/zfs-initramfs/usr/share/initramfs-tools/hooks/zfs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@


# This module depends on these initramfs-tools modules.
PREREQ="udev"

# ZFS on Linux uses udev for device node creation.
PREREQ_UDEV_RULES="60-zpool.rules 60-zvol.rules"
PREREQ="zdev"

# These prerequisites are provided by the zfs package. The zdb utility is not
# strictly required, but it can be useful at the initramfs recovery prompt.
COPY_EXEC_LIST=" \
/lib/udev/zvol_id \
/lib/udev/zpool_id \
/sbin/zdb \
/sbin/zpool \
/sbin/zfs \
Expand Down Expand Up @@ -57,30 +52,13 @@ fi
. /usr/share/initramfs-tools/hook-functions

mkdir -p "$DESTDIR/etc/"
mkdir -p "$DESTDIR/lib/udev/rules.d/"

# ZDB uses pthreads for some functions, but the library dependency is not
# automatically detected. The `find` utility and extended `cp` options are
# used here because libgcc_s.so could be in a subdirectory of /lib for
# multi-arch installations.
cp --target-directory="$DESTDIR" --parents $(find /lib -type f -name libgcc_s.so.1)


for ii in $PREREQ_UDEV_RULES
do
if [ -e "/etc/udev/rules.d/$ii" ]
then
cp -p "/etc/udev/rules.d/$ii" "$DESTDIR/lib/udev/rules.d/"
elif [ -e "/lib/udev/rules.d/$ii" ]
then
cp -p "/lib/udev/rules.d/$ii" "$DESTDIR/lib/udev/rules.d/"
else
echo "Error: Missing udev rule: $ii"
echo " This file must be in the /etc/udev/rules.d or /lib/udev/rules.d directory."
exit 1
fi
done

for ii in $COPY_EXEC_LIST
do
copy_exec "$ii"
Expand All @@ -101,8 +79,3 @@ fi
# The spl package ensures that the /etc/hostid file exists.
# NB: Commentary in the spl.postinst script.
cp -p "/etc/hostid" "$DESTDIR/etc/hostid"

if [ -e "/etc/zfs/" ]
then
cp -a "/etc/zfs/" "$DESTDIR/etc/"
fi
79 changes: 79 additions & 0 deletions debian/tree/zfsutils/usr/share/initramfs-tools/hooks/zdev
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/sh
#
# Add ZFS filesystem capabilities to an initrd through update-initramfs.
#


# This module depends on these initramfs-tools modules.
PREREQ="udev"

# ZFS on Linux uses udev for device node creation.
PREREQ_UDEV_RULES="60-zpool.rules 60-zvol.rules"

# These prerequisites are provided by the zfs package. The zdb utility is not
# strictly required, but it can be useful at the initramfs recovery prompt.
COPY_EXEC_LIST=" \
/lib/udev/zvol_id \
/lib/udev/zpool_id \
"

# Generic result code.
RC=0

case $1 in
prereqs)
echo "$PREREQ"
exit 0
;;
esac

for ii in $COPY_EXEC_LIST
do
if [ ! -x "$ii" ]
then
echo "Error: $ii is not executable."
RC=2
fi
done

if [ "$RC" -ne 0 ]
then
exit "$RC"
fi

. /usr/share/initramfs-tools/hook-functions

mkdir -p "$DESTDIR/etc/"
mkdir -p "$DESTDIR/lib/udev/rules.d/"

# ZDB uses pthreads for some functions, but the library dependency is not
# automatically detected. The `find` utility and extended `cp` options are
# used here because libgcc_s.so could be in a subdirectory of /lib for
# multi-arch installations.
cp --target-directory="$DESTDIR" --parents $(find /lib -type f -name libgcc_s.so.1)


for ii in $PREREQ_UDEV_RULES
do
if [ -e "/etc/udev/rules.d/$ii" ]
then
cp -p "/etc/udev/rules.d/$ii" "$DESTDIR/lib/udev/rules.d/"
elif [ -e "/lib/udev/rules.d/$ii" ]
then
cp -p "/lib/udev/rules.d/$ii" "$DESTDIR/lib/udev/rules.d/"
else
echo "Error: Missing udev rule: $ii"
echo " This file must be in the /etc/udev/rules.d or /lib/udev/rules.d directory."
exit 1
fi
done

for ii in $COPY_EXEC_LIST
do
copy_exec "$ii"
done

if [ -e "/etc/zfs/" ]
then
cp -a "/etc/zfs/" "$DESTDIR/etc/"
fi
1 change: 1 addition & 0 deletions debian/zfsutils.triggers
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
activate update-initramfs

0 comments on commit ca3e482

Please sign in to comment.