Linux remove kernel driver

Howto: Linux Add or Remove a Linux Kernel Modules / Drivers

A kernel module is a program which can loaded into or unloaded from the kernel upon demand, without necessarily recompiling it (the kernel) or rebooting the system, and is intended to enhance the functionality of the kernel.

In general software terms, modules are more or less like plugins to a software such as WordPress. Plugins provide means to extend software functionality, without them, developers would have to build a single massive software with all functionalities integrated in a package. If new functionalities are needed, they would have to be added in new versions of a software.

Likewise without modules, the kernel would have to be built with all functionalities integrated directly into the kernel image. This would mean having bigger kernels, and system administrators would need to recompile the kernel every time a new functionality is needed.

A simple example of a module is a device driver – which enables the kernel to access a hardware component/device connected to the system.

List All Loaded Kernel Modules in Linux

In Linux, all modules end with the .ko extension, and they are normally loaded automatically as the hardware is detected at system boot. However a system administrator can manage the modules using certain commands.

To list all currently loaded modules in Linux, we can use the lsmod (list modules) command which reads the contents of /proc/modules like this.

Module Size Used by rfcomm 69632 2 pci_stub 16384 1 vboxpci 24576 0 vboxnetadp 28672 0 vboxnetflt 28672 0 vboxdrv 454656 3 vboxnetadp,vboxnetflt,vboxpci bnep 20480 2 rtsx_usb_ms 20480 0 memstick 20480 1 rtsx_usb_ms btusb 45056 0 uvcvideo 90112 0 btrtl 16384 1 btusb btbcm 16384 1 btusb videobuf2_vmalloc 16384 1 uvcvideo btintel 16384 1 btusb videobuf2_memops 16384 1 videobuf2_vmalloc bluetooth 520192 29 bnep,btbcm,btrtl,btusb,rfcomm,btintel videobuf2_v4l2 28672 1 uvcvideo videobuf2_core 36864 2 uvcvideo,videobuf2_v4l2 v4l2_common 16384 1 videobuf2_v4l2 videodev 176128 4 uvcvideo,v4l2_common,videobuf2_core,videobuf2_v4l2 intel_rapl 20480 0 x86_pkg_temp_thermal 16384 0 media 24576 2 uvcvideo,videodev .

How to Load and Unload (Remove) Kernel Modules in Linux

To load a kernel module, we can use the insmod (insert module) command. Here, we have to specify the full path of the module. The command below will insert the speedstep-lib.ko module.

# insmod /lib/modules/4.4.0-21-generic/kernel/drivers/cpufreq/speedstep-lib.ko

To unload a kernel module, we use the rmmod (remove module) command. The following example will unload or remove the speedstep-lib.ko module.

# rmmod /lib/modules/4.4.0-21-generic/kernel/drivers/cpufreq/speedstep-lib.ko

How to Manage Kernel Modules Using modprobe Command

modprobe is an intelligent command for listing, inserting as well as removing modules from the kernel. It searches in the module directory /lib/modules/$(uname -r) for all the modules and related files, but excludes alternative configuration files in the /etc/modprobe.d directory.

Читайте также:  My ini file in linux

Here, you don’t need the absolute path of a module; this is the advantage of using modprobe over the previous commands.

To insert a module, simply provide its name as follows.

To remove a module, use the -r flag like this.

Note: Under modprobe, automatic underscore conversion is performed, so there is no difference between _ and – while entering module names.

For more usage info and options, read through the modprobe man page.

# man modprobe Source: https://www.tecmint.com/load-and-unload-kernel-modules-in-linux/ ow do I add or remove hardware device driver (module) from running Linux kernel? Linux systems comes with the modprobe command, to add and remove modules from the Linux Kernel. Please note that:

=> Under MS-Windows you use term device driver for modules.

=> Under Linux you use term modules for device drivers.

Tutorial details
Difficulty level Advanced
Root privileges Yes
Requirements modprobe/lsmod/modinfo utilities
Est. reading time 2 minutes
=> The Linux kernel has a modular design.

