This situation always bother me:
I wrote a kernel module, and sometimes it has a bug(dereference a NULL pointer). After I insmod hello.ko, it shows some kernel errors. Then I change the code, and try to remove the module and install it again. The question is: I don't know how to remove the kernel module.
$ rmmod hello
ERROR: module hello in use
$ rmmod -f hello
ERROR: removing hello: device or resource busy
I always reboot the machine in order to remove the module, which takes too long. Does anyone have a better solution for this? Thanks for any inputs.
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.
First, boot into a new kernel. List all other older kernel using the dpkg command. Note down system disk space usage by running the df -H command. Delete all unused old kernels, run: sudo apt --purge autoremove.
The Linux kernel has a modular design. Functionality is extendible with modules or drivers. Use the modprobe command to add or remove modules on Linux. The command works intelligently and adds any dependent modules automatically.
They are located in /lib/modules or /usr/lib/modules and have had the extension . ko ("kernel object") since version 2.6 (previous versions used the .o extension). The lsmod command lists the loaded kernel modules.
Use a virtual machine.
Once you make a NULL dereference or other such mistake, you've put the kernel into an unknown state. Even if you did manage to remove the module (which is unlikely to be possible; a kernel OOPS kills the calling thread, so it'll never have a chance to reduce the reference count - the module will never be removable) there may still be corruption left behind, and your new, 'fixed' module is just as likely to be in trouble.
Much better to just use a fast-to-reboot virtual machine - perhaps with a snapshot, to make restoration even faster.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With