Blame 1882-dmsquash-live-root-Run-checkisomd5-on-correct-device.patch

adc42d
From 0636c42eaddef24903b66aa8d0cb392ba24b9a3d Mon Sep 17 00:00:00 2001
adc42d
From: "Brian C. Lane" <bcl@redhat.com>
adc42d
Date: Fri, 22 Jul 2022 16:10:20 -0700
adc42d
Subject: [PATCH] fix(dmsquash-live): run checkisomd5 on correct device
adc42d
adc42d
When the new grub2 iso is written to a usb drive the disk label points
adc42d
to a partition that does not include the full iso image. This causes
adc42d
checkisomd5 to run with the wrong data and it fails.
adc42d
adc42d
This patch adds a check that will test to see if there is a parent
adc42d
device that is a disk, and to run checkisomd5 on it instead of on the
adc42d
partition pointed to by the label.
adc42d
adc42d
When running from an iso this will return the original
adc42d
/dev/disk/by-label/ path, and when running from a usb drive it will
adc42d
return the parent device (eg. /dev/sda).
adc42d
adc42d
Resolves: rhbz#2107858
adc42d
---
adc42d
 .../90dmsquash-live/dmsquash-live-root.sh     | 33 +++++++++++++++++--
adc42d
 modules.d/90dmsquash-live/module-setup.sh     |  2 +-
adc42d
 2 files changed, 31 insertions(+), 4 deletions(-)
adc42d
adc42d
diff --git a/modules.d/90dmsquash-live/dmsquash-live-root.sh b/modules.d/90dmsquash-live/dmsquash-live-root.sh
adc42d
index abc68407f4..665bff87c1 100755
adc42d
--- a/modules.d/90dmsquash-live/dmsquash-live-root.sh
adc42d
+++ b/modules.d/90dmsquash-live/dmsquash-live-root.sh
adc42d
@@ -33,8 +33,35 @@ overlay_size=$(getarg rd.live.overlay.size=)
adc42d
 getargbool 0 rd.live.overlay.thin && thin_snapshot="yes"
adc42d
 getargbool 0 rd.live.overlay.overlayfs && overlayfs="yes"
adc42d
 
adc42d
+# Take a path to a disk label and return the parent disk if it is a partition
adc42d
+# Otherwise returns the original path
adc42d
+function get_check_dev() {
adc42d
+    local _udevinfo
adc42d
+    dev_path="$(udevadm info -q path --name "$1")"
adc42d
+    _udevinfo="$(udevadm info -q property --path "${dev_path}")"
adc42d
+    strstr "$_udevinfo" "DEVTYPE=partition" || {
adc42d
+        echo "$1"
adc42d
+        return
adc42d
+    }
adc42d
+    parent="${dev_path%/*}"
adc42d
+    _udevinfo="$(udevadm info -q property --path "${parent}")"
adc42d
+    strstr "$_udevinfo" "DEVTYPE=disk" || {
adc42d
+        echo "$1"
adc42d
+        return
adc42d
+    }
adc42d
+    strstr "$_udevinfo" "ID_FS_TYPE=iso9660" || {
adc42d
+        echo "$1"
adc42d
+        return
adc42d
+    }
adc42d
+
adc42d
+    # Return the name of the parent disk device
adc42d
+    echo "$_udevinfo" | grep "DEVNAME=" | sed 's/DEVNAME=//'
adc42d
+}
adc42d
+
adc42d
+# Find the right device to run check on
adc42d
+check_dev=$(get_check_dev "$livedev")
adc42d
 # CD/DVD media check
adc42d
-[ -b "$livedev" ] && fs=$(blkid -s TYPE -o value "$livedev")
adc42d
+[ -b "$check_dev" ] && fs=$(blkid -s TYPE -o value "$check_dev")
adc42d
 if [ "$fs" = "iso9660" -o "$fs" = "udf" ]; then
adc42d
     check="yes"
adc42d
 fi
adc42d
@@ -42,10 +69,10 @@ getarg rd.live.check -d check || check=""
adc42d
 if [ -n "$check" ]; then
adc42d
     type plymouth > /dev/null 2>&1 && plymouth --hide-splash
adc42d
     if [ -n "$DRACUT_SYSTEMD" ]; then
adc42d
-        p=$(dev_unit_name "$livedev")
adc42d
+        p=$(dev_unit_name "$check_dev")
adc42d
         systemctl start checkisomd5@"${p}".service
adc42d
     else
adc42d
-        checkisomd5 --verbose "$livedev"
adc42d
+        checkisomd5 --verbose "$check_dev"
adc42d
     fi
adc42d
     if [ $? -eq 1 ]; then
adc42d
         die "CD check failed!"
adc42d
diff --git a/modules.d/90dmsquash-live/module-setup.sh b/modules.d/90dmsquash-live/module-setup.sh
adc42d
index dc35ba6579..b305ce1aa3 100755
adc42d
--- a/modules.d/90dmsquash-live/module-setup.sh
adc42d
+++ b/modules.d/90dmsquash-live/module-setup.sh
adc42d
@@ -22,7 +22,7 @@ installkernel() {
adc42d
 
adc42d
 # called by dracut
adc42d
 install() {
adc42d
-    inst_multiple umount dmsetup blkid dd losetup blockdev find rmdir
adc42d
+    inst_multiple umount dmsetup blkid dd losetup blockdev find rmdir grep
adc42d
     inst_multiple -o checkisomd5
adc42d
     inst_hook cmdline 30 "$moddir/parse-dmsquash-live.sh"
adc42d
     inst_hook cmdline 31 "$moddir/parse-iso-scan.sh"