=> At boot time, only a minimal resident kernel is loaded into memory.

=> If you add new hardware you need to add driver i.e. modules.

=> The modprobe command intelligently adds or removes a module from the Linux kernel

=> Usually, all Linux kernel modules (drivers) are stored in the module directory located that /lib/modules/$(uname -r) directory. To see current modules, type:
$ ls /lib/modules/$(uname -r)
Output:

build modules.ccwmap modules.order initrd modules.dep modules.pcimap kernel modules.dep.bin modules.seriomap misc modules.devname modules.softdep modules.alias modules.ieee1394map modules.symbols modules.alias.bin modules.inputmap modules.symbols.bin modules.builtin modules.isapnpmap modules.usbmap modules.builtin.bin modules.ofmap updates

Use the following command to list all drivers for various devices:
$ ls /lib/modules/$(uname -r)/kernel/drivers/
Sample outputs:

Fig.01: Device drivers on my Linux based system

Fig.01: Device drivers on my Linux based system

Task: Add a Module (driver) Called foo

Type the following command as root user:
# modprobe foo
In this example, I am loading a module called i8k, enter:
# modprobe -v i8k
Sample outputs:

insmod /lib/modules/3.5.0-30-generic/kernel/drivers/char/i8k.ko

Find out info about loaded module

You need to use the modinfo command to see information about a Linux Kernel module. The syntax is:
# modinfo -v
# modinfo i8k
Sample outputs:

Fig.02: Displaying information about a Linux Kernel module called i8k

Fig.02: Displaying information about a Linux Kernel module called i8k

Task: List all loaded modules

Use the lsmod command to show the status of modules in the Linux Kernel:
# lsmod
Sample outputs:

Module Size Used by smbfs 75465 0 md5 5953 1 ipv6 284193 10 ipt_TOS 4033 2 iptable_mangle 4545 1 ip_conntrack_ftp 74801 0 ip_conntrack_irc 74033 0 ipt_REJECT 8897 43 ipt_LOG 8513 2 ipt_limit 4033 6 iptable_filter 4673 1 ipt_multiport 3521 4 ipt_state 3393 16 ip_conntrack 54297 3 ip_conntrack_ftp,ip_conntrack_irc,ipt_state ip_tables 21825 8 ipt_TOS,iptable_mangle,ipt_REJECT,ipt_LOG,ipt_limit,iptable_filter,ipt_multiport,ipt_state i2c_dev 13889 0 i2c_core 28865 1 i2c_dev dm_mirror 32721 0 dm_mod 68609 1 dm_mirror button 9313 0 battery 11465 0 ac 6985 0 ohci_hcd 24529 0 ehci_hcd 33989 0 tg3 109381 0 floppy 66065 0 ext3 137937 2 jbd 69105 1 ext3 sata_svw 10053 3 libata 78345 1 sata_svw sd_mod 19393 4 scsi_mod 141457 2 libata,sd_mod

Task: Remove a module called foo

Pass the -r option to modprobe command to remove a module, type:
# modprobe -r foo
You can also use the rmmod command, which is simple program to remove a module from the Linux Kernel:
# rmmod foo

Читайте также:  Linux terminal change colours
Recommended readings

Источник

Delete kernel module completely

I would like to ask you how can I delete some kernel module completely? I mean really delete, not unload or prevent to load. I tried to use rmmod , but it just unloaded module, same as modprobe -r . So I got list of all modules using modprobe -n -v and deleted them manually.

rmmod cramfs: ERROR: Module cramfs does not exist in /proc/modules 
modprobe -v -n cramfs: FATAL: Could not open '/lib/modules/2.6.32-573.12.1.el6.x86_64/kerne/fs/cramfs/cramfs.ko': No such file or directory 

but that means, system still got some information about removed module because it knows the path to the cramfs.ko file. Example of not loaded, but loadable module:

