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

3
  • rmmod -f doesn't work, it prints ERROR: device or resource busy Jun 22, 2013 at 14:37
  • 2
    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.)
    – Mat
    Jun 22, 2013 at 14:53
  • 2
    If you print out dmesg and are able to provide code snippets we may be able to help further. Jun 23, 2013 at 16:41

4 Answers 4

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.

1

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

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.

1
  • 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.
    – Naveen
    Jan 5, 2019 at 14:03
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.