0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Linuxのカーネルモジュール(モジュール)をロードしてみる

Last updated at Posted at 2022-02-12

Linuxにおけるモジュールを自分なりに調べてみた。

(前提)モジュールとは
カーネルモジュールとは、オペレーティングシステム(OS)の中核部分であるカーネルに機能を追加するよう設計されたソフトウェア部品のこと。単にカーネルモジュールといった場合はLinuxカーネルに追加できるプログラムを指すことが多い。

(参考)https://e-words.jp/w/%E3%82%AB%E3%83%BC%E3%83%8D%E3%83%AB%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB.html

というわけで、モジュール=カーネルに追加するプログラムのことである。

ちなみに、モジュールは「/lib/modules」配下に「.ko」という拡張子で格納されている。

[ec2-user@concentrate 5.10.82-83.359.amzn2.x86_64]$ ls -lR | grep .ko | wc -l
959
[ec2-user@concentrate 5.10.82-83.359.amzn2.x86_64]$

「/lib/modules」配下に「.ko」の拡張子のファイルは959個存在した。

●現在有効のモジュールを確認してみる(lsmodコマンド)

[ec2-user@concentrate 5.10.82-83.359.amzn2.x86_64]$ lsmod
Module Size Used by
sunrpc 667648 1
dm_mirror 28672 0
dm_region_hash 24576 1 dm_mirror
dm_log 20480 2 dm_region_hash,dm_mirror
dm_mod 159744 2 dm_log,dm_mirror
dax 106496 1 dm_mod
crc32_pclmul 16384 0
ghash_clmulni_intel 16384 0
aesni_intel 372736 0
crypto_simd 16384 1 aesni_intel
cryptd 28672 2 crypto_simd,ghash_clmulni_intel
glue_helper 16384 1 aesni_intel
mousedev 24576 0
ata_piix 40960 0
libata 303104 1 ata_piix
scsi_mod 270336 1 libata
psmouse 36864 0
button 24576 0
ena 139264 0
crc32c_intel 24576 0
[ec2-user@concentrate 5.10.82-83.359.amzn2.x86_64]$

詳細は以下。
Module:モジュール名
Size:モジュールのサイズ
Used by:依存しているモジュールの数と依存モジュール名
※どのモジュールが何かはよくわからないのでスルー。

●実機(Amazon Linux)でモジュールを追加してみる。
基本的にモジュールの追加・削除(ロード・アンロード)はコマンド実行により自動的に行ってくれる。

①depmodコマンドを実行して、依存関係を更新する
 モジュールどうしは互いに依存しているものがあり、それらの関係性を更新する作業から始める。
 ※依存関係は「modules.dep」ファイルで確認可能。

[root@concentrate ~]# cat /usr/lib/modules/5.10.82-83.359.amzn2.x86_64/modules.dep | head
kernel/arch/x86/crypto/glue_helper.ko:
kernel/arch/x86/crypto/twofish-x86_64.ko: kernel/crypto/twofish_common.ko
kernel/arch/x86/crypto/twofish-x86_64-3way.ko: kernel/arch/x86/crypto/twofish-x86_64.ko kernel/crypto/twofish_common.ko kernel/arch/x86/crypto/glue_helper.ko

このような感じで依存関係が記載されている。

[root@concentrate ~]# depmod
[root@concentrate ~]#

特に何もなくコマンドが終了した。

②modprobeコマンドでモジュールをロードしてみる。
コマンドの書式は以下
modprobe モジュール

今回は-vオプションで詳細を表示させつつ、「tcp_lp」というモジュールをロードする。

[root@concentrate 5.10.82-83.359.amzn2.x86_64]# modprobe -v tcp_lp
insmod /lib/modules/5.10.82-83.359.amzn2.x86_64/extra/net/ipv4/tcp_lp.ko
[root@concentrate 5.10.82-83.359.amzn2.x86_64]#

insmodが表示され、正常終了した。

結論:モジュールを一つロードしただけではよくわからなかった。
ただ、モジュールのロードに使用するコマンドや順序、ファイルの場所などは理解できた。
今後意図的にモジュールをロードする機会があったときに再度リベンジしたい

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?