linux kernel module 基礎

 

1.3 What Is A Kernel Module?

So, you want to write a kernel module. You know C, you have written a few normal programs to run as processes, and now you want to get to where the real action is, to where a single wild pointer can wipe out your file system and a core dump means a reboot.

What exactly is a kernel module? Modules are pieces of code that can be loaded and unloaded into the kernel upon demand. They extend the functionality of the kernel without the need to reboot the system. 

kernel module 是段能夠被載入並且卸除的程式,可以為 kernel 增加功能但不必重啟系統

For example, one type of module is the device driver, which allows the kernel to access hardware connected to the system. 

Without modules, we would have to build monolithic kernels and add new functionality directly into the kernel image. Besides having larger kernels, this has the disadvantage of requiring us to rebuild and reboot the kernel every time we want new functionality.

如不使用module就須將driver build進整個kernel image即花費大量時間編譯


1.4 Kernel module package

Linux distributions provide the commands modprobe insmod and depmod within a package.

On Ubuntu/Debian:

1sudo apt-get install build-essential kmod

On Arch Linux:

1sudo pacman -S gcc kmod


1.5 What Modules are in my Kernel?

To discover what modules are already loaded within your current kernel use the command lsmod .

1sudo lsmod

Modules are stored within the file /proc/modules, so you can also see them with:

1sudo cat /proc/modules

This can be a long list, and you might prefer to search for something particular. To search for the fat module:

1sudo lsmod | grep fat





留言

這個網誌中的熱門文章

sysfs_create_group 註冊 attribute

vim 基礎操作

20220411 台南砲校教召