modprobe -v -n jffs2 insmod /lib/modules/2.6.32-573.12.1.el6.x86_64/kernel/lib/zlib_deflat/zlib_deflate.ko insmod /lib/modules/2.6.32-573.12.1.el6.x86_64/kernel/fs/jffs2/jffs2.ko rmmod jffs2 ERROR: Module jffs2 does not exist in /proc/modules 

Recompile the kernel, using make menuconfig , (or xconfig, or gconfig), and uncheck the unwanted module.

May I ask, why do you want to do this and what would be the real task? (Real task, for example: release some storage allocated by unnecessary modules) If you installed your kernel and modules by a package manager, then I recommend, not to do it.

Ooops. I just noticed, your system is possibly, a router. I fear, you can’t remove these modules except, you build an own firmware from source.

3 Answers 3

Modules are loaded into RAM (and linked to the running kernel) at runtime when required somehow. Until that happens, they (only) use disk space (or it’s equivalent).

You can save a bit of disk space by building your own kernel that has the module configured out. The kernel will be a very tiny bit faster using the relevant functionality if you build a kernel that includes (not as modules, builtin) whatever you need. But that is a huge hit in flexibility and hassle.

If a kernel module is not loaded, it’s the same as if it doesn’t exist, unless it was built into the kernel (I’ll explain that below), the only exception is you typically can later reload it with an insmod command.

The reason why you get the path in the error message with modprobe is because modprobe is hardcoded to check standard locations for modules (reference). There’s no configuration file or anything telling modprobe to do that. (If your module is not in the standard paths and you want to insert it you can always use insmod ).

Modules are loaded by some mechanism outside of the kernel after the kernel starts. systemd can load modules, so can udev . You have to find out what mechanism your system uses and blacklist a module from that.

jffs2 strongly suggests you’re doing this on a router or other device like an Android phone. Need more information on the make/model of the device to give you specific advice here.

Читайте также:  Linux dev ttyusb0 permissions

There’s two reasons why you might be getting that error about `/proc/modules:

  1. In your example with modprobe jffs2 and then the error you get with rmmod — it may be the insmod jffs2.ko didn’t work but no error message was printed. Check your logs ( dmesg , etc.) for errors.
  2. The proc virtual filesystem is not mounted. Things like chroot , SELinux, and kernel capabilities can prevent you from accessing or mounting /proc even as root. Check if you can ls /proc and get something like that looks like a list of directories for each PID on your system. If you are running this in a chroot you have to bind mount /proc into your chroot .

It’s possible to build a module into a kernel. This makes it part of the kernel. It’s no longer a module at that point so rmmod and other things won’t work. I am not sure what will happen if you try to insmod a module that is part of the kernel (it will probably give you a cryptic «file in use» error referring to kernel resources already in use).

It used to be common to build in support for disk controllers and such and some embedded platforms may still do the same for devices needed to access the software.

Источник

Linux Mint Forums

Forum rules
There are no such things as «stupid» questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Please stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions prefer the other forums within the support section.
Before you post please read how to get help. Topics in this forum are automatically closed 6 months after creation.

Proper way to remove a driver?

Post by MRK0017 » Sat Sep 22, 2018 7:02 am

I manually installed some drivers for my wifi adapter (RTL8812au).

And rtfm. It worked. The module is installed, and I can find it in /lib/modules/4.15.0-20-generic/kernel/drivers/net/wireless/rtl8812au.ko

But I noticed that this driver doesn’t seem to work 100%. Sometimes when I turn on my computer I have to unplug the usb adapter and then plug it in again to make it work. I want to try another driver, because I had a similar problems some time ago on Windows 7 with another adapter, and I solved it by installing an updated driver manually.

What is the proper way to remove this driver? Can I just brutally delete the .ko file or is there a more elegant way to do so?

Also as a bonus, can I get some basic info on what happens when you do the part related to DKMS in the instruction and what DKMS actually is and what it does?

Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.

Источник

Оцените статью
Adblock
detector