# Linux Kernel Module Cheat
The perfect emulation setup to study and develop the <<linux-kernel>> v5.9.2, kernel modules, <<qemu-buildroot-setup,QEMU>>, <<gem5-buildroot-setup,gem5>> and x86_64, ARMv7 and ARMv8 <<userland-assembly,userland>> and <<baremetal-setup,baremetal>> assembly, <<c,ANSI C>>, <<cpp,C++>> and <<posix,POSIX>>. <<gdb>> and <<kgdb>> just work. Powered by <<about-the-qemu-buildroot-setup,Buildroot>> and <<about-the-baremetal-setup,crosstool-NG>>. Highly automated. Thoroughly documented. Automated <<test-this-repo,tests>>.

##### 17.5.2.1. Kernel module dependencies with modprobe

Unlike `insmod`, modprobe deals with kernel module dependencies for us.

First get kernel_modules buildroot package working.

Then, for example:

    modprobe buildroot_dep2

outputs to dmesg:

    42

and then:

    lsmod

outputs:

    Module                  Size  Used by    Tainted: G
    buildroot_dep2         16384  0
    buildroot_dep          16384  1 buildroot_dep2

Sources:

- buildroot_packages/kernel_modules/buildroot_dep.c

- buildroot_packages/kernel_modules/buildroot_dep2.c

Removal also removes required modules that have zero usage count:

    modprobe -r buildroot_dep2

`modprobe` uses information from the `modules.dep` file to decide the required dependencies. That file contains:

    extra/buildroot_dep2.ko: extra/buildroot_dep.ko

Bibliography:

- https://askubuntu.com/questions/20070/whats-the-difference-between-insmod-and-modprobe

- https://stackoverflow.com/questions/22891705/whats-the-difference-between-insmod-and-modprobe