How to Check Loaded Linux Kernel Firmware Modules Since Boot for Debian Optimization


2 views

When maintaining a Debian system, many administrators install all available firmware packages to ensure hardware compatibility. However, this approach leads to unnecessary storage consumption and potential security surface expansion. The key is identifying actually loaded firmware modules.

The primary method involves examining the kernel ring buffer, which logs all firmware load events:

dmesg | grep -i firmware

Sample output might show:

[    2.350124] iwlwifi 0000:03:00.0: loaded firmware version 36.ca7b901d.0 op_mode iwlmvm
[    2.723456] Bluetooth: hci0: Intel Bluetooth firmware file: intel/ibt-12-16.sfi

For historical tracking across reboots, configure rsyslog to capture firmware events:

# /etc/rsyslog.d/30-firmware.conf
kern.=info /var/log/firmware.log

Then filter specifically for firmware loads:

grep -i "firmware" /var/log/firmware.log

For real-time monitoring of firmware requests:

# stap -e 'probe kernel.function("request_firmware") { printf("%s: %s\\n", execname(), $$parms$$) }'

This will output the process name and firmware details for each load event.

After identifying used firmware, create a package exclusion list for apt:

# /etc/apt/apt.conf.d/99firmware
APT::Install-Recommends "false";
APT::Install-Suggests "false";

Then selectively install only required firmware packages:

apt install firmware-linux firmware-realtek firmware-iwlwifi

Post-cleanup, verify no devices lost functionality. Check for failed loads:

journalctl -b | grep -i "failed to load firmware"
dmesg | grep -i "direct-loading firmware"

When dealing with Debian systems, many users accumulate firmware packages over time without proper maintenance. The Linux kernel dynamically loads firmware for hardware components when needed, leaving traces in system logs and virtual filesystems.

The most straightforward method is examining the kernel ring buffer:

dmesg | grep -i firmware

This will show all firmware loading events since boot, including successful loads and any errors. Example output:

[    2.345678] iwlwifi 0000:03:00.0: loaded firmware version 36.77d01142.0 op_mode iwlmvm
[    2.456789] Bluetooth: hci0: Intel Bluetooth firmware file: intel/ibt-12-16.sfi

For a more permanent record, check the kernel's firmware_class debug facility:

sudo cat /sys/kernel/debug/firmware_class/log

If the debugfs isn't mounted:

sudo mount -t debugfs none /sys/kernel/debug

Use ftrace to capture firmware loading events:

echo 1 | sudo tee /sys/kernel/debug/tracing/events/firmware/enable
sudo cat /sys/kernel/debug/tracing/trace_pipe

This provides detailed timing and loading path information for each firmware request.

To create a comprehensive list of firmware used during normal operation:

sudo journalctl -k --grep="firmware" --since="1 hour ago" > ~/firmware_usage.log

Run this after testing all hardware components (bluetooth, camera, etc.) to capture their firmware dependencies.

For specific devices like WiFi adapters:

lspci -k | grep -A 3 -i network
dmesg | grep -i iwl

This identifies the exact firmware version loaded for Intel wireless cards, helping determine if the package firmware-iwlwifi is actually needed.

Once you've identified necessary firmware, safely remove unused packages:

apt list --installed | grep firmware
sudo apt purge firmware-{package-name}

Always keep a backup of your current firmware packages before removal.