0

The /lib/firmware in my initramfs-5.*.img has only 4 modules:

modules/5.10.12-gentoo/kernel/
├── drivers
│   └── net
│       ├── macvlan.ko.xz
│       └── vxlan.ko.xz
└── net
    ├── ipv4
    │   └── udp_tunnel.ko.xz
    └── ipv6
        └── ip6_udp_tunnel.ko.xz

5 directories, 4 files

But /lib/firmware on rootfs has 172 modules:

/lib/modules/5.10.12-gentoo/kernel/                                                                                                                                                                        [162/352]
├── drivers
│   ├── acpi
│   │   └── dptf
│   │       └── dptf_pch_fivr.ko.xz
│   ├── base
│   │   └── regmap
│   │       └── regmap-mmio.ko.xz
│   ├── char
│   │   ├── agp
│   │   │   └── intel-gtt.ko.xz
│   │   └── tpm
│   │       ├── tpm.ko.xz
│   │       ├── tpm_atmel.ko.xz
│   │       ├── tpm_crb.ko.xz
│   │       ├── tpm_i2c_atmel.ko.xz
│   │       ├── tpm_i2c_infineon.ko.xz
│   │       ├── tpm_i2c_nuvoton.ko.xz
│   │       ├── tpm_infineon.ko.xz
│   │       ├── tpm_nsc.ko.xz
│   │       ├── tpm_tis.ko.xz
│   │       └── tpm_tis_core.ko.xz
│   ├── crypto
│   │   └── qat
│   │       ├── qat_c3xxx
│   │       │   └── qat_c3xxx.ko.xz
│   │       ├── qat_c3xxxvf
│   │       │   └── qat_c3xxxvf.ko.xz
│   │       ├── qat_c62x
│   │       │   └── qat_c62x.ko.xz
│   │       ├── qat_c62xvf
│   │       │   └── qat_c62xvf.ko.xz
│   │       ├── qat_common
│   │       │   └── intel_qat.ko.xz
│   │       ├── qat_dh895xcc
│   │       │   └── qat_dh895xcc.ko.xz
│   │       └── qat_dh895xccvf
│   │           └── qat_dh895xccvf.ko.xz
│   ├── gpu
│   │   └── drm
│   │       ├── i915
│   │       │   └── i915.ko.xz
│   │       ├── nouveau
│   │       │   └── nouveau.ko.xz
│   │       └── ttm
│   │           └── ttm.ko.xz
│   ├── hwmon
│   │   ├── coretemp.ko.xz
│   │   ├── drivetemp.ko.xz
│   │   ├── i5500_temp.ko.xz
│   │   ├── max31730.ko.xz
│   │   └── mr75203.ko.xz
│   ├── net
│   │   ├── bareudp.ko.xz
│   │   ├── ipvlan
│   │   │   ├── ipvlan.ko.xz
│   │   │   └── ipvtap.ko.xz
│   │   ├── macvlan.ko.xz
│   │   ├── macvtap.ko.xz
│   │   ├── nlmon.ko.xz                                                                                                                                                                                    [103/352]
│   │   ├── tap.ko.xz
│   │   ├── tun.ko.xz
│   │   ├── veth.ko.xz
│   │   ├── vxlan.ko.xz
│   │   ├── wireguard
│   │   │   └── wireguard.ko.xz
│   │   └── wireless
│   │       └── intel
│   │           └── iwlwifi
│   │               ├── dvm
│   │               │   └── iwldvm.ko.xz
│   │               ├── iwlwifi.ko.xz
│   │               └── mvm
│   │                   └── iwlmvm.ko.xz
│   ├── usb
│   │   └── misc
│   │       └── apple-mfi-fastcharge.ko.xz
│   └── watchdog
│       ├── i6300esb.ko.xz
│       ├── iTCO_vendor_support.ko.xz
│       ├── iTCO_wdt.ko.xz
│       ├── softdog.ko.xz
│       └── watchdog.ko.xz
├── lib
│   ├── ts_bm.ko.xz
│   ├── ts_fsm.ko.xz
│   └── ts_kmp.ko.xz
├── net
│   ├── bpfilter
│   │   └── bpfilter.ko.xz
│   ├── ipv4
│   │   ├── netfilter
│   │   │   ├── arp_tables.ko.xz
│   │   │   ├── arpt_mangle.ko.xz
│   │   │   ├── arptable_filter.ko.xz
│   │   │   ├── ip_tables.ko.xz
│   │   │   ├── ipt_REJECT.ko.xz
│   │   │   ├── ipt_rpfilter.ko.xz
│   │   │   ├── iptable_filter.ko.xz
│   │   │   ├── iptable_mangle.ko.xz
│   │   │   ├── iptable_nat.ko.xz
│   │   │   ├── iptable_raw.ko.xz
│   │   │   ├── nf_defrag_ipv4.ko.xz
│   │   │   ├── nf_dup_ipv4.ko.xz
│   │   │   ├── nf_log_arp.ko.xz
│   │   │   ├── nf_log_ipv4.ko.xz
│   │   │   ├── nf_reject_ipv4.ko.xz
│   │   │   ├── nf_socket_ipv4.ko.xz
│   │   │   ├── nf_tproxy_ipv4.ko.xz
│   │   │   ├── nft_dup_ipv4.ko.xz
│   │   │   ├── nft_fib_ipv4.ko.xz
│   │   │   └── nft_reject_ipv4.ko.xz
│   │   └── udp_tunnel.ko.xz
│   ├── ipv6
│   │   ├── ip6_udp_tunnel.ko.xz
│   │   └── netfilter
│   │       ├── nf_defrag_ipv6.ko.xz
│   │       ├── nf_reject_ipv6.ko.xz
│   │       ├── nf_socket_ipv6.ko.xz                                                                                                                                                                        [44/352]
│   │       ├── nf_tproxy_ipv6.ko.xz
│   │       └── nft_reject_ipv6.ko.xz
│   └── netfilter
│       ├── nf_conntrack.ko.xz
│       ├── nf_conntrack_netlink.ko.xz
│       ├── nf_dup_netdev.ko.xz
│       ├── nf_flow_table.ko.xz
│       ├── nf_flow_table_inet.ko.xz
│       ├── nf_log_common.ko.xz
│       ├── nf_log_netdev.ko.xz
│       ├── nf_nat.ko.xz
│       ├── nf_tables.ko.xz
│       ├── nfnetlink_acct.ko.xz
│       ├── nfnetlink_log.ko.xz
│       ├── nfnetlink_osf.ko.xz
│       ├── nfnetlink_queue.ko.xz
│       ├── nft_chain_nat.ko.xz
│       ├── nft_compat.ko.xz
│       ├── nft_counter.ko.xz
│       ├── nft_ct.ko.xz
│       ├── nft_dup_netdev.ko.xz
│       ├── nft_fib.ko.xz
│       ├── nft_flow_offload.ko.xz
│       ├── nft_fwd_netdev.ko.xz
│       ├── nft_hash.ko.xz
│       ├── nft_log.ko.xz
│       ├── nft_masq.ko.xz
│       ├── nft_nat.ko.xz
│       ├── nft_numgen.ko.xz
│       ├── nft_objref.ko.xz
│       ├── nft_osf.ko.xz
│       ├── nft_queue.ko.xz
│       ├── nft_redir.ko.xz
│       ├── nft_reject.ko.xz
│       ├── nft_reject_inet.ko.xz
│       ├── nft_socket.ko.xz
│       ├── nft_tproxy.ko.xz
│       ├── nft_tunnel.ko.xz
│       ├── x_tables.ko.xz
│       ├── xt_CHECKSUM.ko.xz
│       ├── xt_CLASSIFY.ko.xz
│       ├── xt_CT.ko.xz
│       ├── xt_HL.ko.xz
│       ├── xt_HMARK.ko.xz
│       ├── xt_IDLETIMER.ko.xz
│       ├── xt_LOG.ko.xz
│       ├── xt_MASQUERADE.ko.xz
│       ├── xt_NETMAP.ko.xz
│       ├── xt_NFLOG.ko.xz
│       ├── xt_NFQUEUE.ko.xz
│       ├── xt_REDIRECT.ko.xz
│       ├── xt_TCPMSS.ko.xz
│       ├── xt_TCPOPTSTRIP.ko.xz
│       ├── xt_TEE.ko.xz
│       ├── xt_TPROXY.ko.xz
│       ├── xt_TRACE.ko.xz
│       ├── xt_addrtype.ko.xz
│       ├── xt_bpf.ko.xz
│       ├── xt_cgroup.ko.xz
│       ├── xt_comment.ko.xz
│       ├── xt_connlabel.ko.xz
│       ├── xt_connmark.ko.xz
│       ├── xt_conntrack.ko.xz
│       ├── xt_devgroup.ko.xz
│       ├── xt_hashlimit.ko.xz
│       ├── xt_helper.ko.xz
│       ├── xt_hl.ko.xz
│       ├── xt_iprange.ko.xz
│       ├── xt_length.ko.xz
│       ├── xt_limit.ko.xz
│       ├── xt_mac.ko.xz
│       ├── xt_mark.ko.xz
│       ├── xt_multiport.ko.xz
│       ├── xt_nat.ko.xz
│       ├── xt_nfacct.ko.xz
│       ├── xt_osf.ko.xz
│       ├── xt_owner.ko.xz
│       ├── xt_pkttype.ko.xz
│       ├── xt_recent.ko.xz
│       ├── xt_socket.ko.xz
│       ├── xt_state.ko.xz
│       ├── xt_statistic.ko.xz
│       ├── xt_string.ko.xz
│       ├── xt_tcpudp.ko.xz
│       └── xt_u32.ko.xz
└── sound
    └── pci
        └── hda
            ├── snd-hda-codec-analog.ko.xz
            ├── snd-hda-codec-ca0110.ko.xz
            ├── snd-hda-codec-ca0132.ko.xz
            ├── snd-hda-codec-cirrus.ko.xz
            ├── snd-hda-codec-cmedia.ko.xz
            ├── snd-hda-codec-conexant.ko.xz
            ├── snd-hda-codec-hdmi.ko.xz
            ├── snd-hda-codec-idt.ko.xz
            ├── snd-hda-codec-realtek.ko.xz
            ├── snd-hda-codec-si3054.ko.xz
            └── snd-hda-codec-via.ko.xz

