I am confused by how built-in kernel modules work. As per my understanding, one can embed a kernel module when compiling the Linux kernel by setting kconfig option to MODULE_NAME=y. Then, it doesn't have to be loaded with e.g. modprobe. Built-in kernel modules can be shown with cat /lib/modules/$(uname -r)/modules.builtin.
When I execute this command, the list shows .ko files. But if they are embedded inside the kernel, why is it showing this? For example:
~$ cat /lib/modules/$(uname -r)/modules.builtin | grep -i bsg #just picking something random
kernel/block/bsg.ko
~$ cat /boot/config-6.5.0-14-generic | grep -i bsg
CONFIG_BLK_DEV_BSG_COMMON=y #implying this is a builtin module
CONFIG_BLK_DEV_BSGLIB=y
CONFIG_BLK_DEV_BSG=y
CONFIG_SCSI_UFS_BSG=y
~$ modinfo bsg
name: bsg
filename: (builtin)
license: GPL
file: block/bsg #why "file"? Isn't it compiled inside the kernel?
...
~$ cat /lib/modules/6.5.0-14-generic/kernel/block/bsg.ko
cat: /lib/modules/6.5.0-14-generic/kernel/block/bsg.ko: No such file or directory
So my questions are:
- What really happens to builtin kernel modules and where do they reside inside the system?
- Are they inside vmlinuz and extracted somehow?
- Why do they appear as
.kofile but are not present in the directory where I would expect them?
Considering they are indeed embedded in vmlinu(x/z), how do they end up being "registered" such that we can find them using modinfo? And why does it still have a file (block/bsg) as shown by modinfo if it's in the kernel binary?