# Linux Kernel Module Cheat

##### 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