How to see kernel modules information and load/unload kernel modules in Linux or solaris ?

Kernel Module Loading/Unloading in Linux

Lets see how to view kernel modules in linux and how can we load or unload a module in linux.

1. View all modules available on system
We can view all available modules on a Linux system using “modprobe -l” command.

[root@nglinux ~]# modprobe -l | more
kernel/arch/x86/kernel/cpu/mcheck/mce-inject.ko
kernel/arch/x86/kernel/cpu/cpufreq/powernow-k8.ko
kernel/arch/x86/kernel/cpu/cpufreq/mperf.ko
kernel/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.ko
kernel/arch/x86/kernel/cpu/cpufreq/pcc-cpufreq.ko
kernel/arch/x86/kernel/cpu/cpufreq/p4-clockmod.ko

2. View currently loaded modules on system
To see the currently loaded modules on system, we can use lsmod command.

[root@nglinux ~]# lsmod
Module                  Size  Used by
bnx2fc                 80024  0
cnic                   47474  1 bnx2fc
uio                     7822  1 cnic
fcoe                   19570  0
libfcoe                47527  2 bnx2fc,fcoe
libfc                  96173  3 bnx2fc,fcoe,libfcoe
scsi_transport_fc      43160  3 bnx2fc,fcoe,libfc
8021q                  16617  0
scsi_tgt                9933  1 scsi_transport_fc
garp                    5703  1 8021q
stp                     1626  1 garp
llc                     4226  2 garp,stp
ipt_REJECT              1899  1
nf_conntrack_ipv4       7374  2
nf_defrag_ipv4          1039  1 nf_conntrack_ipv4
iptable_filter          2173  1
ip_tables               9599  1 iptable_filter
ip6t_REJECT             3731  2
nf_conntrack_ipv6       6588  3
nf_defrag_ipv6         16175  1 nf_conntrack_ipv6

3. Viewing details of individual module.
To view details of a module, we can use modinfo command followed by module name.

### lets see ip_tables module detail
[saket@ngelinux-new ~]$ modinfo ip_tables
filename:       /lib/modules/2.6.32-696.el6.i686/kernel/net/ipv4/netfilter/ip_tables.ko
description:    IPv4 packet filter
author:         Netfilter Core Team < coreteam@netfilter.org >
license:        GPL
srcversion:     D97231A516F24FDE3206537
depends:
vermagic:       2.6.32-696.el6.i686 SMP mod_unload modversions 686
[saket@ngelinux-new ~]$ 

4. Adding a module
To load a module, simply mention the module name with modprobe command.

[root@nglinux ~]#modprobe -v ip_tables
[root@nglinux ~]#

5. Check the loaded module
We can check if the module gets loaded by using lsmod command.

[root@nglinux ~]#lsmod | grep -i ip_tables
ip_tables               9599  1 iptable_filter

6. Removing a module
To remove a module, we can use “-r” switch of modprobe command.

[root@nglinux ~]#modprobe -r ip_tables
FATAL: Module ip_tables is in use.
[root@nglinux ~]#modprobe -rf ip_tables
FATAL: Module ip_tables is in use.

7. Load a module with different name
We can also load a module using some other name, in case its conflicting with some other module.
However sometimes it doesn’t work.

[root@nglinux ~]# modprobe -v nfs -o nfs_ngel_service
install /sbin/modprobe --first-time --ignore-install sunrpc && { /bin/mount -t rpc_pipefs sunrpc /var/lib/nfs/rpc_pipefs > /dev/null 2>&1 || :; }
insmod /lib/modules/2.6.32-696.el6.i686/kernel/net/sunrpc/sunrpc.ko
insmod /lib/modules/2.6.32-696.el6.i686/kernel/fs/nfs_common/nfs_acl.ko
insmod /lib/modules/2.6.32-696.el6.i686/kernel/net/sunrpc/auth_gss/auth_rpcgss.ko
insmod /lib/modules/2.6.32-696.el6.i686/kernel/fs/fscache/fscache.ko
insmod /lib/modules/2.6.32-696.el6.i686/kernel/fs/lockd/lockd.ko
insmod /lib/modules/2.6.32-696.el6.i686/kernel/fs/nfs/nfs.ko
FATAL: Error inserting nfs (/lib/modules/2.6.32-696.el6.i686/kernel/fs/nfs/nfs.ko): Key was rejected by service

Some kernels don’t take new module name, and hence we need to load it by original name.

[root@nglinux ~]# modprobe -v nfs
install /sbin/modprobe --first-time --ignore-install sunrpc && { /bin/mount -t rpc_pipefs sunrpc /var/lib/nfs/rpc_pipefs > /dev/null 2>&1 || :; }
insmod /lib/modules/2.6.32-696.el6.i686/kernel/net/sunrpc/sunrpc.ko
insmod /lib/modules/2.6.32-696.el6.i686/kernel/fs/nfs_common/nfs_acl.ko
insmod /lib/modules/2.6.32-696.el6.i686/kernel/net/sunrpc/auth_gss/auth_rpcgss.ko
insmod /lib/modules/2.6.32-696.el6.i686/kernel/fs/fscache/fscache.ko
insmod /lib/modules/2.6.32-696.el6.i686/kernel/fs/lockd/lockd.ko
insmod /lib/modules/2.6.32-696.el6.i686/kernel/fs/nfs/nfs.ko
[root@nglinux ~]#

 

Loding/Unloading Modules on Solaris

On solaris, we can do the same tasks using below commands.

1. Check all modules of the system

# modinfo | more

2. View specific details of module.

# modinfo | grep -i scsi

3. Loading a module.

# modload -i 27

4. Unloading a module

# modunlod -i 27

Now you can load/unload a module in Linux/Solaris.

Do post your valuable comments or questions below.

Leave a Reply

Your email address will not be published.