Enable/disable module in kernel for controlling hardware on/off.

anyname

New Member
Joined
Jun 22, 2021
Messages
3
Reaction score
1
Credits
38
Is there a method enable/disable active kernel module or is there a dist that can disable active kernel modules "on the fly" without reboot ?

- Iam not asking how to blacklist modules.
- Im not asking how to compile own kernel without certain modules.
- Im asking to disable/enable necessary active kernel module without rebooting to disable hardware controlled by the specific module.

I want to use linux instead of windows and for this I need the ability enable/disable hardware such as networkcard, cpu fan, usb ports as I can do in windows. When using modprobe -r -f or rmmod the module is "unlisted" but still used by kernel. I can see the modules is controlled as they are listed/not listed when running the coammnds but as long as kernel is using the module, module is still active in kernel and thereby also the hardware I want to disable when running modprobe -r the module is only hidden from me as user.

Please do not troll this post with posts on blacklisting of modules, custom kernel compiling etc as that is not in scope here. I want the ability to turn hardware on/off and is hoping to use kernel modules or other function to safely disable network cards for an hour or two until sensitive work is done, or disable usb ports and only activate usb when absolutely needed. Yes I can yank the network cable, turn off the wifi router, cut the wires to the usb ports or send my computer into orbit on a rocket outside wifi coverage etc but as linux states it is "safe" Im asking how to disable hardware to achieve that safety.

EDIT : reason for asking for distro is that man pages for rmmod mentions the switch CONFIG_MODULE_FORCE_UNLOAD enabling force unload but need to find a distro with that active.
 
Last edited:


To disable networking you can just right click on the network-manager applet and uncheck "Enable Networking" and it will disable your network connections.
Code:
 ping -c3 10.31.251.1
PING 10.31.251.1 (10.31.251.1) 56(84) bytes of data.
64 bytes from 10.31.251.1: icmp_seq=1 ttl=64 time=0.366 ms
64 bytes from 10.31.251.1: icmp_seq=2 ttl=64 time=0.266 ms
64 bytes from 10.31.251.1: icmp_seq=3 ttl=64 time=0.253 ms

--- 10.31.251.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2073ms
rtt min/avg/max/mdev = 0.253/0.295/0.366/0.050 ms
Code:
 ping -c3 10.31.251.1
ping: connect: Network is unreachable
For control over your hardware the only software that I know of is Corectrl, I have never used it so not sure if you can do what you want with it. As for modprobe it actually removes a kernel module, I just tried it on a system and removed the network module and I don't have a network connection anymore. Blacklisting a kernel module prevents it from loading during boot, I just tried blacklisting the the same module for my networkcard on that same system and rebooted and I don't have a network connection.
 
For control over your hardware the only software that I know of is Corectrl, I have never used it so not sure if you can do what you want with it. As for modprobe it actually removes a kernel module, I just tried it on a system and removed the network module and I don't have a network connection anymore. Blacklisting a kernel module prevents it from loading during boot, I just tried blacklisting the the same module for my networkcard on that same system and rebooted and I don't have a network connection.

Good news, what dist are you running that have the CONFIG_MODULE_FORCE_UNLOAD enabled ?

Had alook at corectrl but it seems restricted to GPU mostly.
 
Arch and a Rhel clone, but disable the network by right clicking on the networkmanager applet and unchecking "Enable Networking" does the same and more user friendly.
 
The simple and accurate answer is no. And you should not take CONFIG_MODULE_FORCE_UNLOAD for granted. Even after CONFIG_MODULE_FORCE_UNLOAD=y is set, `rmmod -f` still does not work. It simply hangs until all programs using the module are manually closed. For example, `nvidia.ko` is used by Firefox for hardware decoding of videos, `rmmod -f nvidia` will hang until you close Firefox.
 
Is there a method enable/disable active kernel module or is there a dist that can disable active kernel modules "on the fly" without reboot ?
....
I want to use linux instead of windows and for this I need the ability enable/disable hardware such as networkcard, cpu fan, usb ports as I can do in windows.
....
I want the ability to turn hardware on/off and is hoping to use kernel modules or other function to safely disable network cards for an hour or two until sensitive work is done, or disable usb ports and only activate usb when absolutely needed.

There are alternative ways to control a linux system other than removing modules if you are interested in broadening your approach to managing "sensitive work". The usual way of shutting down services and functionality is to use the software that is already part of those programs that run the hardware. For items which don't provide such software facility, it's only a matter of the user's ingenuity in writing a shell script or a systemd service or creating a compiled program for the purpose. Such scripts proliferate online. I guess there are significant differences between the flexibility linux provides with its numerous alternative means to deal with such issues, and ways in which MS Windows does. There's a learning curve with linux that will achieve your aims one way or another.

As an example on controlling usb ports, see:
Here's another example:
 
Last edited:

Members online


Top