Not able to remove a loadable kernel module
Asked Answered
S

4

12

I'm writing a loadable kernel module and trying to test it. After inserting it I was trying to remove it using rmmod xxx command, but I get an error saying module xxx is in use and the module gets stuck and I can't remove it. Any idea how to remove the module without rebooting the entire machine ? (linux Kernel v. 3.5.0)

Note: rmmod -f prints Error: device or resource busy

Sixfooter answered 22/6, 2013 at 14:29 Comment(3)
rmmod -f doesn't work, it prints ERROR: device or resource busyCasing
Well then reboot. (And think about playing around with the kernel in a VM rather than your main host. Rebooting's not really an issue then.)Snoddy
If you print out dmesg and are able to provide code snippets we may be able to help further.Confucian
C
17

This only happens to me when there is a bug in my driver which is causing the code in the module to panic or crash in some way. In my experience once this happens reboot is the only possible course.

As I said, the kernel usually panics so you should check out dmesg after inserting it or running you application to exercise it. I'm not certain but it might be possible that if the driver doesn't release a mutex this behavior will happen as well.

Confucian answered 23/6, 2013 at 16:29 Comment(0)
S
0

Check your module_exit function is proper. You may need to compile your kernel to have "remove the module without rebooting the entire machine" with MODULE_FORCE_UNLOAD=yes.

Sweated answered 27/8, 2013 at 13:47 Comment(2)
I have my kernel compiled with this flag, still I get this error as "Device or resource busy". This happens because my driver crashes. So what I can observe is if there is bug in the driver, then no matter if FORCE_UNLOAD is set, you will not be able to unload the driver.Banker
There is a bug in Linux kernel even up to today, that even if MODULE_FORCE_UNLOAD=yes and CONFIG_MODULE_FORCE_UNLOAD=yes is set when compiling the kernel, you still cannot forcefully remove a module.Gast
W
0

I fix the same error by using the same GCC version as which have compiled the running kernel to compile my module, both 8.3.1; Please check on yours.

    [root@centos fishing]# dmesg | grep gcc
    [    0.000000] Linux version 4.18.0-80.7.2.el7.aarch64 ([email protected]) (gcc version 8.3.1 20190311 (Red Hat 8.3.1-3) (GCC)) #1 SMP Thu Sep 12 16:13:20 UTC 2019
    [root@centos fishing]# gcc -v
    gcc version 8.3.1 20190311 (Red Hat 8.3.1-3) (GCC)
    [root@centos fishing]#

Otherwise, I had errors:

    [root@centos fishing]# rmmod fishing
    rmmod: ERROR: could not remove 'fishing': Device or resource busy
    rmmod: ERROR: could not remove module fishing: Device or resource busy
    [root@centos fishing]#

the kernel module, fishing code is from http://books.gigatux.nl/mirror/kerneldevelopment/0672327201/ch16lev2sec1.html

Wrench answered 14/12, 2019 at 7:36 Comment(0)
V
0

Maybe you forget to provide module_exit, so your module doesn't know how to exit.

Venous answered 3/8, 2021 at 2:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.