Skip to content

Commit

Permalink
fix(dracut-functions.sh): get block device driver if in a virtual sub…
Browse files Browse the repository at this point in the history
…system

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.
  • Loading branch information
aafeijoo-suse authored and haraldh committed Nov 24, 2021
1 parent d364ce8 commit dc3b976
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion dracut-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit dc3b976

Please sign in to comment.