Linux

Making Simple Linux Kernel Module in C



Linux kernel modules enable you to extend the kernel dynamically with more functionality for example add file system drivers, …

[ad_2]

source

Related Articles

33 Comments

  1. How do I learn such stuff? Like the meaning of commands such as dmesg | tail -n l, like what does -n do or what is the meaning of tail? How or where do people learn this ?

  2. A bit late but I have a question, why did you use insmod and not modprobe?
    Surely modprobe is better as a default as it loads a kernel module and all it's dependencies.
    Your example has no dependencies but that should not cause a problem or will it?

  3. A keeper! Amazingly simple, exactly the right way to start.
    Causes a "tainted kernel" warning in dmesg, I guess that's something to fix, but it's perfect.

  4. Developing kernel modules in your machine is not sweet thing, and developing on an external machine from your device is also not that easy…

    Could you explain how I could run a qemu image to start learning about Linux Device Drivers

  5. great video, love the straight-to-the-point style. Slight problem: i followed exactly and get this output from the make command

    make -C /lib/modules/`uname -r`/build M=$PWD
    make: Entering directory '/usr/src/linux-headers-5.15.0-102-generic'
    CC [M] /home/josh/source/linux/module/test/cats.o
    MODPOST /home/josh/source/linux/module/test/Module.symvers
    ERROR: modpost: missing MODULE_LICENSE() in /home/josh/source/linux/module/test/cats.o
    make[1]: * [scripts/Makefile.modpost:133: /home/josh/source/linux/module/test/Module.symvers] Error 1
    make[1]: * Deleting file '/home/josh/source/linux/module/test/Module.symvers'
    make: * [Makefile:1830: modules] Error 2
    make: Leaving directory '/usr/src/linux-headers-5.15.0-102-generic'

    no cats.ko is produced, just cats.o and some other files like .mod, modules.order, and some .cmd files

    Any ideas what's going on? thanks in advance to anyone who responds. also I can provide any extra info if necessary.

  6. This is great! You should make a video similar to this on GPU/cuda processing in C++, it's an unknown area for many people and I'm sure a lot would benefit from a simplistic video showing where you can get started

  7. The M=$PWD environment variable is also explained here:
    google: docs kernel org Building External Modules
    ( obj-m that you put in your own makefile is also explained there)

    the -C /lib/modules/$(uname -r)/build makes the make program switch to the build directory where the kbuild build system is installed and then starts the makefile of kbuild that will source your makefile (finding it because you did set the M= variable) to make your kernel module

  8. Hii Sir.
    I just watched your video.
    It is fantastic and so good. I like it so much.
    Just like you did I also try to do that, but there is an error,
    I type a command:
    1) make -C /lib/modules/`uname -r`/build M=$PWD.
    error : make: * /lib/modules/5.16.0-kali7-arm64/build: No such file or directory.

    2) make -C /lib/modules/$(uname -r)/build M=$PWD.
    Same error is coming.
    -> when I go to this lib/modules/ directory. There is one another subdirectory called '5.16.0-kali7-arm64' in that one subdirectory called 'kernel'. and when I added this into that command.
    3) make -C /lib/modules/5.16.0-kali7-arm64/`uname -r`/build M=$PWD.
    Same error is coming.

    4) make -C /lib/modules/5.16.0-kali7-arm64/kernel/`uname -r`/build M=$PWD.
    Same error is coming.

    Even though all the path is correct. So you plz help me. I want to build one mini project very small for my college.

  9. wait WHAT!? That was fast. So, this is all the configuration I need to destroy my kernel binaries??? Awesome! All this time I've been updating grub to destroy my bootloader, This is so much easier!

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button