RHEL6-23-LINUX
KERNEL -2
KERNEL TUNING:
As we already know that “lsmod” is used to
get the info about loaded modules.
LOADING KERNEL MODULES:
There are 2 ways to load
the kernel modules, “insmod” and “modprobe”
“insmod” inserts a single module into the kernel, provided
underlying dependencies are already loaded.
“modprobe” also used to load single module but it automatically
loads any depended on modules.
We must ensure that the module is not
already loaded before attempting to load it with custom parameters. The
modprobe command does not automatically reload the module, or alert us that it
is already loaded.
How to check that a
module is loaded or not?
[root@rhel6-test1 ~]# lsmod |grep
bluetooth
bluetooth 99239 9 rfcomm,sco,bnep,l2cap,btusb
rfkill 19255 3 bluetooth
In which directory I can
find the modules?
[root@rhel6-test1 ~]# ls -l
/lib/modules/`uname -r`
[root@rhel6-test1 ~]# insmod
/lib/modules/2.6.32-358.el6.x86_64/kernel/drivers/cdrom/cdrom.ko
insmod: error inserting
'/lib/modules/2.6.32-358.el6.x86_64/kernel/drivers/cdrom/cdrom.ko': -1 File
exists
[root@rhel6-test1 ~]# insmod
/lib/modules/2.6.32-358.el6.x86_64/kernel/drivers/usb/storage/usb-storage.ko
If we attempt to load a module that depends
on others and those other modules aren’t loaded, insmod will fail. When this
happens, we must either track down and manually load the dependent modules or
use modprobe.
“modprobe”
-v to verbose
-C <filename> --config filename
-n to dry run
-r to remove
-f to force to load the module
-l to list
[root@rhel6-test1 ~]# modprobe -l usb_storage
kernel/drivers/usb/storage/usb-storage.ko
[root@rhel6-test1 ~]# modprobe -l usb*
kernel/drivers/net/wireless/libertas/usb8xxx.ko
kernel/drivers/net/usb/usbnet.ko
kernel/drivers/usb/storage/usb-storage.ko
kernel/drivers/usb/misc/usblcd.ko
kernel/drivers/usb/misc/usbled.ko
kernel/drivers/usb/misc/usbsevseg.ko
kernel/drivers/usb/class/usblp.ko
kernel/drivers/usb/class/usbtmc.ko
kernel/drivers/usb/serial/usbserial.ko
kernel/drivers/usb/serial/usb_debug.ko
kernel/drivers/usb/serial/usb_wwan.ko
kernel/drivers/usb/atm/usbatm.ko
kernel/drivers/input/touchscreen/usbtouchscreen.ko
kernel/drivers/media/video/usbvision/usbvision.ko
kernel/drivers/isdn/gigaset/usb_gigaset.ko
As we had seen, there is clear option “-r” to remove modules via
“modprobe”, but we have one more command “rmmod” to remove modules.
What is the difference between “modprobe –r” and “rmmod”
“rmmod” is similar to “insmod”.
As we can insert one module via “insmod” bet before that we need to
take care of dependencies.
Similarly, with “rmmod” we can remove one module but again we need to
take care of dependencies.
If we try to unload a module that’s depended upon by other modules or
is in use, rmmod will return an error message.
OPTIONS
-v --verbose | Print messages about what the program is doing. Usually rmmod prints messages only if something goes wrong. |
-f --force | This option can be extremely dangerous: it has no effect unless |
CONFIG_MODULE_FORCE_UNLOAD was set when the kernel was compiled. | |
With this option, you can remove modules which are being used, | |
or which are not designed to be removed, or have been marked as unsafe |
|
-w --wait | Normally, rmmod will refuse to unload modules which are in use. |
With this option, rmmod will isolate the module, and wait until | |
the module is no longer used. Nothing new will be able to use | |
the module, but it’s up to you to make sure the current users | |
eventually finish with it. See lsmod(8)) for information on | |
usage counts. | |
-s --syslog | Send errors to syslog instead of standard error. |
-V --version | Show version of program and exit. |
[root@rhel6-test1 ~]# rmmod dm_log
ERROR: Module dm_log is in use by dm_mirror,dm_region_hash
Let’s remove and install a module “cdrom”.
It is already mounted,
[root@rhel6-test1 ~]# df -kh
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 16G 2.3G
13G 16% /
tmpfs 370M 76K
370M 1% /dev/shm
/dev/sda1 291M 37M
240M 14% /boot
/dev/sdb1 2.0G 82M
1.8G 5% /home
/dev/sr0 3.5G 3.5G
0 100% /media ççç
[root@rhel6-test1 ~]# lsmod |grep sr
sr_mod 15177
1
cdrom
39085 1 sr_mod
[root@rhel6-test1 ~]# lsmod |grep cdrom
cdrom
39085 1 sr_mod
[root@rhel6-test1 /]# rmmod cdrom
ERROR: Module cdrom is in use by sr_mod
[root@rhel6-test1 /]# rmmod sr_mod
ERROR: Module sr_mod is in use
[root@rhel6-test1 /]# umount /media
[root@rhel6-test1 /]# rmmod sr_mod
[root@rhel6-test1 /]# rmmod cdrom
[root@rhel6-test1 /]# lsmod |grep sr
[root@rhel6-test1 /]#
[root@rhel6-test1 /]# modprobe -v sr_mod
insmod
/lib/modules/2.6.32-358.el6.x86_64/kernel/drivers/cdrom/cdrom.ko
insmod
/lib/modules/2.6.32-358.el6.x86_64/kernel/drivers/scsi/sr_mod.ko
[root@rhel6-test1 /]# mount /dev/sr0 /media/
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@rhel6-test1 /]# df -kh /media/
Filesystem Size Used Avail Use% Mounted on
/dev/sr0 3.5G 3.5G
0 100% /media
Now do it again with “modprobe –r”
[root@rhel6-test1 /]# modprobe -v -r cdrom
FATAL: Module cdrom is in use.
[root@rhel6-test1 /]# modprobe -v -r sr_mod
FATAL: Module sr_mod is in use.
[root@rhel6-test1 /]# umount /media/
CD_ROM/
RHEL_6.4 x86_64 Disc 1/
[root@rhel6-test1 /]# umount /media/RHEL_6.4\ x86_64\ Disc\
1/
[root@rhel6-test1 /]# df -kh
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 16G 2.3G
13G 16% /
tmpfs 370M 76K
370M 1% /dev/shm
/dev/sda1 291M 37M
240M 14% /boot
/dev/sdb1 2.0G 82M
1.8G 5% /home
[root@rhel6-test1 /]# modprobe -v -r cdrom
FATAL: Module cdrom is in use.
[root@rhel6-test1 /]# modprobe -v -r sr_mod
rmmod
/lib/modules/2.6.32-358.el6.x86_64/kernel/drivers/scsi/sr_mod.ko
rmmod /lib/modules/2.6.32-358.el6.x86_64/kernel/drivers/cdrom/cdrom.ko
[root@rhel6-test1 /]# lsmod |grep cdrom
[root@rhel6-test1 /]#
[root@rhel6-test1 /]# modprobe -v sr_mod
insmod
/lib/modules/2.6.32-358.el6.x86_64/kernel/drivers/cdrom/cdrom.ko
insmod
/lib/modules/2.6.32-358.el6.x86_64/kernel/drivers/scsi/sr_mod.ko
[root@rhel6-test1 /]# modinfo cdrom
filename:
/lib/modules/2.6.32-358.el6.x86_64/kernel/drivers/cdrom/cdrom.ko
license: GPL
srcversion: 1194A6A16FC30846802E082
depends:
vermagic: 2.6.32-358.el6.x86_64 SMP mod_unload
modversions
parm: debug:bool
parm: autoclose:bool
parm: autoeject:bool
parm: lockdoor:bool
parm: check_media_type:bool
parm: mrw_format_restart:bool
Whenever we do an “insmod” or “rmmod” or “modprobe”, either the
module will loaded or removed depending upon the command. We had seen that the
install/removal first refer dependency. If there is any then the process will
give an error then exits itself.
GREAT………..
But question is how does the “insmod” or “rmmod” or “modprobe” knows
about dependency.
Another tool “depmod” is used for updating the dependency. To make
sure that the module we're installing is aware of all existing modules and
dependencies. This dependency list will be used by “insmod” or “rmmod” or “modprobe”.
[root@rhel6-test1 ~]# depmod –a
modprobe expects an up-to-date modules.dep.bin file (modules.dep in
human redable format) as generated by the depmod utility. This file lists what
other modules each module needs (if any), and modprobe uses this to add or remove
these dependencies automatically.
[root@rhel6-test1
~]# cat /lib/modules/2.6.32-358.el6.x86_64/modules.dep
depmod — Generate a list of kernel module dependences and associated
map files.
How to load a Kernel Module with Custom Parameters?
Non-Persistent
Format:
/etc/modprobe.d/myfilename.conf
---------------------------------------------------------
options modname parametername=parametervalue
[root@rhel6-test1 ~]#
lsmod|grep e1000e
[root@rhel6-test1 ~]# modprobe e1000e
InterruptThrottleRate=3000,3000,3000 EEE=1
[root@rhel6-test1 ~]#
lsmod|grep e1000e
e1000e
253849 0
load the Intel PRO/1000 network driver with the interrupt throttle
rate set to 3000 interrupts per second for the first, second and third
instances of the driver, and Energy Efficient Ethernet (EEE) turned on.
How to load a Kernel Module with Custom Parameters?
Persistent
[root@rhel6-test1 ~]# vi /etc/modprobe.d/e1000e.conf
options e1000e
InterruptThrottleRate=3000,3000,3000 EEE=1
[root@rhel6-test1 ~]# depmod –a
(Here there is no sense of this command because we did not specified
any dependency for this module, so nothing will updated)
[root@rhel6-test1 ~]# modprobe e1000e
[root@rhel6-test1 ~]#
lsmod|grep e1000e
e1000e
253849 0
[root@rhel6-test1 ~]# modprobe -r e1000e
[root@rhel6-test1 ~]#
lsmod|grep e1000e
[root@rhel6-test1 ~]# modprobe e1000e
[root@rhel6-test1 ~]#
lsmod|grep e1000e
e1000e 253849
0
What is blacklisting of module?
A mechanism to prevent the kernel module from loading. This could be
useful if, for example, the associated hardware is not needed, or if loading
that module causes problems
How to blacklist a module?
[root@rhel6-test1 ~]# vim /etc/modprobe.d/e1000e.conf
#options e1000e
InterruptThrottleRate=3000,3000,3000 EEE=1
blacklist e1000e
Even though after blacklisting I can manually load/unload the module.
Let’s see it is automatically starting or not?
[root@rhel6-test1 ~]# reboot
Broadcast message from root@rhel6-test1
(/dev/pts/0) at 18:47
...
The system is going down for reboot NOW!
[root@rhel6-test1 ~]#
login as: root
root@192.168.234.144's password:
Last login: Mon Apr 10 18:49:36 2017 from 192.168.234.1
[root@rhel6-test1 ~]# lsmod|grep e1000e
[root@rhel6-test1 ~]#
[root@rhel6-test1 ~]# modprobe e1000e
[root@rhel6-test1 ~]# lsmod|grep e1000e
e1000e
253849 0
“OR”
[root@rhel6-test1 ~]# vim /etc/modprobe.d/e1000e.conf
options e1000e
InterruptThrottleRate=3000,3000,3000 EEE=1
#blacklist e1000e
[root@rhel6-test1 ~]# vim /etc/modprobe.d/blacklist.conf
blacklist e1000e çç added
this at end
[root@rhel6-test1 ~]# reboot
Broadcast message from root@rhel6-test1
(/dev/pts/1) at 19:01
...
The system is going down for reboot NOW!
[root@rhel6-test1 ~]#
login as: root
root@192.168.234.144's password:
Last login: Mon Apr 10 18:49:42 2017 from 192.168.234.1
[root@rhel6-test1 ~]# lsmod|grep e1000e
Reference & Good Read:
No comments:
Post a Comment