I am trying to learn about Linux device drivers. I am trying to install the module using insmod from the command line. After insertion, I try to remove the loaded module, which fails with the error,

could not remove module hello: Device or resource busy

I found this link but it doesn't seem to provide a valid answer.

Below is the C code (hello.c) of the module:

#include <linux/module.h>   /* Needed by all modules */
#include <linux/kernel.h>   /* Needed for KERN_INFO */
#include <linux/init.h>     /* Needed for the macros */

static int data __initdata = 3;


int init_module(void)
    printk(KERN_INFO "Hello world 1.\n");

    return -1;

void cleanup_module(void)
    printk(KERN_INFO "Goodbye world 1.\n");


static int __init my_init(void)
    printk(KERN_ALERT "Hello Module Inserted : %d \n",data);
    return 0;

static void __exit my_exit(void)
    printk(KERN_ALERT "Hello Module removed : %d \n",data);



I am compiling this module with the following Makefile:

obj-m += hello.o

    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

After compiling, I install the module using the command sudo insmod ./hello.ko. I can see the loaded module in /proc/modules. Output of cat /proc/modules | grep hello is hello 12490 0 - Live 0x0000000000000000 (POF).

When I check in dmesg, I can see the logs Hello Module Inserted : 3. When I try to remove the module, I am getting the below error

rmmod: ERROR: ../libkmod/libkmod-module.c:769 kmod_module_remove_module() could not remove 'hello': Device or resource busy
rmmod: ERROR: could not remove module hello: Device or resource busy

Output of cat /proc/modules | grep hello is hello 12422 0 - Unloading 0x0000000000000000 (POF-)

My question is how to remove that module? And what is wrong with sequence/code?


First of all , there is a return statement in your my_exit function which is causing this problem.

And as for unloading part, if you want to forcefully remove a module then you have to enable CONFIG_MODULE_FORCE_UNLOAD in the kernel. Otherwise, you have to restart your system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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