Skip to content

Commit

Permalink
Add zdev rules to the initrd for all installations.
Browse files Browse the repository at this point in the history
Always hook the udev rules that read the `/etc/zfs/zdev.conf` file into the
initrd, even if the system is not using the zfs-initramfs package.

This change ensures that `/dev/disk/zpool` device aliases are ready in time for
`mount` calls early in the init stack.

Amended-by: Darik Horn <dajhorn@vanadac.com>
Closes: dajhorn/pkg-zfs#39
Closes: openzfs/zfs#811
  • Loading branch information
pdf authored and dajhorn committed Oct 29, 2012
1 parent 7e0eab8 commit a73631b
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 45 deletions.
55 changes: 10 additions & 45 deletions debian/tree/zfs-initramfs/usr/share/initramfs-tools/hooks/zfs
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
#!/bin/sh
#
# Add ZFS filesystem capabilities to an initrd through update-initramfs.
# Add ZoL filesystem capabilities to an initrd, usually for a native ZFS root.
#

# This hook installs udev rules for ZoL.
PREREQ="zdev"

# 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 zfsutils package. The zdb utility is
# not strictly required, but it can be useful at the initramfs recovery prompt.
COPY_EXEC_LIST="/sbin/zdb /sbin/zpool /sbin/zfs /sbin/mount.zfs"

# 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 \
/sbin/mount.zfs \
"
# These prerequisites are provided by the base system.
COPY_EXEC_LIST="$COPY_EXEC_LIST /bin/hostname /sbin/blkid"

# These prerequisites are provides by other packages.
COPY_EXEC_LIST="$COPY_EXEC_LIST \
/bin/hostname \
/sbin/blkid \
"

# Explicitly specify all modules because dependency resolution is unreliable here.
# Explicitly specify all kernel modules because automatic dependency resolution
# is unreliable on many systems.
MANUAL_ADD_MODULES_LIST="zlib_deflate spl zavl zcommon znvpair zunicode zfs"

# Generic result code.
Expand Down Expand Up @@ -57,30 +44,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 +71,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
62 changes: 62 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,62 @@
#!/bin/sh
#
# Add udev rules for ZoL to the initrd.
#

PREREQ="udev"
PREREQ_UDEV_RULES="60-zpool.rules 60-zvol.rules"
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/"

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 a73631b

Please sign in to comment.