Day 1.1: Explaination of few basic terms related to Linux modules

in #linux6 years ago

Hi, so this post can't be said as day 2 because I did nothing new.
Today I'll just explain the terms which I mentioned in my last post.

insmod - You wrote your module, you generated object file(.ko file or kernel object file), now what? Now we have to load our kernel object file to the kernel. For this we need 'insmod' command. This command takes the absolute or relative path of the object file as argument and loads it to the kernel.
I can give an example from our last simple hello world program.

$ make
make -C /lib/modules/4.15.0-45-generic/build M=/home/bhargav/Practice-push/practise/Device-Drivers/LearnLDD/1-Hello-World modules
make[1]: Entering directory '/usr/src/linux-headers-4.15.0-45-generic'
  CC [M]  /home/bhargav/Practice-push/practise/Device-Drivers/LearnLDD/1-Hello-World/1_hello_simple.o
  Building modules, stage 2.
  MODPOST 1 modules
WARNING: modpost: missing MODULE_LICENSE() in /home/bhargav/Practice-push/practise/Device-Drivers/LearnLDD/1-Hello-World/1_hello_simple.o
see include/linux/module.h for more information
  CC      /home/bhargav/Practice-push/practise/Device-Drivers/LearnLDD/1-Hello-World/1_hello_simple.mod.o
  LD [M]  /home/bhargav/Practice-push/practise/Device-Drivers/LearnLDD/1-Hello-World/1_hello_simple.ko
make[1]: Leaving directory '/usr/src/linux-headers-4.15.0-45-generic'
$ insmod 1_hello_simple.ko
insmod: ERROR: could not insert module 1_hello_simple.ko: Operation not permitted
$ sudo insmod 1_hello_simple.ko

So here I have first executed make command to generate our object files (.ko files), many more files are there but we are not concerned with them right now. ( ignore the License error during make, I'll come to that in later posts)

Also if you get Operation not permitted error like me, use sudo command.

lsmod - I inserted the module, but how do I verify that? Here the lsmod command comes to play. Not only for verifying but also to check all the modules loaded in the system.

$ lsmod | grep -i "hello"
1_hello_simple         16384  0

From the above we can see that our module is available in the lsmod list (I'm not going to display all my modules as it will be a long list). The first column shows the module name, the second one shows the size of the module, and the third one show how many processes are using our module ( in this case it's zero, as it's doing nothing)

rmmod - After loading your module, if you want to unload it you would need this command

$ rmmod <module name>

Boom you have unloaded from your system.

modinfo - I compiled my module, now what if I want to check it's details without opening the code? for this I will use the modinfo command. That's it, I know for now.

modprobe - This is a very useful command to load modules it makes our life earsier by loading the dependency modules intelligently but I haven't used it by writing my own module (because I'm still a beginner) but I have used it else where to get things done.

$ modprobe <module name>

Thanks if like the post. I haven't been regular with my learning and also posting but I will be on track within a couple of days.

1385698302_funny_linux_wallpapers.jpg

Sort:  

Congratulations @bhargavdas! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You received more than 50 upvotes. Your next target is to reach 100 upvotes.

You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard:

SteemitBoard to support the german speaking community meetups
Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Congratulations @bhargavdas! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.27
TRX 0.20
JST 0.039
BTC 97468.81
ETH 3593.60
USDT 1.00
SBD 3.89