个人工具

UbuntuHelp:Loadable Modules

来自Ubuntu中文

跳转至: 导航, 搜索

What are loadable modules(Drivers)

Modules are to Linux what drivers are for Windows. Most modules come supplied with the linux distrubution, unlike windows which mostly come supplied form the hardware manufacturer. The Linux kernel can be extended to have more capabilities two basic ways:

  • Recompile the kernel with new capabilities "compiled-in" and reboot the new kernel
  • Build the kernel with loadable modules you might want occasionally. If you want a module's features to be added to your kernel, the the module can either automatically be loaded, or you can manually load it. When you are done using the module, you can either remove it from your kernel, or it can disappear automatically.

When you configure and build your kernel, if you specify a kernel feature with a y then the software to support it will be part of your kernel (the features will be "compiled into" your kernel and always using up memory). If you specify the feature with an m then the feature will be a loadable module that can come and go as you wish (and will use memory only if the module is loaded). An n means the feature will not be enabled in the kernel.

Using loadable modules

The file /etc/modules configures which loadable modules are automatically loaded. Here is a sample:

nano -w /etc/modules
 
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.

loop
lp
fuse
r8169

Changing /etc/modules: Let's say your eepro100 Ethernet device breaks and you buy a new Ethernet card that uses the tulip driver. In this case, the relevant line in /etc/modules file should be changed to:

tulip

In most cases, when you reboot with your new Ethernet card, Ubuntu's configuration manager should automatically notice a new Ethernet card is installed, and change the /etc/modules file for you. To see a list of loadable kernel modules on your system with their status:

lsmod
Module                  Size  Used by    Not tainted
i810_audio             26408   2 (autoclean)
ac97_codec             13768   0 (autoclean) [i810_audio]
soundcore               7108   2 (autoclean) [i810_audio]
scanner                10716   0 (unused)
mousedev                5688   0 (unused)
keybdev                 2944   0 (unused)
input                   6176   0 [mousedev keybdev]
hid                    11804   0 (unused)
usb-uhci               27436   0 (unused)
usbcore                81088   1 [scanner hid usb-uhci]

To see a list of the module files:

modprobe --list
/lib/modules/2.4.20/kernel/drivers/block/floppy.o
/lib/modules/2.4.20/kernel/drivers/block/loop.o
/lib/modules/2.4.20/kernel/drivers/char/rtc.o
/lib/modules/2.4.20/kernel/drivers/input/input.o
/lib/modules/2.4.20/kernel/drivers/input/keybdev.o
/lib/modules/2.4.20/kernel/drivers/input/mousedev.o
/lib/modules/2.4.20/kernel/drivers/net/dummy.o
/lib/modules/2.4.20/kernel/drivers/scsi/atp870u.o
/lib/modules/2.4.20/kernel/drivers/scsi/scsi_mod.o
/lib/modules/2.4.20/kernel/drivers/scsi/st.o
/lib/modules/2.4.20/kernel/drivers/sound/ac97_codec.o
/lib/modules/2.4.20/kernel/drivers/sound/i810_audio.o
/lib/modules/2.4.20/kernel/drivers/sound/soundcore.o
/lib/modules/2.4.20/kernel/drivers/usb/dc2xx.o
/lib/modules/2.4.20/kernel/drivers/usb/hid.o
/lib/modules/2.4.20/kernel/drivers/usb/scanner.o
/lib/modules/2.4.20/kernel/drivers/usb/usb-uhci.o
/lib/modules/2.4.20/kernel/drivers/usb/usbcore.o
/lib/modules/2.4.20/kernel/fs/fat/fat.o
/lib/modules/2.4.20/kernel/fs/msdos/msdos.o
/lib/modules/2.4.20/kernel/fs/vfat/vfat.o

or to search

modprobe --list *8169*
/lib/modules/2.6.24-16-server/kernel/drivers/net/r'''8169'''.ko

To load a module, and any modules that it needs, use modprobe:

modprobe st

To remove a loaded module, use rmmod:

rmmod st

To get information about a module, use modinfo:

modinfo st
filename:    /lib/modules/2.4.20/kernel/drivers/scsi/st.o
description: "SCSI Tape Driver"
author:      "Kai Makisara"
license:     "GPL"
parm:        buffer_kbs int, description "Default driver buffer size (KB; 32)"
parm:        write_threshold_kbs int, description "Asynchronous write threshold (KB; 30)"
parm:        max_buffers int, description "Maximum number of buffer allocated at initialisation (4)"
parm:        max_sg_segs int, description "Maximum number of scatter/gather segments to use (32)"
parm:        blocking_open int, description "Block in open if not ready an no O_NONBLOCK (0)"

Blacklist Module

For various reasons you might want to stop a module form loading, In this case you can blacklist the module in /etc/modprobe.d/blacklist

nano -w /etc/modprobe.d/blacklist

for example add the line

blacklist e100