summaryrefslogtreecommitdiffstats
path: root/contrib/dracut/02zfsexpandknowledge/module-setup.sh.in
diff options
context:
space:
mode:
authorMatthew Thode <[email protected]>2016-03-30 18:59:15 -0500
committerBrian Behlendorf <[email protected]>2016-04-25 08:51:38 -0700
commita5a370227eb0a3daf8992a38920d54eb3b7b3c25 (patch)
treecc85181222f7cd64ff79c9eae7013588730977c2 /contrib/dracut/02zfsexpandknowledge/module-setup.sh.in
parent232604b58e8579501c5a260ad3a7b71a239dd546 (diff)
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) <[email protected]> Signed-off-by: Matthew Thode <[email protected]> Closes #3605 Closes #4478
Diffstat (limited to 'contrib/dracut/02zfsexpandknowledge/module-setup.sh.in')
-rwxr-xr-xcontrib/dracut/02zfsexpandknowledge/module-setup.sh.in132
1 files changed, 132 insertions, 0 deletions
diff --git a/contrib/dracut/02zfsexpandknowledge/module-setup.sh.in b/contrib/dracut/02zfsexpandknowledge/module-setup.sh.in
new file mode 100755
index 000000000..830ee42f6
--- /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
+}