Tuesday, August 17, 2010

Installing and Removing Modules in Ubuntu

Modules are relatively easy to install. The insmod command loads modules, and rmmod removes modules. The modprobecommand actually uses insmod and rmmod but adds a little more intelligence. The modprobe command can resolve dependencies and search for modules.

As an example, let’s look at the suni.ko ATM driver (you probably do not have it installed, and you probably don’t need it). Listing 3-1 shows different queries for the driver, installing the driver, and removing it.

Asynchronous transfer mode (ATM) network cards are uncommon on home PCs, so this is a good type of device driver to play with when learning how to
load and unload LKMs. If we used a common driver for this example, then you could end up disabling your hard drive, printer, or other device. If you do happen to have a Saturn User Network Interface (SUNI) ATM card, then consider using a different driver for this example, such as pppoatm.

Listing 3-1: Sample LKM Queries and Management
$ modinfo suni # information about the module
filename: /lib/modules/2.6.24-26-generic/kernel/drivers/atm/suni.ko
license: GPL
srcversion: 4F4DC0C890932441A81CC12
depends:
vermagic: 2.6.24-26-generic SMP mod_unload 586
$ lsmod | grep suni # see if it is installed
[none found]
$ modprobe -l -t atm # show all ATM modules
/lib/modules/2.6.24-26-generic/kernel/drivers/usb/atm/cxacru.ko
/lib/modules/2.6.24-26-generic/kernel/drivers/usb/atm/usbatm.ko
/lib/modules/2.6.24-26-generic/kernel/drivers/usb/atm/speedtch.ko
/lib/modules/2.6.24-26-generic/kernel/drivers/usb/atm/ueagle-atm.ko
/lib/modules/2.6.24-26-generic/kernel/drivers/usb/atm/xusbatm.ko
/lib/modules/2.6.24-26-generic/kernel/drivers/atm/idt77252.ko
/lib/modules/2.6.24-26-generic/kernel/drivers/atm/iphase.ko
/lib/modules/2.6.24-26-generic/kernel/drivers/atm/he.ko
/lib/modules/2.6.24-26-generic/kernel/drivers/atm/atmtcp.ko
/lib/modules/2.6.24-26-generic/kernel/drivers/atm/fore_200e.ko
/lib/modules/2.6.24-26-generic/kernel/drivers/atm/nicstar.ko
/lib/modules/2.6.24-26-generic/kernel/drivers/atm/lanai.ko
/lib/modules/2.6.24-26-generic/kernel/drivers/atm/suni.ko
...
$ modprobe -l '*suni*' # Show only the suni.ko module
/lib/modules/2.6.24-26-generic/kernel/drivers/atm/suni.ko
$ modprobe -l -a 'suni’ # Show all suni modules
/lib/modules/2.6.24-26-generic/kernel/drivers/atm/suni.ko
$ sudo modprobe -a suni # install all suni modules
$ lsmod | grep suni # show it is installed
suni 7504 0
$ sudo modprobe -r suni # remove it
$ lsmod | grep suni # show it is removed
[none found]


Using modprobe -l without any other parameters will list every module on the system.

The installation step could also be accomplished using

sudo insmod /lib/modules/2.6.24-26-generic/kernel/drivers/atm/suni.ko

Similarly, removal could also use any of the following commands:

sudo rmmod /lib/modules/2.6.24-26-generic/kernel/drivers/atm/suni.ko
sudo rmmod suni.ko
sudo rmmod suni

To make the installation permanent, you can add the module name to either /etc/modules or /etc/modprobe.d/. (See the man pages for modules and modprobe.conf.) In general, /etc/modules is simpler for adding a new module, since it just lists onemodule per line.However, the /etc/modprobe.d/ configuration files permit more configuration options.

Source of Information : Wiley Ubuntu Powerful Hacks And Customizations

No comments: