User:Douglarek/Tutorials/Streamlining linux-firmware
This article assumes you are using modular firmware loading rather than built-in firmware when configuring your kernel.
Optimizing sys-kernel/linux-firmware is much simpler than customizing the kernel while providing significant benefits. If firmware is not built into the kernel (due to licensing issues), the linux-firmware package must be installed alongside the Linux kernel for system operation. However, this package contains all proprietary firmware binaries currently available for Linux, reaching a size of 1.2GB, while a typical desktop system only requires 3-5 files from this collection. Let's explore how to optimize it.
Identifying Currently Loaded Firmware
The firmware loading information output is a Gentoo-specific patch feature that requires enabling
CONFIG_GENTOO_PRINT_FIRMWARE_INFO=y
in the kernel configuration. This feature is not available in vanilla-kernels. If you need to optimize firmware, a common approach is to boot with gentoo-kernel-bin first to collect the dmesg information.root #
dmesg | grep -i 'Loading firmware'
[ 4.763489] Loading firmware: regulatory.db [ 4.764642] Loading firmware: regulatory.db.p7s [ 4.909102] Loading firmware: iwlwifi-9260-th-b0-jf-b0-46.ucode [ 4.920791] Loading firmware: iwl-debug-yoyo.bin [ 4.979257] Loading firmware: nvidia/565.57.01/gsp_tu10x.bin [ 5.045129] Loading firmware: intel/ibt-18-16-1.sfi [ 6.577898] Loading firmware: rtl_nic/rtl8168h-2.fw
The output shows all firmware loaded during system boot. Not all of these firmware files are included in the linux-firmware package. In this example, only iwlwifi-9260-th-b0-jf-b0-46.ucode, intel/ibt-18-16-1.sfi, and rtl_nic/rtl8168h-2.fw are part of the package.
How to determine which firmware files are included in linux-firmware? Even without enabling the
savedconfig
USE flag for linux-firmware, the package installation creates a list of all firmware names in a file like /etc/portage/savedconfig/sys-kernel/linux-firmware-20241110. We can compare our loaded firmware against this list.Customizing the Configuration
root #
mkdir -p /etc/portage/savedconfig/sys-kernel # Optional if directory exists
root #
rm -f /etc/portage/savedconfig/sys-kernel/linux-firmware* # Optional if fresh install, may need to remove old configs
root #
dmesg | grep -i 'loading firmware' | sed 's/.*firmware: //' | while read fw; do
grep -q "^$fw\$" /etc/portage/savedconfig/sys-kernel/linux-firmware-20241110 && echo "$fw"
done > /etc/portage/savedconfig/sys-kernel/linux-firmware
root #
mkdir -p /etc/portage/package.use/
root #
echo 'sys-kernel/linux-firmware savedconfig' > /etc/portage/package.use/linux-firmware
Replace /etc/portage/savedconfig/sys-kernel/linux-firmware-20241110 with your corresponding version.
Building Custom linux-firmware
root #
emerge -av sys-kernel/linux-firmware
root #
etc-update # -3
Before and After Comparison
Build time:
Before: 2024-11-13T10:12:44 >>> sys-kernel/linux-firmware-20241110: 1 minute, 55 seconds After: 2024-11-19T15:53:06 >>> sys-kernel/linux-firmware-20241110: 31 seconds
Installation size:
Before: sys-kernel/linux-firmware: 4251 files, 380 non-files, 1.2G After: sys-kernel/linux-firmware: 9 files, 19 non-files, 2.1M
Troubleshooting
System won't boot after misconfiguration
This can occur and typically results in entering root emergency mode. Enter the root password, then remove /etc/portage/savedconfig/sys-kernel/linux-firmware* and re-emerge linux-firmware to restore functionality.
See also
Linux_firmware — is a package distributed alongside the Linux kernel that contains firmware binary blobs necessary for partial or full functionality of certain hardware devices.