site  contact  subhomenews

Hardware profiling for kernel module loading

October 16, 2021 — BarryK

EasyOS, when on a portable media such as a USB-stick, can be booted on different computers. For this to work, Easy needs to remember any settings for the particular hardware being booted on, especially for video and audio. This is an ongoing project, see earlier blog posts:

One area that has missed out so far, is /etc/modprobe.d, in particular for audio and video. For example, on one computer we might want to blacklist the kernel 'nouveau' module, but might want it on another computer.

To remedy, this, /etc/modprobe.d is now hardware-profiled, but only for audio and video. This code has been added to the 'init' script in the initrd:

###hardware profiling###
#20211015 want hardware-profiling for /etc/modprobe.d ...
mkdir -p /mnt/${WKG_DEV}/${WKG_DIR}.session/etc/modprobe.d
#class ids are: 0300 video controller, 0403 audio device, 0106 sata controller, 0c03 usb controller, 0600 host bridge
#note, must use busybox lspci...
newModprobeHardwareProfile="$(lspci | grep -E 'Class 0300:|Class 0403:' | cut -f 4 -d ' ' | tr '\n' '+')" #ex: 8086:3e91+8086:3e91+
if [ "$newModprobeHardwareProfile" ];then
if [ -f /mnt/${WKG_DEV}/${WKG_DIR}.session/etc/modprobe.d/ModprobeHardwareProfile ];then
. /mnt/${WKG_DEV}/${WKG_DIR}.session/etc/modprobe.d/ModprobeHardwareProfile
if [ ! -d /mnt/${WKG_DEV}/${WKG_DIR}.session/etc/modprobe.d.${ModprobeHardwareProfile} ];then
cp -a /mnt/${WKG_DEV}/${WKG_DIR}.session/etc/modprobe.d /mnt/${WKG_DEV}/${WKG_DIR}.session/etc/modprobe.d.${ModprobeHardwareProfile}
if [ "$ModprobeHardwareProfile" != "newModprobeHardwareProfile" ];then
if [ -d /mnt/${WKG_DEV}/${WKG_DIR}.session/etc/modprobe.d.${newModprobeHardwareProfile} ];then
rm -rf /mnt/${WKG_DEV}/${WKG_DIR}.session/etc/modprobe.d
cp -a /mnt/${WKG_DEV}/${WKG_DIR}.session/etc/modprobe.d.${newModprobeHardwareProfile} /mnt/${WKG_DEV}/${WKG_DIR}.session/etc/modprobe.d
#make sure they are synced...
echo "ModprobeHardwareProfile='${newModprobeHardwareProfile}'" > /mnt/${WKG_DEV}/${WKG_DIR}.session/etc/modprobe.d/ModprobeHardwareProfile
rm -rf /mnt/${WKG_DEV}/${WKG_DIR}.session/etc/modprobe.d.${newModprobeHardwareProfile}
cp -a /mnt/${WKG_DEV}/${WKG_DIR}.session/etc/modprobe.d /mnt/${WKG_DEV}/${WKG_DIR}.session/etc/modprobe.d.${newModprobeHardwareProfile}

What the above does, is keep a backup of /etc/modprobe.d for a particular video+audio chip combination. If the hardware changes, the backup will be restored to /etc/modprobe.d

While showing new code in the 'init' script, here is something else that is new:
###broken video###
#20211014 kernel boot "qfix=vid nomodeset"
# ...see refind.conf and syslinux.conf, generated by 3buildeasydistro
if [ $BROKENVID -eq 1 ];then
#prevent kernel drm gpu modules from loading...
#instead of modeprobe.blacklist=nouveau modeprobe.blacklist=i915 modeprobe.blacklist=radeon modeprobe.blacklist=amdgpu modeprobe.blacklist=gma500_gfx
echo 'blacklist amdgpu
blacklist gma500_gfx
blacklist i915
blacklist nouveau
blacklist radeon' > /mnt/${WKG_DEV}/${WKG_DIR}.session/etc/modprobe.d/gpu.conf
# so whatever framebuffer currently active, run xorgwizard-cli...
# firstly, get rid of previous settings...
mkdir -p /mnt/${WKG_DEV}/${WKG_DIR}.session/etc/X11
rm -f /mnt/${WKG_DEV}/${WKG_DIR}.session/etc/X11/xorg.conf 2>/dev/null
rm -rf /mnt/${WKG_DEV}/${WKG_DIR}.session/etc/xorg.conf.d 2>/dev/null
# now set a flag, /root/.profile will run xorgwizard-cli...
touch /mnt/${WKG_DEV}/${WKG_DIR}.session/.brokenvideo

There is a new menu entry at bootup "Fix broken video". Still working on it, will post about it soon.

Note, I'm cutting down how long I sit in front of the computer, as having trouble with eye strain. So, progress will be slower.    

Tags: easy