LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 11-26-2008, 12:50 AM   #1
duyuyang
Member
 
Registered: Mar 2008
Posts: 56

Rep: Reputation: 16
How to force remove a kernel module


I am developing a kernel module. Something wrong happens, so I want to remove this module. But the kernel says it is in use, even I add the force option to rmmod utility, it is still holding there.

rmmod **** -f
ERROR: Removing '****': Device or resource busy

Anyone knows what I should do, other than reboot.

Thanks,
Shawn

Last edited by duyuyang; 11-26-2008 at 12:57 AM.
 
Old 11-26-2008, 01:25 AM   #2
datopdog
Member
 
Registered: Feb 2008
Location: JHB South Africa
Distribution: Centos, Kubuntu, Cross LFS, OpenSolaris
Posts: 806

Rep: Reputation: 41
Try
Code:
modprobe -rf
 
Old 11-26-2008, 01:39 AM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
You may need to remove modules that depend on the module. You may also need to stop a service that uses it. One example shutting down a NIC device before unloading the kernel module for that device. Not doing so could lead to a lockup.
 
Old 11-26-2008, 08:59 PM   #4
duyuyang
Member
 
Registered: Mar 2008
Posts: 56

Original Poster
Rep: Reputation: 16
Thank you both.

Quote:
Originally Posted by jschiwal View Post
You may need to remove modules that depend on the module. You may also need to stop a service that uses it. One example shutting down a NIC device before unloading the kernel module for that device. Not doing so could lead to a lockup.
The module communicates with a user space partner using Netlink.
It might not have any other modules dependent on it.
Anyway, I want to know if I can get the information about what modules or kernel threads or anything depend on a certain given module.

BTW: Distro is short for distribution. Why the O? It is interesting. Maybe distribution, have you got any better explanation?
 
Old 11-26-2008, 09:04 PM   #5
dxqcanada
Member
 
Registered: Sep 2006
Location: Canada
Distribution: Gentoo
Posts: 702

Rep: Reputation: 43
modinfo will show what other module is a dependency.

rmmod -f will only work if CONFIG_MODULE_FORCE_UNLOAD is enabled in the kernel ... not sure if modprobe -r has the same restriction.

Last edited by dxqcanada; 11-26-2008 at 09:05 PM.
 
1 members found this post helpful.
Old 11-26-2008, 09:13 PM   #6
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Run "lsmod". On the right hand side of the line are the modules that depend on the module on the left.
Code:
lsmod | grep i2c
i2c_nforce2            24704  0
i2c_core               45344  2 nvidia,i2c_nforce2
The nvidia and i2c_nforce2 depend on the i2c_core module, so I couldn't simply remove the i2c_core module.
Code:
/sbin/modinfo nvidia | grep -v -e alias: -e parm:
filename:       /lib/modules/2.6.25.18-0.2-default/weak-updates/nvidia.ko
license:        NVIDIA
depends:        i2c-core
supported:      external
vermagic:       2.6.25.11-0.1-default SMP mod_unload
The modinfo can supply more information about modules. Here you see that nvidia needs the i2c-core module.
 
Old 11-27-2008, 01:42 AM   #7
duyuyang
Member
 
Registered: Mar 2008
Posts: 56

Original Poster
Rep: Reputation: 16
Quote:
Try modprobe -rf
modprobe -rf is more powerful than rmmod, sometimes it can remove an in use module. Don't know why, in some other cases, I just learned that.
So thank datopdog.

Module may not be removed by rmmod even if no other modules depend on it, according to the dependency information obtained from lsmod.

Thank you all. I learned a lot about modules and their dependency from you.

All the best,
Shawn

Last edited by duyuyang; 11-27-2008 at 01:43 AM.
 
1 members found this post helpful.
Old 09-05-2016, 05:05 AM   #8
randyman99
LQ Newbie
 
Registered: Dec 2014
Posts: 7

Rep: Reputation: Disabled
I ran into the same problem, and came to realize that my module was installed with dkms. Therefore, I had to remove it with dkms, rather than with modprobe. The command will look something like this:

Code:
sudo dkms remove -m <module-name> -v <version-number> -k $(uname -r);

The <module-name> and <version-number> are from the dkms.conf file in the module package root directory.
The snippet $(uname -r) will return the current kernel version, so this will only remove the module from the current kernel, so it will remain for previous versions, or you can use --all to remove it from all kernels.

Once you do this, you can rebuild and reinstall the module with dkms if that is what you chose to do.
 
Old 09-06-2016, 03:59 PM   #9
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
And that is also why you develop kernel stuff on VMs, and get rather used to rebooting them a lot ...
 
Old 09-06-2016, 11:43 PM   #10
randyman99
LQ Newbie
 
Registered: Dec 2014
Posts: 7

Rep: Reputation: Disabled
Smile

Quote:
Originally Posted by sundialsvcs View Post
And that is also why you develop kernel stuff on VMs, and get rather used to rebooting them a lot ...
Actually, I find it advantageous to have a multiboot system, so I was never dead in the water. But I did want to get the new upgrade working - ever forward. In fact, I have Xubutnu installed twice, once on each of two different drives, as well as Ubuntu installed on both drives, plus Vector and Puppy both installed once on the second drive, in addition to Windows 10 which hardly ever gets used anymore (aren't 2 TB drives grand?). I also check out other distros from time to time to see if there's any I like.

As my wifi router is in another room, some months ago I also took my old Linksys 802.11-G router and turned it around as a wifi bridge, and run my wired adapter to that as a backup, so it appears to my network manager that I have both wired and wifi connections. The "wired" is slower than the wifi -- dog-slow for doing partition backups, but is fine for internet browsing, and helped me get through the period of having the true wifi adapter down. Normally I have it disabled and just use the wifi. If you don't have an old 802.11-g router in a closet somewhere, they are dirt cheap now, and make a good insurance policy as a bridge.

But good advice, sundialsvcs . I've worked with simulators before, but not VMware. I'll have to give it a spin. Thanks.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How Can I Force Removal of a Kernel Module (ERROR: Module usb_storage is in use) klearview Linux - Software 2 10-10-2008 09:20 PM
how to remove a module from kernel htamayo Debian 1 06-18-2008 11:31 AM
JMicron controller issues + how do I permanently remove a module from the kernel? xtknight Linux - Hardware 10 03-28-2007 08:25 AM
unable to remove kernel module........ dogslayer Linux - Software 6 03-27-2006 12:26 AM
How to remove module from kernel without recompile? Stoic Linux - Software 10 09-23-2003 06:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 08:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration