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:
The changes will take place next time you reboot (well, technically the next time you reload udev).
# Custom blacklist file so I don't mess with any of the files that come with
# the module-init-tools package.
Manually loading/unloading and listing modules
If you want to unload the module without rebooting, you can use the command
If you later decide you want to manually load a module, issue the command
user@ubuntu$ sudo modprobe -r 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
user@ubuntu$ sudo modprobe pcspkr
and to check if any modules with "spkr" in the name are loaded, use
user@ubuntu$ lsmod | grep spkr