HOWTO: Prevent (blacklist) modules from loading
Introduction
It is sometimes useful to prevent a module from loading. This howto will show you how to do this, and should be applicable to most modern Linux distros. This is really easy to do, so if you want you can just skip to the end to see how to do it; if you are more interested in how this stuff actually works, read the full howto.
My motivation for doing this was to prevent the system bell from sounding. In other words, I didn't want my laptop to beep if I backspaced on an empty line in a virtual console, or put my laptop into sleep mode. The system bell (which is actually a buzzer not controlled by your speakers) is accessed via the pcspkr module.
In most modern Linux distributions (I think from kernel 2.2 onwards) the module settings are controlled by the file /etc/modprobe.conf and the files in the /etc/modprobe.d directory. In particular, if you are running udev on your system one of the things that udev does is check all of these files and load modules based on their contents. This is a good thing, because it means that you can create your own files in /etc/modprobe.d to fiddle with the files that come with the module-init-tools package.
Creating a blacklist file
Since you probably don't want to mess with any of the files that come with your system, you will want to create a new file to hold all of the rules that you write. I called mine blacklist-custom, but you can call yours anything that isn't already taken. This file goes in the /etc/modprobe.d directory. Once you have created the file, you can blacklist modules by adding a line of the form "blacklist name_of_module". Lines starting with a # are ignored. My file looks like this:
Code:
# /etc/modprobe.d/blacklist-custom
# Custom blacklist file so I don't mess with any of the files that come with
# the module-init-tools package.
blacklist pcspkr
The changes will take place next time you reboot (well, technically the next time you reload udev).
Manually loading/unloading and listing modules
If you want to unload the module without rebooting, you can use the command
Code:
user@ubuntu$ sudo modprobe -r pcspkr
If you later decide you want to manually load a module, issue the command
Code:
user@ubuntu$ sudo modprobe pcspkr
To check whether or not a module is running, use the lsmod command. Since you will probably get a pretty long list, you can check for a particular module by combining lsmod with grep. For example to list all loaded modules, use
and to check if any modules with "spkr" in the name are loaded, use
Code:
user@ubuntu$ lsmod | grep spkr
Re: HOWTO: Prevent (blacklist) modules from loading
Thanx for the info, i am going to try and use this for my wireless card, rather use ndiswrapper instead. hopefully it works better.
Re: HOWTO: Prevent (blacklist) modules from loading
thanks, your info was helpful.
only one thing: sometimes it's necessary to update the initramfs with
update-initramfs -u
so that the module really does not load.
flow
Re: HOWTO: Prevent (blacklist) modules from loading
Thanks to both eklitzke and flow_ca -- this is great information and helped me along a good bit.
Re: HOWTO: Prevent (blacklist) modules from loading
Thanks. Just tried it and worked.
Re: HOWTO: Prevent (blacklist) modules from loading
thanks!
and as for disabling the beep sound you also can use the command:
and put it in your .profile
Re: HOWTO: Prevent (blacklist) modules from loading
newer versions need the blacklist file to have the .conf extension.
offtopic:
A wiki would be much better for such tutorials, don't you guys think?
Re: HOWTO: Prevent (blacklist) modules from loading
I've got a problem with Virtualbox since upgrading to 9.10. The modules kvm-intel and kvm are running and prevent virtualbox from starting a VM. I've added the lines
blacklist kvm_intel
blacklist kvm
to the blacklist.conf file, however after a reboot these modules still load.
every time I start virtualbox I need to preceed this with:
sudo rmmod kvm_intel kvm
Anyone got any ideas how to get rid of this nasty beastie thats making my Koala far from Kalm?
Re: HOWTO: Prevent (blacklist) modules from loading
Anybody have any ideas for Gresley?
Re: HOWTO: Prevent (blacklist) modules from loading
I had this same problem. It turns out the qemu manually loads the kvm kernel module. So if you run
Quote:
sudo apt-get remove qemu-kvm qemu --purge
It should no longer load the kvm kernel modules.