Sunday, 5 March 2017

Blacklisting modules for linux by detecting PC\NoteBook model strings in the BIOS

Stepdown recently asked on reboot.pro about how to detect specific makes\models of hardware so that the correct linux kernel parameters can be used automatically.

For instance, a certain model of system may not boot using the default linux kernel parameters unless nomodeset or a 'blacklist' module is specified as a kernel parameter.

The 'sample' example below shows how you can  detect the type of system you are using and automatically use the correct kernel parameters for that system.

I will put example .mnu files in E2B v1.91b and later versions.


Check BIOS for Make\Model string

# Look for a BIOS string to find PC Model
# Search strings (e.g. "eeepc") are not case-sensitive
# 0x7ff+0x01 searches 512 bytes at end of BIOS ROM, 0x600+0x40 will search the BIOS VGA ROM area
# 0x680+0x180 searches all of BIOS from 0xD000:0 to 0xFFFF:F (and so will be slower)
# remove the " > nul" text if you want to see the strings that it has found

# This example sets blacklist modules depending on what Model we find
# We can also set nomodeset parameter for specific models
# Note that a blacklist must NOT contain spaces or the values after the space won't be parsed correctly by linux!

# ATTENTION: The modules used are for example only - they are not real module names!

iftitle [if exist $HOME$/ubuntu-16.10-desktop-amd64.iso] Boot Ubuntu (detect system model for blacklist)\n Auto-detect based on BIOS strings
set ISO=ubuntu-16.10-desktop-amd64.iso
set GOTSTR=
set MATCH=
set bl=
set modeset=

if not exist MATCH call /%grub%/SearchBS.g4b 0x780+0x80 "eeepc" > nul
if not exist MATCH if "%GOTSTR%"=="1" set bl=emodule1,module2 && set MATCH=1

if not exist MATCH call /%grub%/SearchBS.g4b 0x780+0x80 "ASUS Z87" > nul
if not exist MATCH if "%GOTSTR%"=="1" set bl=modulez87 && set MATCH=1

if not exist MATCH call /%grub%/SearchBS.g4b 0x780+0x80 "virtualbox" > nul
if not exist MATCH if "%GOTSTR%"=="1" set bl=vbmodule1,module3 && set modeset=nomodeset && set MATCH=1

# add more pairs of lines here

if exist bl echo -e -n $[0x0E]Using blacklist=%bl% %modeset% && pause --wait=3 > nul
# suppress messages from QRUN
set redir=> nul
# Map ISO automatically by calling QRUN
/%grub%/QRUN.g4b $HOME$/%ISO%
# (0xff) will have ISO - root should be (0xff)
if not exist /casper/vmlinuz.efi pause ERROR: Wrong ISO? && configfile (md)0xa000+0x50

kernel /casper/vmlinuz.efi  file=/cdrom/preseed/ubuntu.seed boot=casper blacklist=%bl% %modeset% quiet splash ---
initrd /casper/initrd.lz

# can boot to linux here...
boot


PCI ID detection example

# This example sets blacklist modules depending on what PCI IDs we find
# We can also set nomodeset parameter for specific models
# Note that a blacklist must NOT contain spaces or the values after the space won't be parsed correctly by linux!

# ATTENTION: The modules used are for example only - they are not real module names!

iftitle [if exist $HOME$/ubuntu-16.10-desktop-amd64.iso] Boot Ubuntu (detect PCI ID for blacklist)\n Auto-detect based on PCI IDs
set ISO=ubuntu-16.10-desktop-amd64.iso
set bl=
set modeset=
# get PCI IDs of this system into memory
/%grub%/DPMS/chkpci > (md)0x300+2
set bl=

cat --locatei=EN_8086&DEV_27B9 (md)0x300+2 > nul && set bl=vbmodule1,module3 && set modeset=nomodeset 

# add more lines here

if exist bl echo -e -n $[0x0E]Using blacklist=%bl% %modeset% && pause --wait=3 > nul
# suppress messages from QRUN
set redir=> nul
# Map ISO automatically by calling QRUN
/%grub%/QRUN.g4b $HOME$/%ISO%
# (0xff) will have ISO - root should be (0xff)
if not exist /casper/vmlinuz.efi pause ERROR: Wrong ISO? && configfile (md)0xa000+0x50

kernel /casper/vmlinuz.efi  file=/cdrom/preseed/ubuntu.seed boot=casper blacklist=%bl% %modeset% quiet splash ---
initrd /casper/initrd.lz

# can boot to linux here...
boot


No comments:

Post a Comment