[Pkg-zfsonlinux-devel] [SCM] zfs branch, master, updated. debian/0.6.5.8-3-5-g94b699f

Aron Xu aron at debian.org
Fri Jan 27 18:44:22 UTC 2017


The following commit has been merged in the master branch:
commit 146eee208ab3a35cecdb65a3edafd82e3130ff44
Author: Lukas Wunner <lukas at wunner.de>
Date:   Sat Jan 28 02:36:30 2017 +0800

    Cherry picks for root zpool with dracut (Closes: #849969)
    
    After upgrading to systemd 230 as included with Debian stretch, systems
    that build their initramfs with dracut and have their root partition on
    a zpool fail to boot:
    
    On boot, /usr/lib/dracut/modules.d/98dracut-systemd/rootfs-generator.sh
    generates a systemd unit to mount the "root=" kernel parameter, which
    for ZFS may look like "zfs:pool/dataset" or "zfs:AUTO", a format not
    understood by mount(8).  As a result systemd switches to emergency mode.
    
    A fix was committed upstream in April 2016 with a5a370227eb0 ("fix
    booting via dracut generated initramfs"), but never made it into the
    0.6.5.* point releases, presumably because they do not pick up fixes
    in the contrib/ directory.
    
    Signed-off-by: Aron Xu <aron at debian.org>

diff --git a/debian/patches/0001-fix-booting-via-dracut-generated-initramfs.patch b/debian/patches/0001-fix-booting-via-dracut-generated-initramfs.patch
new file mode 100644
index 0000000..eeea4e2
--- /dev/null
+++ b/debian/patches/0001-fix-booting-via-dracut-generated-initramfs.patch
@@ -0,0 +1,337 @@
+From a5a370227eb0a3daf8992a38920d54eb3b7b3c25 Mon Sep 17 00:00:00 2001
+From: Matthew Thode <mthode at mthode.org>
+Date: Wed, 30 Mar 2016 18:59:15 -0500
+Subject: [PATCH 001/530] fix booting via dracut generated initramfs
+
+Dracut and Systemd updated how they integrate with each other, because
+of this our current integrations stopped working (around the time
+4.1.13 came out).  This patch addresses that issue and gets us booting
+again.
+
+Thanks to @Rudd-O for doing the work to get dracut working again and
+letting me submit this on his behalf.
+
+Signed-off-by: Manuel Amador (Rudd-O) <rudd-o at rudd-o.com>
+Signed-off-by: Matthew Thode <mthode at mthode.org>
+Closes #3605
+Closes #4478
+---
+ configure.ac                                       |   1 +
+ contrib/dracut/02zfsexpandknowledge/Makefile.am    |  22 ++++
+ .../dracut/02zfsexpandknowledge/module-setup.sh.in | 132 +++++++++++++++++++++
+ contrib/dracut/90zfs/Makefile.am                   |   3 +
+ contrib/dracut/90zfs/module-setup.sh.in            |  19 ++-
+ contrib/dracut/90zfs/zfs-generator.sh.in           |  39 ++++++
+ contrib/dracut/Makefile.am                         |   2 +-
+ 7 files changed, 216 insertions(+), 2 deletions(-)
+ create mode 100644 contrib/dracut/02zfsexpandknowledge/Makefile.am
+ create mode 100755 contrib/dracut/02zfsexpandknowledge/module-setup.sh.in
+ create mode 100644 contrib/dracut/90zfs/zfs-generator.sh.in
+
+diff --git a/configure.ac b/configure.ac
+index 41cd007..5037ccb 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -114,6 +114,7 @@ AC_CONFIG_FILES([
+ 	contrib/Makefile
+ 	contrib/bash_completion.d/Makefile
+ 	contrib/dracut/Makefile
++	contrib/dracut/02zfsexpandknowledge/Makefile
+ 	contrib/dracut/90zfs/Makefile
+ 	contrib/initramfs/Makefile
+ 	module/Makefile
+diff --git a/contrib/dracut/02zfsexpandknowledge/Makefile.am b/contrib/dracut/02zfsexpandknowledge/Makefile.am
+new file mode 100644
+index 0000000..0a2170b
+--- /dev/null
++++ b/contrib/dracut/02zfsexpandknowledge/Makefile.am
+@@ -0,0 +1,22 @@
++pkgdracutdir = $(dracutdir)/modules.d/02zfsexpandknowledge
++pkgdracut_SCRIPTS = \
++	module-setup.sh
++
++EXTRA_DIST = \
++	$(top_srcdir)/contrib/dracut/02zfsexpandknowledge/module-setup.sh.in
++
++$(pkgdracut_SCRIPTS):
++	-$(SED) -e 's, at bindir\@,$(bindir),g' \
++		-e 's, at sbindir\@,$(sbindir),g' \
++		-e 's, at datadir\@,$(datadir),g' \
++		-e 's, at dracutdir\@,$(dracutdir),g' \
++		-e 's, at udevdir\@,$(udevdir),g' \
++		-e 's, at udevruledir\@,$(udevruledir),g' \
++		-e 's, at sysconfdir\@,$(sysconfdir),g' \
++		"$(top_srcdir)/contrib/dracut/02zfsexpandknowledge/$@.in" >'$@'
++
++clean-local::
++	-$(RM) $(pkgdracut_SCRIPTS)
++
++distclean-local::
++	-$(RM) $(pkgdracut_SCRIPTS)
+diff --git a/contrib/dracut/02zfsexpandknowledge/module-setup.sh.in b/contrib/dracut/02zfsexpandknowledge/module-setup.sh.in
+new file mode 100755
+index 0000000..830ee42
+--- /dev/null
++++ b/contrib/dracut/02zfsexpandknowledge/module-setup.sh.in
+@@ -0,0 +1,132 @@
++#!/bin/sh
++
++get_devtype() {
++  local typ
++  typ=$(udevadm info --query=property --name="$1" | grep "^ID_FS_TYPE=" | sed 's|^ID_FS_TYPE=||')
++  if [ "$typ" = "" ] ; then
++     typ=$(blkid -c /dev/null "$1" -o value -s TYPE)
++  fi
++  echo "$typ"
++}
++
++get_pool_devices() {
++  # also present in 99zfssystemd
++  local poolconfigtemp
++  local poolconfigoutput
++  local pooldev
++  local prefix
++  poolconfigtemp=`mktemp`
++  @sbindir@/zpool list -v -H "$1" > "$poolconfigtemp" 2>&1
++  if [ "$?" != "0" ] ; then
++    poolconfigoutput=$(cat "$poolconfigtemp")
++    dinfo "zfsexpandknowledge: pool $1 cannot be listed: $poolconfigoutput"
++  else
++    while read pooldev ; do
++      for prefix in /dev/disk/* /dev/mapper ; do
++        if [ -e "$prefix"/"$pooldev" ] ; then
++          dinfo "zfsexpandknowledge: pool $1 has device $prefix/$pooldev"
++          echo `readlink -f "$prefix"/"$pooldev"`
++          break
++        fi
++      done
++    done < <(cat "$poolconfigtemp" | awk -F '\t' 'NR>1 { print $2 }')
++  fi
++  rm -f "$poolconfigtemp"
++}
++
++find_zfs_block_devices() {
++    local dev
++    local blockdev
++    local mp
++    local fstype
++    local pool
++    local key
++    local n
++    local poolconfigoutput
++    numfields=`head -1 /proc/self/mountinfo | awk '{print NF}'`
++    if [ "$numfields" == "10" ] ; then
++        fields="n n n n mp n n fstype dev n"
++    else
++        fields="n n n n mp n n n fstype dev n"
++    fi
++    while read $fields ; do
++       if [ "$fstype" != "zfs" ]; then continue ; fi
++       if [ "$mp" == "$1" ]; then
++           pool=$(echo "$dev" | cut -d / -f 1)
++           get_pool_devices "$pool"
++       fi
++    done < /proc/self/mountinfo
++}
++
++array_contains () {
++  local e
++  for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
++  return 1
++}
++
++check() {
++    local mp
++    local dev
++    local blockdevs
++    local fstype
++    local majmin
++    local _slavedev
++    local _slavedevname
++    local _slavedevtype
++    local _slavemajmin
++    local _dev
++
++if [[ $hostonly ]]; then
++
++    for mp in \
++        "/" \
++        "/etc" \
++        "/bin" \
++        "/sbin" \
++        "/lib" \
++        "/lib64" \
++        "/usr" \
++        "/usr/bin" \
++        "/usr/sbin" \
++        "/usr/lib" \
++        "/usr/lib64" \
++        "/boot";
++    do
++        mp=$(readlink -f "$mp")
++        mountpoint "$mp" >/dev/null 2>&1 || continue
++        blockdevs=$(find_zfs_block_devices "$mp")
++        if [ -z "$blockdevs" ] ; then continue ; fi
++        dinfo "zfsexpandknowledge: block devices backing ZFS dataset $mp: $blockdevs"
++        for dev in $blockdevs
++        do
++            array_contains "$dev" "${host_devs[@]}" || host_devs+=("$dev")
++            fstype=$(get_devtype "$dev")
++            host_fs_types["$dev"]="$fstype"
++            majmin=$(get_maj_min "$dev")
++            if [[ -d /sys/dev/block/$majmin/slaves ]] ; then
++                for _slavedev in /sys/dev/block/$majmin/slaves/*; do
++                    [[ -f $_slavedev/dev ]] || continue
++                    _slavedev=/dev/$(basename "$_slavedev")
++                    _slavedevname=$(udevadm info --query=property --name="$_slavedev" | grep "^DEVNAME=" | sed 's|^DEVNAME=||')
++                    _slavedevtype=$(get_devtype "$_slavedevname")
++                    _slavemajmin=$(get_maj_min "$_slavedevname")
++                    dinfo "zfsexpandknowledge: slave block device backing ZFS dataset $mp: $_slavedevname"
++                    array_contains "$_slavedevname" "${host_devs[@]}" || host_devs+=("$_slavedevname")
++                    host_fs_types["$_slavedevname"]="$_slavedevtype"
++                done
++            fi
++        done
++    done
++    for a in "${host_devs[@]}"
++        do
++        dinfo "zfsexpandknowledge: host device $a"
++    done
++    for a in "${!host_fs_types[@]}"
++        do
++        dinfo "zfsexpandknowledge: device $a of type ${host_fs_types[$a]}"
++    done
++
++fi
++
++return 1
++}
+diff --git a/contrib/dracut/90zfs/Makefile.am b/contrib/dracut/90zfs/Makefile.am
+index b778a27..f81d6c3 100644
+--- a/contrib/dracut/90zfs/Makefile.am
++++ b/contrib/dracut/90zfs/Makefile.am
+@@ -4,6 +4,7 @@ pkgdracut_SCRIPTS = \
+ 	module-setup.sh \
+ 	mount-zfs.sh \
+ 	parse-zfs.sh \
++	zfs-generator.sh \
+ 	zfs-lib.sh
+ 
+ EXTRA_DIST = \
+@@ -11,6 +12,7 @@ EXTRA_DIST = \
+ 	$(top_srcdir)/contrib/dracut/90zfs/module-setup.sh.in \
+ 	$(top_srcdir)/contrib/dracut/90zfs/mount-zfs.sh.in \
+ 	$(top_srcdir)/contrib/dracut/90zfs/parse-zfs.sh.in \
++	$(top_srcdir)/contrib/dracut/90zfs/zfs-generator.sh.in \
+ 	$(top_srcdir)/contrib/dracut/90zfs/zfs-lib.sh.in
+ 
+ $(pkgdracut_SCRIPTS):
+@@ -19,6 +21,7 @@ $(pkgdracut_SCRIPTS):
+ 		-e 's, at udevdir\@,$(udevdir),g' \
+ 		-e 's, at udevruledir\@,$(udevruledir),g' \
+ 		-e 's, at sysconfdir\@,$(sysconfdir),g' \
++		-e 's, at systemdunitdir\@,$(systemdunitdir),g' \
+ 		"$(top_srcdir)/contrib/dracut/90zfs/$@.in" >'$@'
+ 
+ distclean-local::
+diff --git a/contrib/dracut/90zfs/module-setup.sh.in b/contrib/dracut/90zfs/module-setup.sh.in
+index 9eb9f57..301375a 100755
+--- a/contrib/dracut/90zfs/module-setup.sh.in
++++ b/contrib/dracut/90zfs/module-setup.sh.in
+@@ -40,16 +40,22 @@ install() {
+ 	dracut_install awk
+ 	dracut_install head
+ 	inst_hook cmdline 95 "${moddir}/parse-zfs.sh"
+-	inst_hook mount 98 "${moddir}/mount-zfs.sh"
++	if [ -n "$systemdutildir" ] ; then
++		inst_script "${moddir}/zfs-generator.sh" "$systemdutildir"/system-generators/dracut-zfs-generator
++	else
++		inst_hook mount 98 "${moddir}/mount-zfs.sh"
++	fi
+ 	inst_hook shutdown 30 "${moddir}/export-zfs.sh"
+ 
+ 	inst_simple "${moddir}/zfs-lib.sh" "/lib/dracut-zfs-lib.sh"
+ 	if [ -e @sysconfdir@/zfs/zpool.cache ]; then
+ 		inst @sysconfdir@/zfs/zpool.cache
++		type mark_hostonly >/dev/null 2>&1 && mark_hostonly @sysconfdir@/zfs/zpool.cache
+ 	fi
+ 
+ 	if [ -e @sysconfdir@/zfs/vdev_id.conf ]; then
+ 		inst @sysconfdir@/zfs/vdev_id.conf
++		type mark_hostonly >/dev/null 2>&1 && mark_hostonly @sysconfdir@/zfs/vdev_id.conf
+ 	fi
+ 
+ 	# Synchronize initramfs and system hostid
+@@ -58,4 +64,15 @@ install() {
+ 	CC=`hostid | cut -b 5,6`
+ 	DD=`hostid | cut -b 7,8`
+ 	printf "\x${DD}\x${CC}\x${BB}\x${AA}" > "${initdir}/etc/hostid"
++
++	if dracut_module_included "systemd"; then
++		mkdir -p "${initdir}/$systemdsystemunitdir/initrd.target.wants"
++		for _item in scan cache ; do
++			dracut_install @systemdunitdir@/zfs-import-$_item.service
++			if ! [ -L "${initdir}/$systemdsystemunitdir/initrd.target.wants"/zfs-import-$_item.service ]; then
++				ln -s ../zfs-import-$_item.service "${initdir}/$systemdsystemunitdir/initrd.target.wants"/zfs-import-$_item.service
++				type mark_hostonly >/dev/null 2>&1 && mark_hostonly @systemdunitdir@/zfs-import-$_item.service
++			fi
++		done
++	fi
+ }
+diff --git a/contrib/dracut/90zfs/zfs-generator.sh.in b/contrib/dracut/90zfs/zfs-generator.sh.in
+new file mode 100644
+index 0000000..0e0664d
+--- /dev/null
++++ b/contrib/dracut/90zfs/zfs-generator.sh.in
+@@ -0,0 +1,39 @@
++#!/bin/bash
++
++GENERATOR_DIR="$1"
++[ -z "$GENERATOR_DIR" ] && exit 1
++
++[ -f /lib/dracut-lib.sh ] && dracutlib=/lib/dracut-lib.sh
++[ -f /usr/lib/dracut/modules.d/99base/dracut-lib.sh ] && dracutlib=/usr/lib/dracut/modules.d/99base/dracut-lib.sh
++
++type getarg >/dev/null 2>&1 || . "$dracutlib"
++
++[ -z "$root" ]       && root=$(getarg root=)
++[ -z "$rootfstype" ] && rootfstype=$(getarg rootfstype=)
++[ -z "$rootflags" ]  && rootflags=$(getarg rootflags=)
++
++[ "${root##zfs:}" = "${root}" -a "${root##ZFS=}" = "${root}" -a "$rootfstype" != "zfs" ] && exit 0
++
++rootfstype=zfs
++if echo "${rootflags}" | grep -q zfsutil ; then
++    true
++else
++    rootflags=zfsutil
++fi
++
++root="${root##zfs:}"
++root="${root##ZFS=}"
++
++[ -d "$GENERATOR_DIR" ] || mkdir "$GENERATOR_DIR"
++[ -d "$GENERATOR_DIR/sysroot.mount.d" ] || mkdir "$GENERATOR_DIR/sysroot.mount.d"
++
++{
++    echo "[Unit]"
++    echo "After=zfs-import-scan.service"
++    echo "After=zfs-import-cache.service"
++    echo ""
++    echo "[Mount]"
++    echo "What=${root}"
++    echo "Type=${rootfstype}"
++    echo "Options=${rootflags}"
++} > "$GENERATOR_DIR/sysroot.mount.d/zfs-enhancement.conf"
+diff --git a/contrib/dracut/Makefile.am b/contrib/dracut/Makefile.am
+index 35b88c3..1065e5e 100644
+--- a/contrib/dracut/Makefile.am
++++ b/contrib/dracut/Makefile.am
+@@ -1,3 +1,3 @@
+-SUBDIRS = 90zfs
++SUBDIRS = 02zfsexpandknowledge 90zfs
+ 
+ EXTRA_DIST = README.dracut.markdown
+-- 
+2.1.4
+
diff --git a/debian/patches/0032-A-collection-of-dracut-fixes.patch b/debian/patches/0032-A-collection-of-dracut-fixes.patch
new file mode 100644
index 0000000..a9886d4
--- /dev/null
+++ b/debian/patches/0032-A-collection-of-dracut-fixes.patch
@@ -0,0 +1,235 @@
+From d402c18dd60124525b253b27c5018f54a030928d Mon Sep 17 00:00:00 2001
+From: "Manuel Amador (Rudd-O)" <rudd-o at rudd-o.com>
+Date: Sun, 24 Apr 2016 11:35:44 +0000
+Subject: [PATCH 032/530] A collection of dracut fixes
+
+- In older systems without sysroot.mount, import before dracut-mount,
+  and re-enable old dracut mount hook
+- rootflags MUST be present even if the administrator neglected to
+  specify it explicitly
+- Check that mount.zfs exists in sbindir
+- Remove awk and head as (now unused) requirements, add grep, and
+  install the right mount.zfs
+- Eliminate one use of grep in Dracut
+- Use a more accurate grepping statement to identify zfsutil in rootflags
+- Ensure that pooldev is nonempty
+- Properly handle /dev/sd* devices and more
+- Use new -P to get list of zpool devices
+- Bail out of the generator when zfs:AUTO is on the root command line
+- Ignore errors from systemctl trying to load sysroot.mount, we only
+  care about the output
+- Determine which one is the correct initqueuedir at run time.
+- Add a compatibility getargbool for our detection / setup script.
+- Update dracut .gitignore files
+
+Signed-off-by: <Matthew Thode mthode at mthode.org>
+Signed-off-by: Brian Behlendorf <behlendorf1 at llnl.gov>
+Closes #4558
+Closes #4562
+---
+ contrib/dracut/02zfsexpandknowledge/module-setup.sh.in    | 19 +++++++++++--------
+ contrib/dracut/90zfs/.gitignore                       |  1 +
+ contrib/dracut/90zfs/module-setup.sh.in               | 17 +++++++++--------
+ contrib/dracut/90zfs/mount-zfs.sh.in                  | 10 ++++++++++
+ contrib/dracut/90zfs/parse-zfs.sh.in                  |  6 +++++-
+ contrib/dracut/90zfs/zfs-generator.sh.in              | 10 +++++++++-
+ contrib/dracut/90zfs/zfs-lib.sh.in                    | 18 ++++++++++++++++++
+ etc/systemd/system/zfs-import-cache.service.in        |  1 +
+ etc/systemd/system/zfs-import-scan.service.in         |  1 +
+ 10 files changed, 66 insertions(+), 18 deletions(-)
+ create mode 100644 contrib/dracut/02zfsexpandknowledge/.gitignore
+ mode change 100644 => 100755 contrib/dracut/90zfs/zfs-generator.sh.in
+
+Index: zfs/contrib/dracut/02zfsexpandknowledge/module-setup.sh.in
+===================================================================
+--- zfs.orig/contrib/dracut/02zfsexpandknowledge/module-setup.sh.in
++++ zfs/contrib/dracut/02zfsexpandknowledge/module-setup.sh.in
+@@ -15,21 +15,24 @@ get_pool_devices() {
+   local poolconfigoutput
+   local pooldev
+   local prefix
++  local resolved
+   poolconfigtemp=`mktemp`
+-  @sbindir@/zpool list -v -H "$1" > "$poolconfigtemp" 2>&1
++  @sbindir@/zpool list -v -H -P "$1" > "$poolconfigtemp" 2>&1
+   if [ "$?" != "0" ] ; then
+     poolconfigoutput=$(cat "$poolconfigtemp")
+     dinfo "zfsexpandknowledge: pool $1 cannot be listed: $poolconfigoutput"
+   else
+     while read pooldev ; do
+-      for prefix in /dev/disk/* /dev/mapper ; do
+-        if [ -e "$prefix"/"$pooldev" ] ; then
+-          dinfo "zfsexpandknowledge: pool $1 has device $prefix/$pooldev"
+-          echo `readlink -f "$prefix"/"$pooldev"`
+-          break
++        if [ -n "$pooldev" -a -e "$pooldev" ] ; then
++          if [ -h "$pooldev" ] ; then
++              resolved=`readlink -f "$pooldev"`
++          else
++              resolved="$pooldev"
++          fi
++          dinfo "zfsexpandknowledge: pool $1 has device $pooldev (which resolves to $resolved)"
++          echo "$resolved"
+         fi
+-      done
+-    done < <(cat "$poolconfigtemp" | awk -F '\t' 'NR>1 { print $2 }')
++    done < <(cat "$poolconfigtemp" |  awk -F '\t' '/\t\/dev/ { print $2 }')
+   fi
+   rm -f "$poolconfigtemp"
+ }
+Index: zfs/contrib/dracut/90zfs/module-setup.sh.in
+===================================================================
+--- zfs.orig/contrib/dracut/90zfs/module-setup.sh.in
++++ zfs/contrib/dracut/90zfs/module-setup.sh.in
+@@ -5,8 +5,11 @@ check() {
+ 	[ "${1}" = "-d" ] && return 0
+ 
+ 	# Verify the zfs tool chain
+-	which zpool >/dev/null 2>&1 || return 1
+-	which zfs >/dev/null 2>&1 || return 1
++	for tool in "@sbindir@/zpool" "@sbindir@/zfs" "@sbindir@/mount.zfs" ; do
++		test -x "$tool" || return 1
++	done
++	# Verify grep exists
++	which grep >/dev/null 2>&1 || return 1
+ 
+ 	return 0
+ }
+@@ -31,20 +34,18 @@ install() {
+ 	inst_rules @udevruledir@/90-zfs.rules
+ 	inst_rules @udevruledir@/69-vdev.rules
+ 	inst_rules @udevruledir@/60-zvol.rules
++	dracut_install hostid
++	dracut_install grep
+ 	dracut_install @sbindir@/zfs
+ 	dracut_install @sbindir@/zpool
++	dracut_install @sbindir@/mount.zfs
+ 	dracut_install @udevdir@/vdev_id
+ 	dracut_install @udevdir@/zvol_id
+-	dracut_install mount.zfs
+-	dracut_install hostid
+-	dracut_install awk
+-	dracut_install head
+ 	inst_hook cmdline 95 "${moddir}/parse-zfs.sh"
+ 	if [ -n "$systemdutildir" ] ; then
+ 		inst_script "${moddir}/zfs-generator.sh" "$systemdutildir"/system-generators/dracut-zfs-generator
+-	else
+-		inst_hook mount 98 "${moddir}/mount-zfs.sh"
+ 	fi
++	inst_hook mount 98 "${moddir}/mount-zfs.sh"
+ 	inst_hook shutdown 30 "${moddir}/export-zfs.sh"
+ 
+ 	inst_simple "${moddir}/zfs-lib.sh" "/lib/dracut-zfs-lib.sh"
+Index: zfs/contrib/dracut/90zfs/mount-zfs.sh.in
+===================================================================
+--- zfs.orig/contrib/dracut/90zfs/mount-zfs.sh.in
++++ zfs/contrib/dracut/90zfs/mount-zfs.sh.in
+@@ -10,6 +10,16 @@ case "${root}" in
+ 	*) return ;;
+ esac
+ 
++# If sysroot.mount exists, the initial RAM disk configured
++# it to mount ZFS on root.  In that case, we bail early.
++loadstate="$(systemctl --system --show -p LoadState sysroot.mount || true)"
++if [ "${loadstate}" = "LoadState=not-found" -o "${loadstate}" = "" ] ; then
++	info "ZFS: sysroot.mount absent, mounting root with mount-zfs.sh"
++else
++	info "ZFS: sysroot.mount present, delegating root mount to it"
++	return
++fi
++
+ # Delay until all required block devices are present.
+ udevadm settle
+ 
+Index: zfs/contrib/dracut/90zfs/parse-zfs.sh.in
+===================================================================
+--- zfs.orig/contrib/dracut/90zfs/parse-zfs.sh.in
++++ zfs/contrib/dracut/90zfs/parse-zfs.sh.in
+@@ -55,5 +55,9 @@ esac
+ # modules to settle before mounting.
+ if [ ${wait_for_zfs} -eq 1 ]; then
+ 	ln -s /dev/null /dev/root 2>/dev/null
+-	echo '[ -e /dev/zfs ]' > "${hookdir}/initqueue/finished/zfs.sh"
++	initqueuedir="${hookdir}/initqueue/finished"
++	test -d initqueuedir || {
++		initqueuedir="${hookdir}/initqueue-finished"
++	}
++	echo '[ -e /dev/zfs ]' > "${initqueuedir}/zfs.sh"
+ fi
+Index: zfs/contrib/dracut/90zfs/zfs-generator.sh.in
+===================================================================
+--- zfs.orig/contrib/dracut/90zfs/zfs-generator.sh.in
++++ zfs/contrib/dracut/90zfs/zfs-generator.sh.in
+@@ -13,10 +13,18 @@ type getarg >/dev/null 2>&1 || . "$dracu
+ [ -z "$rootflags" ]  && rootflags=$(getarg rootflags=)
+ 
+ [ "${root##zfs:}" = "${root}" -a "${root##ZFS=}" = "${root}" -a "$rootfstype" != "zfs" ] && exit 0
++# If root is set to zfs:AUTO, then we know sysroot.mount will not be generated
++# so we have no need to enhance it.
++# See https://github.com/zfsonlinux/zfs/pull/4558#discussion_r61118952 for details.
++if [ "${root}" = "zfs:AUTO" ] ; then
++  exit 0
++fi
+ 
+ rootfstype=zfs
+-if echo "${rootflags}" | grep -q zfsutil ; then
++if echo "${rootflags}" | grep -Eq '^zfsutil$|^zfsutil,|,zfsutil$|,zfsutil,' ; then
+     true
++elif test -n "${rootflags}" ; then
++    rootflags="zfsutil,${rootflags}"
+ else
+     rootflags=zfsutil
+ fi
+Index: zfs/contrib/dracut/90zfs/zfs-lib.sh.in
+===================================================================
+--- zfs.orig/contrib/dracut/90zfs/zfs-lib.sh.in
++++ zfs/contrib/dracut/90zfs/zfs-lib.sh.in
+@@ -1,6 +1,24 @@
+ #!/bin/sh
+ 
+ command -v getarg >/dev/null || . /lib/dracut-lib.sh
++command -v getargbool >/dev/null || {
++    # Compatibility with older Dracut versions.
++    # With apologies to the Dracut developers.
++    getargbool() {
++        local _b
++        unset _b
++        local _default
++        _default="$1"; shift
++        _b=$(getarg "$@")
++        [ $? -ne 0 -a -z "$_b" ] && _b="$_default"
++        if [ -n "$_b" ]; then
++            [ $_b = "0" ] && return 1
++            [ $_b = "no" ] && return 1
++            [ $_b = "off" ] && return 1
++        fi
++        return 0
++    }
++}
+ 
+ OLDIFS="${IFS}"
+ NEWLINE="
+Index: zfs/etc/systemd/system/zfs-import-cache.service.in
+===================================================================
+--- zfs.orig/etc/systemd/system/zfs-import-cache.service.in
++++ zfs/etc/systemd/system/zfs-import-cache.service.in
+@@ -4,6 +4,7 @@ DefaultDependencies=no
+ Requires=systemd-udev-settle.service
+ After=systemd-udev-settle.service
+ After=cryptsetup.target
++Before=dracut-mount.service
+ After=systemd-remount-fs.service
+ ConditionPathExists=@sysconfdir@/zfs/zpool.cache
+ 
+Index: zfs/etc/systemd/system/zfs-import-scan.service.in
+===================================================================
+--- zfs.orig/etc/systemd/system/zfs-import-scan.service.in
++++ zfs/etc/systemd/system/zfs-import-scan.service.in
+@@ -4,6 +4,7 @@ DefaultDependencies=no
+ Requires=systemd-udev-settle.service
+ After=systemd-udev-settle.service
+ After=cryptsetup.target
++Before=dracut-mount.service
+ ConditionPathExists=!@sysconfdir@/zfs/zpool.cache
+ 
+ [Service]
diff --git a/debian/patches/0034-Fix-the-test-to-use-the-variable.patch b/debian/patches/0034-Fix-the-test-to-use-the-variable.patch
new file mode 100644
index 0000000..89b6aef
--- /dev/null
+++ b/debian/patches/0034-Fix-the-test-to-use-the-variable.patch
@@ -0,0 +1,28 @@
+From dabe1c42f9724ab030dea7fc1db1c924d21a8a6a Mon Sep 17 00:00:00 2001
+From: jyxent <jordanp at gmail.com>
+Date: Fri, 13 May 2016 21:44:03 -0600
+Subject: [PATCH 034/530] Fix the test to use the variable
+
+Signed-off-by: Manuel Amador (Rudd-O) <rudd-o at rudd-o.com>
+Signed-off-by: Brian Behlendorf <behlendorf1 at llnl.gov>
+Closes #4645
+---
+ contrib/dracut/90zfs/parse-zfs.sh.in | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/contrib/dracut/90zfs/parse-zfs.sh.in b/contrib/dracut/90zfs/parse-zfs.sh.in
+index 74a426e..6ca3165 100755
+--- a/contrib/dracut/90zfs/parse-zfs.sh.in
++++ b/contrib/dracut/90zfs/parse-zfs.sh.in
+@@ -56,7 +56,7 @@ esac
+ if [ ${wait_for_zfs} -eq 1 ]; then
+ 	ln -s /dev/null /dev/root 2>/dev/null
+ 	initqueuedir="${hookdir}/initqueue/finished"
+-	test -d initqueuedir || {
++	test -d "${initqueuedir}" || {
+ 		initqueuedir="${hookdir}/initqueue-finished"
+ 	}
+ 	echo '[ -e /dev/zfs ]' > "${initqueuedir}/zfs.sh"
+-- 
+2.1.4
+
diff --git a/debian/patches/0159-Set-proper-dependency-for-string-replacement-targets.patch b/debian/patches/0159-Set-proper-dependency-for-string-replacement-targets.patch
new file mode 100644
index 0000000..4d42301
--- /dev/null
+++ b/debian/patches/0159-Set-proper-dependency-for-string-replacement-targets.patch
@@ -0,0 +1,151 @@
+From 5b1bc1a1d8ae284f834f239ab0309c6ce96ab74f Mon Sep 17 00:00:00 2001
+From: Chunwei Chen <david.chen at osnexus.com>
+Date: Fri, 29 Jul 2016 16:35:33 -0700
+Subject: [PATCH 159/530] Set proper dependency for string replacement targets
+
+A lot of string replacement target don't have dependency or incorrect
+dependency. We setup proper dependency by pattern rules.
+
+Signed-off-by: Chunwei Chen <david.chen at osnexus.com>
+Signed-off-by: Brian Behlendorf <behlendorf1 at llnl.gov>
+Closes #4908
+---
+ contrib/dracut/02zfsexpandknowledge/Makefile.am |  4 ++--
+ contrib/dracut/90zfs/Makefile.am                |  4 ++--
+ etc/init.d/Makefile.am                          |  4 ++--
+ etc/modules-load.d/Makefile.am                  |  4 ++--
+ etc/systemd/system/Makefile.am                  | 11 ++---------
+ udev/rules.d/Makefile.am                        |  4 ++--
+ 6 files changed, 12 insertions(+), 19 deletions(-)
+
+diff --git a/contrib/dracut/02zfsexpandknowledge/Makefile.am b/contrib/dracut/02zfsexpandknowledge/Makefile.am
+index 0a2170b..a5c567c 100644
+--- a/contrib/dracut/02zfsexpandknowledge/Makefile.am
++++ b/contrib/dracut/02zfsexpandknowledge/Makefile.am
+@@ -5,7 +5,7 @@ pkgdracut_SCRIPTS = \
+ EXTRA_DIST = \
+ 	$(top_srcdir)/contrib/dracut/02zfsexpandknowledge/module-setup.sh.in
+ 
+-$(pkgdracut_SCRIPTS):
++$(pkgdracut_SCRIPTS):%:%.in
+ 	-$(SED) -e 's, at bindir\@,$(bindir),g' \
+ 		-e 's, at sbindir\@,$(sbindir),g' \
+ 		-e 's, at datadir\@,$(datadir),g' \
+@@ -13,7 +13,7 @@ $(pkgdracut_SCRIPTS):
+ 		-e 's, at udevdir\@,$(udevdir),g' \
+ 		-e 's, at udevruledir\@,$(udevruledir),g' \
+ 		-e 's, at sysconfdir\@,$(sysconfdir),g' \
+-		"$(top_srcdir)/contrib/dracut/02zfsexpandknowledge/$@.in" >'$@'
++		$< >'$@'
+ 
+ clean-local::
+ 	-$(RM) $(pkgdracut_SCRIPTS)
+diff --git a/contrib/dracut/90zfs/Makefile.am b/contrib/dracut/90zfs/Makefile.am
+index f81d6c3..2777a81 100644
+--- a/contrib/dracut/90zfs/Makefile.am
++++ b/contrib/dracut/90zfs/Makefile.am
+@@ -15,14 +15,14 @@ EXTRA_DIST = \
+ 	$(top_srcdir)/contrib/dracut/90zfs/zfs-generator.sh.in \
+ 	$(top_srcdir)/contrib/dracut/90zfs/zfs-lib.sh.in
+ 
+-$(pkgdracut_SCRIPTS):
++$(pkgdracut_SCRIPTS):%:%.in
+ 	-$(SED) -e 's, at bindir\@,$(bindir),g' \
+ 		-e 's, at sbindir\@,$(sbindir),g' \
+ 		-e 's, at udevdir\@,$(udevdir),g' \
+ 		-e 's, at udevruledir\@,$(udevruledir),g' \
+ 		-e 's, at sysconfdir\@,$(sysconfdir),g' \
+ 		-e 's, at systemdunitdir\@,$(systemdunitdir),g' \
+-		"$(top_srcdir)/contrib/dracut/90zfs/$@.in" >'$@'
++		$< >'$@'
+ 
+ distclean-local::
+ 	-$(RM) $(pkgdracut_SCRIPTS)
+diff --git a/etc/init.d/Makefile.am b/etc/init.d/Makefile.am
+index c6e29d1..247db0a 100644
+--- a/etc/init.d/Makefile.am
++++ b/etc/init.d/Makefile.am
+@@ -15,7 +15,7 @@ EXTRA_DIST = \
+ 	$(top_srcdir)/etc/init.d/zfs-zed.in \
+ 	$(top_srcdir)/etc/init.d/zfs.in
+ 
+-$(init_SCRIPTS) $(initconf_SCRIPTS) $(initcommon_SCRIPTS): $(EXTRA_DIST)
++$(init_SCRIPTS) $(initconf_SCRIPTS) $(initcommon_SCRIPTS):%:%.in
+ 	-(if [ -e /etc/debian_version ]; then \
+ 		NFS_SRV=nfs-kernel-server; \
+ 	  else \
+@@ -36,7 +36,7 @@ $(init_SCRIPTS) $(initconf_SCRIPTS) $(initcommon_SCRIPTS): $(EXTRA_DIST)
+ 		 -e 's, at runstatedir\@,$(runstatedir),g' \
+ 		 -e "s, at SHELL\@,$$SHELL,g" \
+ 		 -e "s, at NFS_SRV\@,$$NFS_SRV,g" \
+-		 "$(top_srcdir)/etc/init.d/$@.in" >'$@'; \
++		 $< >'$@'; \
+ 	  [ '$@' = 'zfs-functions' -o '$@' = 'zfs' ] || \
+ 		chmod +x '$@')
+ 
+diff --git a/etc/modules-load.d/Makefile.am b/etc/modules-load.d/Makefile.am
+index a6780e1..58c7acd 100644
+--- a/etc/modules-load.d/Makefile.am
++++ b/etc/modules-load.d/Makefile.am
+@@ -4,10 +4,10 @@ modulesload_DATA = \
+ EXTRA_DIST = \
+ 	$(top_srcdir)/etc/modules-load.d/zfs.conf.in
+ 
+-$(modulesload_DATA):
++$(modulesload_DATA):%:%.in
+ 	-$(SED) \
+ 		-e '' \
+-		"$(top_srcdir)/etc/modules-load.d/$@.in" >'$@'
++		$< >'$@'
+ 
+ distclean-local::
+ 	-$(RM) $(modulesload_DATA)
+diff --git a/etc/systemd/system/Makefile.am b/etc/systemd/system/Makefile.am
+index f7023df..b097497 100644
+--- a/etc/systemd/system/Makefile.am
++++ b/etc/systemd/system/Makefile.am
+@@ -18,19 +18,12 @@ EXTRA_DIST = \
+ 	$(top_srcdir)/etc/systemd/system/zfs.target.in \
+ 	$(top_srcdir)/etc/systemd/system/50-zfs.preset.in
+ 
+-$(systemdunit_DATA):
++$(systemdunit_DATA) $(systemdpreset_DATA):%:%.in
+ 	-$(SED) -e 's, at bindir\@,$(bindir),g' \
+ 		-e 's, at runstatedir\@,$(runstatedir),g' \
+ 		-e 's, at sbindir\@,$(sbindir),g' \
+ 		-e 's, at sysconfdir\@,$(sysconfdir),g' \
+-		"$(top_srcdir)/etc/systemd/system/$@.in" >'$@'
+-
+-$(systemdpreset_DATA):
+-	-$(SED) -e 's, at bindir\@,$(bindir),g' \
+-		-e 's, at runstatedir\@,$(runstatedir),g' \
+-		-e 's, at sbindir\@,$(sbindir),g' \
+-		-e 's, at sysconfdir\@,$(sysconfdir),g' \
+-		"$(top_srcdir)/etc/systemd/system/$@.in" >'$@'
++		$< >'$@'
+ 
+ distclean-local::
+ 	-$(RM) $(systemdunit_DATA) $(systemdpreset_DATA)
+diff --git a/udev/rules.d/Makefile.am b/udev/rules.d/Makefile.am
+index febbb48..f79ea4b 100644
+--- a/udev/rules.d/Makefile.am
++++ b/udev/rules.d/Makefile.am
+@@ -8,13 +8,13 @@ EXTRA_DIST = \
+ 	$(top_srcdir)/udev/rules.d/60-zvol.rules.in \
+ 	$(top_srcdir)/udev/rules.d/90-zfs.rules.in
+ 
+-$(udevrule_DATA):
++$(udevrule_DATA):%:%.in
+ 	-$(SED) -e 's, at bindir\@,$(bindir),g' \
+ 		-e 's, at sbindir\@,$(sbindir),g' \
+ 		-e 's, at udevdir\@,$(udevdir),g' \
+ 		-e 's, at udevruledir\@,$(udevruledir),g' \
+ 		-e 's, at sysconfdir\@,$(sysconfdir),g' \
+-		"$(top_srcdir)/udev/rules.d/$@.in" > '$@'
++		$< > '$@'
+ 
+ distclean-local::
+ 	-$(RM) $(udevrule_DATA)
+-- 
+2.1.4
+
diff --git a/debian/patches/0219-Adapt-genkernel-fix-for-zfsonlinux-zfs-4749-to-zfs-d.patch b/debian/patches/0219-Adapt-genkernel-fix-for-zfsonlinux-zfs-4749-to-zfs-d.patch
new file mode 100644
index 0000000..8cea16b
--- /dev/null
+++ b/debian/patches/0219-Adapt-genkernel-fix-for-zfsonlinux-zfs-4749-to-zfs-d.patch
@@ -0,0 +1,34 @@
+From 61c73494394fc9de9283b3fd4f00bcdf4bd300a7 Mon Sep 17 00:00:00 2001
+From: Moritz Maxeiner <moritz at ucworks.org>
+Date: Thu, 1 Sep 2016 18:15:10 +0200
+Subject: [PATCH 219/530] Adapt genkernel fix for zfsonlinux/zfs#4749 to zfs
+ dracut module
+
+Signed-off-by: Moritz Maxeiner <moritz at ucworks.org>
+Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
+Closes #4749
+Closes #5058
+---
+ contrib/dracut/90zfs/module-setup.sh.in | 6 ++++++
+ 1 file changed, 6 insertions(+)
+
+diff --git a/contrib/dracut/90zfs/module-setup.sh.in b/contrib/dracut/90zfs/module-setup.sh.in
+index 70eac87..6dff2a8 100755
+--- a/contrib/dracut/90zfs/module-setup.sh.in
++++ b/contrib/dracut/90zfs/module-setup.sh.in
+@@ -38,6 +38,12 @@ install() {
+ 	dracut_install grep
+ 	dracut_install @sbindir@/zfs
+ 	dracut_install @sbindir@/zpool
++	# Include libgcc_s.so.1 to workaround zfsonlinux/zfs#4749
++	if type gcc-config 2>&1 1>/dev/null; then
++		dracut_install "/usr/lib/gcc/$(s=$(gcc-config -c); echo ${s%-*}/${s##*-})/libgcc_s.so.1"
++	else
++		dracut_install /usr/lib/gcc/*/*/libgcc_s.so.1
++	fi
+ 	dracut_install @sbindir@/mount.zfs
+ 	dracut_install @udevdir@/vdev_id
+ 	dracut_install @udevdir@/zvol_id
+-- 
+2.1.4
+
diff --git a/debian/patches/0220-zfs-dracut-module-should-not-assume-systemd-presence.patch b/debian/patches/0220-zfs-dracut-module-should-not-assume-systemd-presence.patch
new file mode 100644
index 0000000..dfe51a8
--- /dev/null
+++ b/debian/patches/0220-zfs-dracut-module-should-not-assume-systemd-presence.patch
@@ -0,0 +1,45 @@
+From 8516203d53380bc32f62827afd0c13d16337c4e6 Mon Sep 17 00:00:00 2001
+From: Moritz Maxeiner <moritz at ucworks.org>
+Date: Thu, 1 Sep 2016 18:29:31 +0200
+Subject: [PATCH 220/530] zfs dracut module should not assume systemd presence
+
+Signed-off-by: Moritz Maxeiner <moritz at ucworks.org>
+Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
+Closes #4749
+Closes #5058
+---
+ contrib/dracut/90zfs/mount-zfs.sh.in | 18 ++++++++++--------
+ 1 file changed, 10 insertions(+), 8 deletions(-)
+
+diff --git a/contrib/dracut/90zfs/mount-zfs.sh.in b/contrib/dracut/90zfs/mount-zfs.sh.in
+index 43862fa..51e107b 100755
+--- a/contrib/dracut/90zfs/mount-zfs.sh.in
++++ b/contrib/dracut/90zfs/mount-zfs.sh.in
+@@ -10,14 +10,16 @@ case "${root}" in
+ 	*) return ;;
+ esac
+ 
+-# If sysroot.mount exists, the initial RAM disk configured
+-# it to mount ZFS on root.  In that case, we bail early.
+-loadstate="$(systemctl --system --show -p LoadState sysroot.mount || true)"
+-if [ "${loadstate}" = "LoadState=not-found" -o "${loadstate}" = "" ] ; then
+-	info "ZFS: sysroot.mount absent, mounting root with mount-zfs.sh"
+-else
+-	info "ZFS: sysroot.mount present, delegating root mount to it"
+-	return
++if command -v systemctl >/dev/null; then
++	# If sysroot.mount exists, the initial RAM disk configured
++	# it to mount ZFS on root.  In that case, we bail early.
++	loadstate="$(systemctl --system --show -p LoadState sysroot.mount || true)"
++	if [ "${loadstate}" = "LoadState=not-found" -o "${loadstate}" = "" ] ; then
++		info "ZFS: sysroot.mount absent, mounting root with mount-zfs.sh"
++	else
++		info "ZFS: sysroot.mount present, delegating root mount to it"
++		return
++	fi
+ fi
+ 
+ # Delay until all required block devices are present.
+-- 
+2.1.4
+
diff --git a/debian/patches/0246-Fix-regression-that-broke-dracut-initramfs-generatio.patch b/debian/patches/0246-Fix-regression-that-broke-dracut-initramfs-generatio.patch
new file mode 100644
index 0000000..dcb451a
--- /dev/null
+++ b/debian/patches/0246-Fix-regression-that-broke-dracut-initramfs-generatio.patch
@@ -0,0 +1,49 @@
+From 70cc394d919fb576bc23d3dc2552a55a4c9d1c24 Mon Sep 17 00:00:00 2001
+From: Moritz Maxeiner <moritz at ucworks.org>
+Date: Wed, 21 Sep 2016 22:35:16 +0200
+Subject: [PATCH 246/530] Fix regression that broke dracut initramfs generation
+
+Based upon @ryao's initial fix for 1c73494394fc9de9283b3fd4f00bcdf4bd300a7
+( 5e9843405f63fdabe76e87b92b81a127d488abc7 ) this one also uses
+`command -v` instead of `type`, but additionally only applies the
+fix to close zfsonlinux/zfs#4749 when `libgcc_s.so.1` has not been included
+by dracut automatically (verified by whether `zpool` links directly to
+`libgcc_s.so`), as well as change the fallback option to match `libgcc_s.so*`.
+
+Tested-by: Ben Jencks <ben at bjencks.net>
+Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
+Signed-off-by: Moritz Maxeiner <moritz at ucworks.org>
+Closes #5089
+Closed #5138
+---
+ contrib/dracut/90zfs/module-setup.sh.in | 12 +++++++++---
+ 1 file changed, 9 insertions(+), 3 deletions(-)
+
+diff --git a/contrib/dracut/90zfs/module-setup.sh.in b/contrib/dracut/90zfs/module-setup.sh.in
+index 6dff2a8..9c88b32 100755
+--- a/contrib/dracut/90zfs/module-setup.sh.in
++++ b/contrib/dracut/90zfs/module-setup.sh.in
+@@ -38,11 +38,17 @@ install() {
+ 	dracut_install grep
+ 	dracut_install @sbindir@/zfs
+ 	dracut_install @sbindir@/zpool
+-	# Include libgcc_s.so.1 to workaround zfsonlinux/zfs#4749
+-	if type gcc-config 2>&1 1>/dev/null; then
++	# Workaround for zfsonlinux/zfs#4749 by ensuring libgcc_s.so(.1) is included
++	if [[ -n "$(ldd @sbindir@/zpool | grep -F 'libgcc_s.so')" ]]; then
++		# Dracut will have already tracked and included it
++		:;
++	elif command -v gcc-config 2>&1 1>/dev/null; then
++		# On systems with gcc-config (Gentoo, Funtoo, etc.):
++		# Use the current profile to resolve the appropriate path
+ 		dracut_install "/usr/lib/gcc/$(s=$(gcc-config -c); echo ${s%-*}/${s##*-})/libgcc_s.so.1"
+ 	else
+-		dracut_install /usr/lib/gcc/*/*/libgcc_s.so.1
++		# Fallback: Guess the path and include all matches
++		dracut_install /usr/lib/gcc/*/*/libgcc_s.so*
+ 	fi
+ 	dracut_install @sbindir@/mount.zfs
+ 	dracut_install @udevdir@/vdev_id
+-- 
+2.1.4
+
diff --git a/debian/patches/0296-Use-a-different-technique-to-detect-whether-to-mount.patch b/debian/patches/0296-Use-a-different-technique-to-detect-whether-to-mount.patch
new file mode 100644
index 0000000..45eb55c
--- /dev/null
+++ b/debian/patches/0296-Use-a-different-technique-to-detect-whether-to-mount.patch
@@ -0,0 +1,177 @@
+From b0f578a8073da49dd0af879944a1b8e8dfd6db56 Mon Sep 17 00:00:00 2001
+From: Rudd-O <rudd-o at rudd-o.com>
+Date: Thu, 6 Oct 2016 17:26:47 +0000
+Subject: [PATCH 296/530] Use a different technique to detect whether to
+ mount-zfs
+
+The behavior of the Dracut module was very wrong before.
+
+The correct behavior: initramfs should not run `zfs-mount` to completion
+if the two generator files exist.  If, however, one of them is missing,
+it indicates one of three cases:
+
+* The kernel command line did not specify a root ZFS file system, and
+  another Dracut module is already handling root mount (via systemd).
+  `mount-zfs` can run, but it will do nothing.
+* There is no systemd to run `sysroot.mount` to begin with.
+  `mount-zfs` must run.
+* The root parameter is zfs:AUTO, which cannot be run in sysroot.mount.
+  `mount-zfs` must run.
+
+In any of these three cases, it is safe to run `zfs-mount` to completion.
+
+`zfs-mount` must also delete itself if it determines it should not run,
+or else Dracut will do the insane thing of running it over and over again.
+Literally, the definition of insanity, doing the same thing that did not
+work before, expecting different results.  Doing that may have had a great
+result before, when we had a race between devices appearing and pools
+being mounted, and `mount-zfs` was tasked with the full responsibility
+of importing the needed pool, but nowadays it is wrong behavior and
+should be suppressed.
+
+I deduced that self-deletion was the correct thing to do by looking at
+other Dracut code, because (as we all are very fully aware of) Dracut
+is entirely, ahem, "implementation-defined".
+
+Tested-by: @wphilips
+Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
+Signed-off-by: Manuel Amador (Rudd-O) <rudd-o at rudd-o.com>
+Closes #5157
+Closes #5204
+---
+ contrib/dracut/90zfs/mount-zfs.sh.in     | 37 ++++++++++++++++++++++----------
+ contrib/dracut/90zfs/zfs-generator.sh.in | 34 ++++++++++++++++++++++-------
+ 2 files changed, 52 insertions(+), 19 deletions(-)
+
+diff --git a/contrib/dracut/90zfs/mount-zfs.sh.in b/contrib/dracut/90zfs/mount-zfs.sh.in
+index 51e107b..3b6be31 100755
+--- a/contrib/dracut/90zfs/mount-zfs.sh.in
++++ b/contrib/dracut/90zfs/mount-zfs.sh.in
+@@ -10,17 +10,29 @@ case "${root}" in
+ 	*) return ;;
+ esac
+ 
+-if command -v systemctl >/dev/null; then
+-	# If sysroot.mount exists, the initial RAM disk configured
+-	# it to mount ZFS on root.  In that case, we bail early.
+-	loadstate="$(systemctl --system --show -p LoadState sysroot.mount || true)"
+-	if [ "${loadstate}" = "LoadState=not-found" -o "${loadstate}" = "" ] ; then
+-		info "ZFS: sysroot.mount absent, mounting root with mount-zfs.sh"
+-	else
+-		info "ZFS: sysroot.mount present, delegating root mount to it"
+-		return
+-	fi
++GENERATOR_FILE=/run/systemd/generator/sysroot.mount
++GENERATOR_EXTENSION=/run/systemd/generator/sysroot.mount.d/zfs-enhancement.conf
++
++if [ -e "$GENERATOR_FILE" -a -e "$GENERATOR_EXTENSION" ] ; then
++	# If the ZFS sysroot.mount flag exists, the initial RAM disk configured
++	# it to mount ZFS on root.  In that case, we bail early.  This flag
++	# file gets created by the zfs-generator program upon successful run.
++	info "ZFS: There is a sysroot.mount and zfs-generator has extended it."
++	info "ZFS: Delegating root mount to sysroot.mount."
++	# Let us tell the initrd to run on shutdown.
++	# We have a shutdown hook to run
++	# because we imported the pool.
++	need_shutdown
++	# We now prevent Dracut from running this thing again.
++	for zfsmounthook in "$hookdir"/mount/*zfs* ; do
++		if [ -f "$zfsmounthook" ] ; then
++			rm -f "$zfsmounthook"
++		fi
++	done
++	return
+ fi
++info "ZFS: No sysroot.mount exists or zfs-generator did not extend it."
++info "ZFS: Mounting root with the traditional mount-zfs.sh instead."
+ 
+ # Delay until all required block devices are present.
+ udevadm settle
+@@ -45,6 +57,10 @@ ZFS_DATASET="${ZFS_DATASET:-${root#zfs:}}"
+ ZFS_POOL="${ZFS_DATASET%%/*}"
+ 
+ if import_pool "${ZFS_POOL}" ; then
++	# Let us tell the initrd to run on shutdown.
++	# We have a shutdown hook to run
++	# because we imported the pool.
++	need_shutdown
+ 	info "ZFS: Mounting dataset ${ZFS_DATASET}..."
+ 	if mount_dataset "${ZFS_DATASET}" ; then
+ 		ROOTFS_MOUNTED=yes
+@@ -53,4 +69,3 @@ if import_pool "${ZFS_POOL}" ; then
+ fi
+ 
+ rootok=0
+-need_shutdown
+diff --git a/contrib/dracut/90zfs/zfs-generator.sh.in b/contrib/dracut/90zfs/zfs-generator.sh.in
+index aa12fb8..c6384f5 100755
+--- a/contrib/dracut/90zfs/zfs-generator.sh.in
++++ b/contrib/dracut/90zfs/zfs-generator.sh.in
+@@ -1,21 +1,32 @@
+ #!/bin/bash
+ 
++echo "zfs-generator: starting" >> /dev/kmsg
++
+ GENERATOR_DIR="$1"
+-[ -z "$GENERATOR_DIR" ] && exit 1
++[ -n "$GENERATOR_DIR" ] || {
++    echo "zfs-generator: no generator directory specified, exiting" >> /dev/kmsg
++    exit 1
++}
+ 
+ [ -f /lib/dracut-lib.sh ] && dracutlib=/lib/dracut-lib.sh
+ [ -f /usr/lib/dracut/modules.d/99base/dracut-lib.sh ] && dracutlib=/usr/lib/dracut/modules.d/99base/dracut-lib.sh
+ 
+-type getarg >/dev/null 2>&1 || . "$dracutlib"
++type getarg >/dev/null 2>&1 || {
++    echo "zfs-generator: loading Dracut library from $dracutlib" >> /dev/kmsg
++    . "$dracutlib"
++}
+ 
+ [ -z "$root" ]       && root=$(getarg root=)
+ [ -z "$rootfstype" ] && rootfstype=$(getarg rootfstype=)
+ [ -z "$rootflags" ]  && rootflags=$(getarg rootflags=)
+ 
++# If root is not ZFS= or zfs: or rootfstype is not zfs
++# then we are not supposed to handle it.
+ [ "${root##zfs:}" = "${root}" -a "${root##ZFS=}" = "${root}" -a "$rootfstype" != "zfs" ] && exit 0
+-# If root is set to zfs:AUTO, then we know sysroot.mount will not be generated
+-# so we have no need to enhance it.
+-# See https://github.com/zfsonlinux/zfs/pull/4558#discussion_r61118952 for details.
++# If root is set to zfs:AUTO, then we are also not
++# supposed to handle it, and it should be handled
++# by the traditional Dracut mount hook.
++# See https://github.com/zfsonlinux/zfs/pull/4558#discussion_r61118952
+ if [ "${root}" = "zfs:AUTO" ] ; then
+   exit 0
+ fi
+@@ -32,16 +43,23 @@ fi
+ root="${root##zfs:}"
+ root="${root##ZFS=}"
+ 
++echo "zfs-generator: writing extension for sysroot.mount to $GENERATOR_DIR"/sysroot.mount.d/zfs-enhancement.conf >> /dev/kmsg
++
+ [ -d "$GENERATOR_DIR" ] || mkdir "$GENERATOR_DIR"
+-[ -d "$GENERATOR_DIR/sysroot.mount.d" ] || mkdir "$GENERATOR_DIR/sysroot.mount.d"
++[ -d "$GENERATOR_DIR"/sysroot.mount.d ] || mkdir "$GENERATOR_DIR"/sysroot.mount.d
+ 
+ {
+     echo "[Unit]"
++    echo "Before=initrd-root-fs.target"
+     echo "After=zfs-import-scan.service"
+     echo "After=zfs-import-cache.service"
+-    echo ""
+     echo "[Mount]"
+     echo "What=${root}"
+     echo "Type=${rootfstype}"
+     echo "Options=${rootflags}"
+-} > "$GENERATOR_DIR/sysroot.mount.d/zfs-enhancement.conf"
++} > "$GENERATOR_DIR"/sysroot.mount.d/zfs-enhancement.conf
++
++[ -d "$GENERATOR_DIR"/initrd-root-fs.target.requires ] || mkdir -p "$GENERATOR_DIR"/initrd-root-fs.target.requires
++ln -s ../sysroot.mount "$GENERATOR_DIR"/initrd-root-fs.target.requires/sysroot.mount
++
++echo "zfs-generator: finished" >> /dev/kmsg
+-- 
+2.1.4
+
diff --git a/debian/patches/0334-Use-F-to-export-pools-so-as-not-to-dirty-up-device-l.patch b/debian/patches/0334-Use-F-to-export-pools-so-as-not-to-dirty-up-device-l.patch
new file mode 100644
index 0000000..03fcbe5
--- /dev/null
+++ b/debian/patches/0334-Use-F-to-export-pools-so-as-not-to-dirty-up-device-l.patch
@@ -0,0 +1,90 @@
+From 7e8a2d0b755ea67291d3f576069706e43abc5e31 Mon Sep 17 00:00:00 2001
+From: Rudd-O <rudd-o at rudd-o.com>
+Date: Sun, 16 Oct 2016 03:30:53 +0000
+Subject: [PATCH 334/530] Use -F to export pools so as not to dirty up device
+ labels
+
+Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
+Signed-off-by: Manuel Amador (Rudd-O) <rudd-o at rudd-o.com>
+Closes #5228
+Closes #5238
+---
+ contrib/dracut/90zfs/export-zfs.sh.in   | 15 ++++++++-------
+ contrib/dracut/90zfs/module-setup.sh.in |  2 +-
+ contrib/dracut/90zfs/mount-zfs.sh.in    |  2 +-
+ contrib/dracut/90zfs/zfs-lib.sh.in      |  2 +-
+ 4 files changed, 11 insertions(+), 10 deletions(-)
+
+diff --git a/contrib/dracut/90zfs/export-zfs.sh.in b/contrib/dracut/90zfs/export-zfs.sh.in
+index 393753f..8747c1c 100755
+--- a/contrib/dracut/90zfs/export-zfs.sh.in
++++ b/contrib/dracut/90zfs/export-zfs.sh.in
+@@ -4,18 +4,19 @@
+ 
+ _do_zpool_export() {
+ 	local ret=0
++	local errs=""
+ 	local final="${1}"
+-	local opts=""
+ 
+-	if [ "x${final}" != "x" ]; then
+-		opts="-f"
++	info "ZFS: Exporting ZFS storage pools..."
++	errs=$(export_all -F 2>&1)
++	ret=$?
++	[ -z "${errs}" ] || echo "${errs}" | vwarn
++	if [ "x${ret}" != "x0" ]; then
++		info "ZFS: There was a problem exporting pools."
+ 	fi
+ 
+-	info "Exporting ZFS storage pools."
+-	export_all ${opts} || ret=$?
+-
+ 	if [ "x${final}" != "x" ]; then
+-		info "zpool list"
++		info "ZFS: pool list"
+ 		zpool list 2>&1 | vinfo
+ 	fi
+ 
+diff --git a/contrib/dracut/90zfs/module-setup.sh.in b/contrib/dracut/90zfs/module-setup.sh.in
+index 9c88b32..240847a 100755
+--- a/contrib/dracut/90zfs/module-setup.sh.in
++++ b/contrib/dracut/90zfs/module-setup.sh.in
+@@ -58,7 +58,7 @@ install() {
+ 		inst_script "${moddir}/zfs-generator.sh" "$systemdutildir"/system-generators/dracut-zfs-generator
+ 	fi
+ 	inst_hook mount 98 "${moddir}/mount-zfs.sh"
+-	inst_hook shutdown 30 "${moddir}/export-zfs.sh"
++	inst_hook shutdown 20 "${moddir}/export-zfs.sh"
+ 
+ 	inst_simple "${moddir}/zfs-lib.sh" "/lib/dracut-zfs-lib.sh"
+ 	if [ -e @sysconfdir@/zfs/zpool.cache ]; then
+diff --git a/contrib/dracut/90zfs/mount-zfs.sh.in b/contrib/dracut/90zfs/mount-zfs.sh.in
+index 3b6be31..db5ccdd 100755
+--- a/contrib/dracut/90zfs/mount-zfs.sh.in
++++ b/contrib/dracut/90zfs/mount-zfs.sh.in
+@@ -44,7 +44,7 @@ if [ "${root}" = "zfs:AUTO" ] ; then
+ 		ZFS_DATASET="$(find_bootfs)"
+ 		if [ $? -ne 0 ] ; then
+ 			warn "ZFS: No bootfs attribute found in importable pools."
+-			export_all || export_all "-f"
++			export_all -F
+ 
+ 			rootok=0
+ 			return 1
+diff --git a/contrib/dracut/90zfs/zfs-lib.sh.in b/contrib/dracut/90zfs/zfs-lib.sh.in
+index c822ddb..c988dfe 100755
+--- a/contrib/dracut/90zfs/zfs-lib.sh.in
++++ b/contrib/dracut/90zfs/zfs-lib.sh.in
+@@ -90,7 +90,7 @@ mount_dataset() {
+ # export_all OPTS
+ #   exports all imported zfs pools.
+ export_all() {
+-	local opts="${1}"
++	local opts="${@}"
+ 	local ret=0
+ 
+ 	IFS="${NEWLINE}"
+-- 
+2.1.4
+
diff --git a/debian/patches/0336-Properly-use-the-Dracut-cleanup-hook-to-order-pool-s.patch b/debian/patches/0336-Properly-use-the-Dracut-cleanup-hook-to-order-pool-s.patch
new file mode 100644
index 0000000..e5142cb
--- /dev/null
+++ b/debian/patches/0336-Properly-use-the-Dracut-cleanup-hook-to-order-pool-s.patch
@@ -0,0 +1,101 @@
+From f8e87e205c745c1e360230ac9c7631eb4632acfa Mon Sep 17 00:00:00 2001
+From: Rudd-O <rudd-o at rudd-o.com>
+Date: Mon, 17 Oct 2016 18:51:15 +0000
+Subject: [PATCH 336/530] Properly use the Dracut cleanup hook to order pool
+ shutdown
+
+When Dracut starts up, it needs to determine whether a pool will remain
+"hanging open" before the system shuts off. In such a case, then the
+code to clean up the pool (using the previous export -F work) must
+be invoked. Since Dracut has had a recent change that makes
+mount-zfs.sh simply not run when the root dataset is already mounted,
+we must use the cleanup hook to order Dracut to do shutdown cleanup.
+
+Important note: this code will not accomplish its stated goal until this
+bug is fixed: https://bugzilla.redhat.com/show_bug.cgi?id=1385432
+
+That bug impacts more than just ZFS. It impacts LUKS, dmraid, and
+unmount during poweroff. It is a Fedora-wide bug.
+
+Reviewed-by: Brian Behlendorf <behlendorf1 at llnl.gov>
+Signed-off-by: Manuel Amador (Rudd-O) <rudd-o at rudd-o.com>
+Closes #5287
+---
+ contrib/dracut/90zfs/Makefile.am            |  2 ++
+ contrib/dracut/90zfs/module-setup.sh.in     |  1 +
+ contrib/dracut/90zfs/mount-zfs.sh.in        |  2 --
+ contrib/dracut/90zfs/zfs-needshutdown.sh.in | 10 ++++++++++
+ 4 files changed, 13 insertions(+), 2 deletions(-)
+ create mode 100644 contrib/dracut/90zfs/zfs-needshutdown.sh.in
+
+diff --git a/contrib/dracut/90zfs/Makefile.am b/contrib/dracut/90zfs/Makefile.am
+index 2777a81..243a520 100644
+--- a/contrib/dracut/90zfs/Makefile.am
++++ b/contrib/dracut/90zfs/Makefile.am
+@@ -5,6 +5,7 @@ pkgdracut_SCRIPTS = \
+ 	mount-zfs.sh \
+ 	parse-zfs.sh \
+ 	zfs-generator.sh \
++	zfs-needshutdown.sh \
+ 	zfs-lib.sh
+ 
+ EXTRA_DIST = \
+@@ -13,6 +14,7 @@ EXTRA_DIST = \
+ 	$(top_srcdir)/contrib/dracut/90zfs/mount-zfs.sh.in \
+ 	$(top_srcdir)/contrib/dracut/90zfs/parse-zfs.sh.in \
+ 	$(top_srcdir)/contrib/dracut/90zfs/zfs-generator.sh.in \
++	$(top_srcdir)/contrib/dracut/90zfs/zfs-needshutdown.sh.in \
+ 	$(top_srcdir)/contrib/dracut/90zfs/zfs-lib.sh.in
+ 
+ $(pkgdracut_SCRIPTS):%:%.in
+diff --git a/contrib/dracut/90zfs/module-setup.sh.in b/contrib/dracut/90zfs/module-setup.sh.in
+index 240847a..a653b50 100755
+--- a/contrib/dracut/90zfs/module-setup.sh.in
++++ b/contrib/dracut/90zfs/module-setup.sh.in
+@@ -58,6 +58,7 @@ install() {
+ 		inst_script "${moddir}/zfs-generator.sh" "$systemdutildir"/system-generators/dracut-zfs-generator
+ 	fi
+ 	inst_hook mount 98 "${moddir}/mount-zfs.sh"
++	inst_hook cleanup 99 "${moddir}/zfs-needshutdown.sh"
+ 	inst_hook shutdown 20 "${moddir}/export-zfs.sh"
+ 
+ 	inst_simple "${moddir}/zfs-lib.sh" "/lib/dracut-zfs-lib.sh"
+diff --git a/contrib/dracut/90zfs/mount-zfs.sh.in b/contrib/dracut/90zfs/mount-zfs.sh.in
+index db5ccdd..e7f2177 100755
+--- a/contrib/dracut/90zfs/mount-zfs.sh.in
++++ b/contrib/dracut/90zfs/mount-zfs.sh.in
+@@ -22,7 +22,6 @@ if [ -e "$GENERATOR_FILE" -a -e "$GENERATOR_EXTENSION" ] ; then
+ 	# Let us tell the initrd to run on shutdown.
+ 	# We have a shutdown hook to run
+ 	# because we imported the pool.
+-	need_shutdown
+ 	# We now prevent Dracut from running this thing again.
+ 	for zfsmounthook in "$hookdir"/mount/*zfs* ; do
+ 		if [ -f "$zfsmounthook" ] ; then
+@@ -60,7 +59,6 @@ if import_pool "${ZFS_POOL}" ; then
+ 	# Let us tell the initrd to run on shutdown.
+ 	# We have a shutdown hook to run
+ 	# because we imported the pool.
+-	need_shutdown
+ 	info "ZFS: Mounting dataset ${ZFS_DATASET}..."
+ 	if mount_dataset "${ZFS_DATASET}" ; then
+ 		ROOTFS_MOUNTED=yes
+diff --git a/contrib/dracut/90zfs/zfs-needshutdown.sh.in b/contrib/dracut/90zfs/zfs-needshutdown.sh.in
+new file mode 100644
+index 0000000..e3d1b59
+--- /dev/null
++++ b/contrib/dracut/90zfs/zfs-needshutdown.sh.in
+@@ -0,0 +1,10 @@
++#!/bin/sh
++
++type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
++
++if zpool list 2>&1 | grep -q 'no pools available' ; then
++    info "ZFS: No active pools, no need to export anything."
++else
++    info "ZFS: There is an active pool, will export it."
++    need_shutdown
++fi
+-- 
+2.1.4
+
diff --git a/debian/patches/series b/debian/patches/series
index ef5fd35..cf3e65e 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -13,3 +13,13 @@ enable-zed.patch
 0003-Linux-4.9-compat-inode_change_ok-renamed-setattr_pre.patch
 0004-Kernel-4.9-compat-file_operations-aio_fsync-removal.patch
 0001-Fix-for-Linux-4.9-compat-iops-rename-wants-flags.patch
+0001-fix-booting-via-dracut-generated-initramfs.patch
+0032-A-collection-of-dracut-fixes.patch
+0034-Fix-the-test-to-use-the-variable.patch
+0159-Set-proper-dependency-for-string-replacement-targets.patch
+0219-Adapt-genkernel-fix-for-zfsonlinux-zfs-4749-to-zfs-d.patch
+0220-zfs-dracut-module-should-not-assume-systemd-presence.patch
+0246-Fix-regression-that-broke-dracut-initramfs-generatio.patch
+0296-Use-a-different-technique-to-detect-whether-to-mount.patch
+0334-Use-F-to-export-pools-so-as-not-to-dirty-up-device-l.patch
+0336-Properly-use-the-Dracut-cleanup-hook-to-order-pool-s.patch

-- 
OpenZFS on Linux



More information about the Pkg-zfsonlinux-devel mailing list