From d5c0803c82bebebea0e995ac862b33620ec3d4d7 Mon Sep 17 00:00:00 2001 From: wangyuhang Date: Thu, 16 Nov 2023 15:10:08 +0800 Subject: [PATCH] get block device driver if in a virtual subsystem (cherry picked from commit 2c3017817e2cfc2f246b98dc8c45338c0a57737a) --- ...ions.sh-get-block-device-driver-if-i.patch | 65 +++++++++++++++++++ dracut.spec | 6 +- 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 backport-fix-dracut-functions.sh-get-block-device-driver-if-i.patch diff --git a/backport-fix-dracut-functions.sh-get-block-device-driver-if-i.patch b/backport-fix-dracut-functions.sh-get-block-device-driver-if-i.patch new file mode 100644 index 0000000..35633b5 --- /dev/null +++ b/backport-fix-dracut-functions.sh-get-block-device-driver-if-i.patch @@ -0,0 +1,65 @@ +From dc3b976f3393d7a3fb75b349418fc8ee2c9142bd Mon Sep 17 00:00:00 2001 +From: Antonio Alvarez Feijoo +Date: Wed, 10 Nov 2021 10:19:14 +0100 +Subject: [PATCH] fix(dracut-functions.sh): get block device driver if in a + virtual subsystem + +dracut does not install the kernel module of the block device that contains +the root filesystem if the following preconditions are met: +- Running in host-only mode. +- Symlinks of all block devices needed to boot the system pointing to virtual +subsystems. + +The get_dev_module function uses "udevadm info -a" to get the corresponding +kernel modules of a /sys/class/*/* or /dev/* device. This function is called +in modules.d/90kernel-modules/module-setup.sh to detect if dracut must install +block device drivers in host-only mode. The symlinks in /sys/dev/block/ +usually point to "real" devices in /sys/devices/pci*. But, we have come across +some NVMe systems where the kernel creates the symlinks in /sys/dev/block/ +pointing to "virtual" devices instead. In this case, udevadm never finds any +"driver" attributes following up the chain of parent devices. + +Reference:https://github.com/dracutdevs/dracut/commit/dc3b976f3393d7a3fb75b349418fc8ee2c9142bd +Conflict:NA +--- + dracut-functions.sh | 26 +++++++++++++++++++++++++- + 1 file changed, 25 insertions(+), 1 deletion(-) + +diff --git a/dracut-functions.sh b/dracut-functions.sh +index 32177994..63b6c892 100755 +--- a/dracut-functions.sh ++++ b/dracut-functions.sh +@@ -945,5 +945,29 @@ block_is_netdevice() { + + # get the corresponding kernel modules of a /sys/class/*/* or/dev/* device + get_dev_module() { +- udevadm info -a "$1" | sed -n 's/\s*DRIVERS=="\(\S\+\)"/\1/p' ++ local dev_attr_walk ++ local dev_drivers ++ dev_attr_walk=$(udevadm info -a "$1") ++ dev_drivers=$(echo "$dev_attr_walk" | sed -n 's/\s*DRIVERS=="\(\S\+\)"/\1/p') ++ # if no kernel modules found and device is in a virtual subsystem, follow symlinks ++ if [[ -z $dev_drivers && $(udevadm info -q path "$1") == "/devices/virtual"* ]]; then ++ local dev_vkernel ++ local dev_vsubsystem ++ local dev_vpath ++ dev_vkernel=$(echo "$dev_attr_walk" | sed -n 's/\s*KERNELS=="\(\S\+\)"/\1/p' | tail -1) ++ dev_vsubsystem=$(echo "$dev_attr_walk" | sed -n 's/\s*SUBSYSTEMS=="\(\S\+\)"/\1/p' | tail -1) ++ dev_vpath="/sys/devices/virtual/$dev_vsubsystem/$dev_vkernel" ++ if [[ -n $dev_vkernel && -n $dev_vsubsystem && -d $dev_vpath ]]; then ++ local dev_links ++ local dev_link ++ dev_links=$(find "$dev_vpath" -maxdepth 1 -type l ! -name "subsystem" -exec readlink {} \;) ++ for dev_link in $dev_links; do ++ [[ -n $dev_drivers && ${dev_drivers: -1} != $'\n' ]] && dev_drivers+=$'\n' ++ dev_drivers+=$(udevadm info -a "$dev_vpath/$dev_link" \ ++ | sed -n 's/\s*DRIVERS=="\(\S\+\)"/\1/p' \ ++ | grep -v -e pcieport) ++ done ++ fi ++ fi ++ echo "$dev_drivers" + } +-- +2.33.0 + diff --git a/dracut.spec b/dracut.spec index 6cf4784..6fc109f 100644 --- a/dracut.spec +++ b/dracut.spec @@ -9,7 +9,7 @@ Name: dracut Version: 055 -Release: 7 +Release: 8 Summary: Initramfs generator using udev @@ -40,6 +40,7 @@ Patch13: backport-feat-lvm-only-run-lvchange-for-LV-that-is-seen-on-de.patch Patch14: backport-fix-lvm-restore-setting-LVM_MD_PV_ACTIVATED.patch Patch15: backport-Bring-back-51-dracut-rescue-postinst.sh.patch Patch16: backport-fix-dracut-shutdown-add-cleanup-handler-on-failure.patch +Patch17: backport-fix-dracut-functions.sh-get-block-device-driver-if-i.patch Patch9000: remove-iscsi-related-code-since-it-is-no-longer-main.patch @@ -516,6 +517,9 @@ install -m 0755 51-dracut-rescue-postinst.sh $RPM_BUILD_ROOT%{_sysconfdir}/kerne %endif %changelog +* Thu Nov 16 2023 wangyuhang - 055-8 +- get block device driver if in a virtual subsystem + * Wed Mar 22 2023 wangyuhang - 055-7 - fix(dracut-shutdown): add cleanup handler on failure -- Gitee