Reducing initramfs size and speed up the generation

TJ ubuntu at iam.tj
Thu Jul 13 07:32:48 UTC 2023


Is there a specific reason why the focus is on trying to shoe-horn 
everything possible into the initrd.img and then compress rather than 
winnow out the files an installed system will never need to find the 
root file-system?

I tackled the issue of ever-expanding host-generated initrd.img file 
sizes when they began hitting 80MB+ back in 2018 and since then have 
carried my own patches that reduce sizes by not including files the host 
will not need.

One small change that brings major benefits is only including the 
firmware files required, not every file declared by a kernel module. The 
GPU drivers are the main culprit there with amdgpu declaring over 500 of 
which, for any individual GPU, only a handful are relevant, but 
Plymouth's pulling in multiple GPU drivers doesn't help that.

Statistics (initrd.img with kernel v6.2.4):
MODULES=  FIRMWARE_LOADED size      MOST DEP firmwares build-time
most      false           77117694           634       14.49
most      true            60302859 -22%        8       11.99
dep       false           42489938 -45%      606       6.84
dep       true            25704125 -66% -40%   8       6.35

FIMWARE_LOADED=true relies on a simple kernel patch which I've been 
meaning to upstream that writes "Firmware loaded: <file>" for each.

$ journalctl --dmesg | grep 'Firmware loaded' | head -n 15
Jul 02 11:42:21 sunny kernel: firmware_class: Firmware loaded: reporting
Jul 02 11:42:21 sunny kernel: radeon 0000:0a:00.0: Firmware loaded: 
radeon/verde_pfp.bin
Jul 02 11:42:21 sunny kernel: radeon 0000:0a:00.0: Firmware loaded: 
radeon/verde_me.bin
Jul 02 11:42:21 sunny kernel: radeon 0000:0a:00.0: Firmware loaded: 
radeon/verde_ce.bin
Jul 02 11:42:21 sunny kernel: radeon 0000:0a:00.0: Firmware loaded: 
radeon/verde_rlc.bin
Jul 02 11:42:21 sunny kernel: radeon 0000:0a:00.0: Firmware loaded: 
radeon/verde_mc.bin
Jul 02 11:42:21 sunny kernel: radeon 0000:0a:00.0: Firmware loaded: 
radeon/verde_smc.bin
Jul 02 11:42:21 sunny kernel: radeon 0000:0a:00.0: Firmware loaded: 
radeon/TAHITI_uvd.bin
Jul 02 11:42:21 sunny kernel: radeon 0000:0a:00.0: Firmware loaded: 
radeon/TAHITI_vce.bin
Jul 02 11:42:22 sunny kernel: r8152 2-8.3:1.0: Firmware loaded: 
rtl_nic/rtl8153a-4.fw
Jul 02 11:42:28 sunny kernel: platform regulatory.0: Firmware loaded: 
regulatory.db
Jul 02 11:42:28 sunny kernel: platform regulatory.0: Firmware loaded: 
regulatory.db.p7s

My experiments and patches are documented at

https://iam.tj/projects/ubuntu/initramfs-tools/

The main take is the question:

Is MODULES=most really the best default for installed-on-host images (it 
obviously is for installer and portable images). If it can be nuanced 
then =DEP plus winnowing the firmware files gives great gains with 
minimal effort.



More information about the ubuntu-devel mailing list