[SOLVED] initrd "/lib/modules/" selection algorithm

If none of the more specific forums is the right place to ask

[SOLVED] initrd "/lib/modules/" selection algorithm

Postby jrobin28260 » 2019-11-21 20:37

Hi folks,

I'm stuck on trying to understand something : even with a "generic" (not "targeted") initrd, my root partition "/lib/modules/4.19.0-6-amd64/" folder is much bigger that the "/lib/modules/4.19.0-6-amd64/" folder of the initrd (extracted using gunzip then cpio). It's 331.4 MB vs 92.5 MB. I understand why (not all drivers are needed into the initrd) but I'm trying to understand which mechanism is used for selecting which modules files will be sent (or not) to the initrd when running update-initramfs

I did the test, putting manually all the 331.4MB of modules into the initrd works fine (but the resulting initrd file is of course bigger that the one created by update-initramfs).

Thank you in advance !
Last edited by jrobin28260 on 2019-11-21 21:47, edited 1 time in total.
Posts: 44
Joined: 2018-11-09 20:30

Re: Where does the initrd "/lib/modules/" list is establishe

Postby L_V » 2019-11-21 20:55

You should have a look to /etc/initramfs-tools/initramfs.conf

Code: Select all
# MODULES: [ most | netboot | dep | list ]
# most - Add most filesystem and all harddrive drivers.
# dep - Try and guess which modules to load.
# netboot - Add the base modules, network modules, but skip block devices.
# list - Only include modules from the 'additional modules' list


initrd.img => 8 MB
Last edited by L_V on 2019-11-21 21:46, edited 1 time in total.
Posts: 1171
Joined: 2007-03-19 09:04

Re: Where does the initrd "/lib/modules/" list is establishe

Postby jrobin28260 » 2019-11-21 21:46

This is not really the description of the mechanism selecting the list of *.ko files, I already looked at it, there is nothing but a single word selection here, even "most" (my current configuration) does some complex selection.

I finally figured out where those files are selected, as update-initramfs is a readable script, calling mkinitramfs (readable too) script.
mkinitramfs script calls auto_add_modules (or dep_add_modules depending on the parameters). auto_add_modules function is described in /usr/share/initramfs-tools/hook-functions

Code: Select all
# The modules "most" classes added per default to the initramfs
   local arg
   local modules=

   if [ "$#" -eq 0 ] ; then
      set -- base net ide scsi block ata i2o dasd ieee1394 firewire mmc usb_storage

   for arg in "$@" ; do
      case "$arg" in
         modules="$modules btrfs ext2 ext3 ext4 ext4dev "
         modules="$modules isofs jfs reiserfs udf xfs"
         modules="$modules nfs nfsv2 nfsv3 nfsv4"
         modules="$modules af_packet atkbd i8042 psmouse"
         modules="$modules virtio_pci virtio_mmio"

         # Include most USB host and dual-role drivers
         copy_modules_dir kernel/drivers/usb/host \
            hwa-hc.ko sl811_cs.ko sl811-hcd.ko \
            u132-hcd.ko whci-hcd.ko
         copy_modules_dir kernel/drivers/usb/c67x00
         copy_modules_dir kernel/drivers/usb/chipidea
         copy_modules_dir kernel/drivers/usb/dwc2
         copy_modules_dir kernel/drivers/usb/dwc3
         copy_modules_dir kernel/drivers/usb/isp1760
         copy_modules_dir kernel/drivers/usb/musb
         copy_modules_dir kernel/drivers/usb/renesas_usbhs
         # and any extcon drivers for USB
         modules="$modules extcon-usb-gpio extcon-usbc-cros-ec"
         # Add the axp20x_usb_power power supply driver,
         # required to initialize the USB host controllers
         # on a number of armhf systems
         modules="$modules axp20x_usb_power"

         # Include all keyboard drivers and all HID drivers
         # unless we're sure they don't support keyboards.
         # hid-*ff covers various game controllers with
         # force feedback.
         copy_modules_dir kernel/drivers/input/keyboard
         copy_modules_dir kernel/drivers/hid \
            'hid-*ff.ko' hid-a4tech.ko hid-cypress.ko \
            hid-dr.ko hid-elecom.ko hid-gyration.ko \
            hid-icade.ko hid-kensington.ko hid-kye.ko \
            hid-lcpower.ko hid-magicmouse.ko \
            hid-multitouch.ko hid-ntrig.ko \
            hid-petalynx.ko hid-picolcd.ko hid-pl.ko \
            hid-ps3remote.ko hid-quanta.ko \
            'hid-roccat-ko*.ko' hid-roccat-pyra.ko \
            hid-saitek.ko hid-sensor-hub.ko hid-sony.ko \
            hid-speedlink.ko hid-tivo.ko hid-twinhan.ko \
            hid-uclogic.ko hid-wacom.ko hid-waltop.ko \
            hid-wiimote.ko hid-zydacron.ko
         # needed to access keyboard on some ChromeOS devices
         modules="$modules cros_ec_spi"

         # Any of these might be needed by other drivers
         copy_modules_dir kernel/drivers/bus
         copy_modules_dir kernel/drivers/clk
         copy_modules_dir kernel/drivers/gpio
         copy_modules_dir kernel/drivers/i2c/busses
         copy_modules_dir kernel/drivers/i2c/muxes
         copy_modules_dir kernel/drivers/mfd
         copy_modules_dir kernel/drivers/phy
         copy_modules_dir kernel/drivers/pinctrl
         copy_modules_dir kernel/drivers/regulator
         copy_modules_dir kernel/drivers/spi
         copy_modules_dir kernel/drivers/usb/phy

         # Needed for periodic fsck
         copy_modules_dir kernel/drivers/rtc
         copy_modules_dir kernel/drivers/net \
            appletalk arcnet bonding can dummy.ko \
            hamradio hippi ifb.ko irda macvlan.ko \
            macvtap.ko pcmcia sb1000.ko team tokenring \
            tun.ko usb veth.ko wan wimax wireless \
         copy_modules_dir kernel/drivers/ide
         copy_modules_dir kernel/drivers/mmc
         copy_modules_dir kernel/drivers/scsi
         modules="$modules mptfc mptsas mptscsih mptspi zfcp"
         copy_modules_dir kernel/drivers/ata
         copy_modules_dir kernel/drivers/block
         copy_modules_dir kernel/drivers/nvme
         modules="$modules vmd"
         modules="$modules deflate zlib lzo ubi ubifs"
         modules="$modules ohci1394 sbp2"
         modules="$modules firewire-ohci firewire-sbp2"
         modules="$modules i2o_block"
         modules="$modules dasd_diag_mod dasd_eckd_mod dasd_fba_mod"
         copy_modules_dir kernel/drivers/usb/storage

   # shellcheck disable=SC2086
   manual_add_modules $modules

Here is the selection algorithm I was looking for!
Posts: 44
Joined: 2018-11-09 20:30

Return to General Questions

Who is online

Users browsing this forum: No registered users and 7 guests