45 directories, 172 files

Why does genkernel decide to only include 4 of them and why is these 4 selected to be in the initramfs?

1 Answer 1

1

The way it decides to use only those modules is unknown to me. But the goal when building an initramfs is to create something of minimal size. That way, it can be loaded from disk faster, reducing boot time. The only modules the initramfs needs are those that will let it mount your root partition from where it can load any other modules. Anything else should be omitted.

Making initramfs as small as possible is particular critical to boot time because the entire image will be loaded from disk. There is no optimization like lazy-loaded mmap()ed files—the bootloader/kernel just blindly loads the entire thing. Of course, even larger initramfs files can be loaded quickly on modern systems with SSDs. So at that point it becomes a matter of wasted memory resources (because the image populates a filesystem cache with its contents). I expect that, after successfully booting, the files loaded from initramfs are cleared, allowing the memory will be reclaimed later, so the memory is only wasted temporarily.

genkernel has a bunch of different options to add/remove different features. For example, if your root is on LVM2, you will need to enable that feature and it will include the modules and userspace utilities necessary to mount LVM2. And any modules for the filesystem used by your root partition will likely be detected and included.

I am not sure why the five modules that are included are included. I do not think they are necessary in a normal environment. Normally, initramfs will be used to mount a local device and not need to initialize the network at all. I looked up macvlan and it looks like it might be used in a virtualization environment by a guest kernel—if your kernel is being booted up and doing something like a network mount to get its root device, that could make sense. Some sort of netbooting might be a feature of initramfs, but I expect that to be optional and able to be disabled.

3
  • I am pretty sure that no network mount is performed on my computer, so I cannot understand why it is included by genkernel
    – JiaHao Xu
    Feb 4, 2021 at 21:53
  • 1
    I read from here that the init executable in initramfs would rm everything in the initramfs except for the real rootfs to free up space.
    – JiaHao Xu
    Feb 4, 2021 at 21:55
  • I tried to add --no-netboot option to genkernel when generating initramfs, but it doesn't help. It still includes these 4 modules.
    – JiaHao Xu
    Feb 5, 2021 at 3:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .