カーネルからロード可能なモジュールを強制的に削除する方法

カーネルからロード可能なモジュールを強制的に削除する方法

デバイスファイルを使用class_create()してdevice_create()実行できる簡単なデバイスドライバを作成しました。しかし、私のドライバの終了関数は最初にクラスを破壊し、次にドライバを破壊します。つまり、class_destroy()最初に呼び出してからドライバを呼び出しますdevice_destroy()。これにより、カーネルログにいくつかのエラーメッセージが表示されますが、シャットダウン機能に入れた出力メッセージは表示されません。

ドライバーも削除されておらず、まだ使用中です。

私は知りたいです:

  1. クラスを最初に解放してからデバイスを削除する間違いを犯したと思われるので、そのエラーメッセージは適切です。しかし、今はドライバの削除は利用できませんrmmod。システムを再起動せずにドライバを削除する方法はありますか?

  2. lsmodどのサービスが私のドライバを使用しているかを確認したことがあります。ただし、「使用」を表示する1代わりに、数はです-1。この行動の理由は何ですか?

ベストアンサー1

man rmmod:

NAME
       rmmod - Simple program to remove a module from the
       Linux Kernel

SYNOPSIS
       rmmod [-f] [-s] [-v] [modulename]

DESCRIPTION
       rmmod is a trivial program to remove a module (when
       module unloading support is provided) from the kernel.
       Most users will want to use modprobe(8) with the -r
       option instead.

OPTIONS
       -v, --verbose
           Print messages about what the program is doing.
           Usually rmmod prints messages only if something
           goes wrong.

       -f, --force
           This option can be extremely dangerous: it has no
           effect unless CONFIG_MODULE_FORCE_UNLOAD was set
           when the kernel was compiled. With this option,
           you can remove modules which are being used, or
           which are not designed to be removed, or have been
           marked as unsafe (see lsmod(8)).

を使用するには、  -fカーネルにCONFIG_MODULE_FORCE_UNLOADこのオプションが設定されている必要があります。設定されていることを確認するには、以下を使用してください。

/boot$ grep CONFIG_MODULE_FORCE_UNLOAD config-`uname -r`
CONFIG_MODULE_FORCE_UNLOAD=y

(配布版の/bootの下に構成がインストールされている場合...)

使用回数は-1以下をご覧ください。回答

おすすめ記事