From 0dd30916f52ace3bf133104a2dcc2e6af21b416d Mon Sep 17 00:00:00 2001 From: Chris Wedgwood Date: Wed, 22 May 2019 22:56:37 -0700 Subject: [PATCH] [RFC] 'Fixes' for initramfs creation zfs-functions is needed, copy that to /etc/zfs/ The zfs hook that copies files will error on critical files. The argument for this is we do not want to create a non-functional initramfs. Some files are optional, those we do silently ignore --- contrib/initramfs/Makefile.am | 4 ++++ contrib/initramfs/hooks/zfs.in | 20 +++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/contrib/initramfs/Makefile.am b/contrib/initramfs/Makefile.am index 87ec7a86f5ac..cf1172e0a5a2 100644 --- a/contrib/initramfs/Makefile.am +++ b/contrib/initramfs/Makefile.am @@ -21,3 +21,7 @@ install-initrdSCRIPTS: $(EXTRA_DIST) cp $(top_srcdir)/etc/init.d/zfs \ $(DESTDIR)$(DEFAULT_INITCONF_DIR)/; \ fi + if [ -f etc/init.d/zfs-functions ]; then \ + cp $(top_srcdir)/etc/init.d/zfs-functions \ + $(DESTDIR)$(initrddir)/etc/zfs/zfs-functions \ + fi diff --git a/contrib/initramfs/hooks/zfs.in b/contrib/initramfs/hooks/zfs.in index e35354141d81..ff896e4cb28b 100755 --- a/contrib/initramfs/hooks/zfs.in +++ b/contrib/initramfs/hooks/zfs.in @@ -3,6 +3,11 @@ # Add ZoL filesystem capabilities to an initrd, usually for a native ZFS root. # +# fail on errors; this might be annoying but for now it's more +# important to fail during initramfs creation where we can do +# something about it, vs after a boot when we can't +set -eu + # This hook installs udev rules for ZoL. PREREQ="zdev" @@ -10,12 +15,12 @@ PREREQ="zdev" # not strictly required, but it can be useful at the initramfs recovery prompt. COPY_EXEC_LIST="@sbindir@/zdb @sbindir@/zpool @sbindir@/zfs" COPY_EXEC_LIST="$COPY_EXEC_LIST @mounthelperdir@/mount.zfs @udevdir@/vdev_id" -COPY_FILE_LIST="/etc/hostid @sysconfdir@/zfs/zpool.cache" -COPY_FILE_LIST="$COPY_FILE_LIST @sysconfdir@/default/zfs" COPY_FILE_LIST="$COPY_FILE_LIST @sysconfdir@/zfs/zfs-functions" -COPY_FILE_LIST="$COPY_FILE_LIST @sysconfdir@/zfs/vdev_id.conf" COPY_FILE_LIST="$COPY_FILE_LIST @udevruledir@/69-vdev.rules" +# These are not required +OPTIONAL_FILE_LIST="/etc/hostid @sysconfdir@/default/zfs @sysconfdir@/zfs/vdev_id.conf" + # These prerequisites are provided by the base system. COPY_EXEC_LIST="$COPY_EXEC_LIST /usr/bin/dirname /bin/hostname /sbin/blkid" COPY_EXEC_LIST="$COPY_EXEC_LIST /usr/bin/env" @@ -66,6 +71,15 @@ do done for ii in $COPY_FILE_LIST +do + dir=$(dirname "$ii") + [ -d "$dir" ] && mkdir -p "$DESTDIR/$dir" + [ -f "$ii" ] && cp -p "$ii" "$DESTDIR/$ii" + # error if missing + [ -e "$ii" ] +done + +for ii in $OPTIONAL_FILE_LIST do dir=$(dirname "$ii") [ -d "$dir" ] && mkdir -p "$DESTDIR/$dir"