In this article, i will list out some of the tools/utilities used to interact with Linux kernel modules.

uname

uname displays information about currently running Kernel

You can use below options with uname command


  -a, --all                print all information, in the following order,
                             except omit -p and -i if unknown:
  -s, --kernel-name        print the kernel name
  -n, --nodename           print the network node hostname
  -r, --kernel-release     print the kernel release
  -v, --kernel-version     print the kernel version
  -m, --machine            print the machine hardware name
  -p, --processor          print the processor type or "unknown"
  -i, --hardware-platform  print the hardware platform or "unknown"
  -o, --operating-system   print the operating system
      --help     display this help and exit
      --version  output version information and exit
[cloud_user@learncloud3c ~]$ uname -a
Linux learncloud3c 3.10.0-957.12.1.el7.x86_64 #1 SMP Mon Apr 29 14:59:59 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
uname -a

lsmod

List out all currently loaded kernel modules. Sorted by Module name , Size in memory and used by modules(dependencies)

[cloud_user@learncloud3c ~]$ lsmod
Module                  Size  Used by
sb_edac                31940  0 
intel_rapl             19542  0 
iosf_mbi               15582  1 intel_rapl
crc32_pclmul           13133  0 
ghash_clmulni_intel    13273  0 
ppdev                  17671  0 
aesni_intel           189414  0 
lrw                    13286  1 aesni_intel
gf128mul               15139  1 lrw
glue_helper            13990  1 aesni_intel
ablk_helper            13597  1 aesni_intel
cryptd                 21190  3 ghash_clmulni_intel,aesni_intel,ablk_helper
parport_pc             28205  0 
parport                46395  2 ppdev,parport_pc
pcspkr                 12718  0 
i2c_piix4              22401  0 
nfsd                  351388  13 
auth_rpcgss            59415  1 nfsd
nfs_acl                12837  1 nfsd
lockd                  93952  1 nfsd
grace                  13515  2 nfsd,lockd
ip_tables              27126  0 
xfs                   997127  1 
libcrc32c              12644  1 xfs
xen_netfront           27082  0 
xen_blkfront           26922  2 
crct10dif_pclmul       14307  0 
crct10dif_common       12595  1 crct10dif_pclmul
crc32c_intel           22094  1 
serio_raw              13434  0 
ata_generic            12923  0 
pata_acpi              13053  0 
cirrus                 24377  1 
drm_kms_helper        179394  1 cirrus
syscopyarea            12529  1 drm_kms_helper
sysfillrect            12701  1 drm_kms_helper
sysimgblt              12640  1 drm_kms_helper
fb_sys_fops            12703  1 drm_kms_helper
ttm                   114635  1 cirrus
floppy                 69432  0 
drm                   429744  4 ttm,drm_kms_helper,cirrus
ata_piix               35052  0 
libata                243133  3 pata_acpi,ata_generic,ata_piix
drm_panel_orientation_quirks    12957  1 drm
scsi_transport_iscsi    99909  0 
sunrpc                353407  19 nfsd,auth_rpcgss,lockd,nfs_acl
dm_mirror              22289  0 
dm_region_hash         20813  1 dm_mirror
dm_log                 18411  2 dm_region_hash,dm_mirror
dm_mod                124407  2 dm_log,dm_mirror
[cloud_user@learncloud3c ~]$ 

modinfo

Displays information about a specified kernel Module. Below you can find the usage of modinfo command

Usage:
        modinfo [options] filename [args]
Options:
        -a, --author                Print only 'author'
        -d, --description           Print only 'description'
        -l, --license               Print only 'license'
        -p, --parameters            Print only 'parm'
        -n, --filename              Print only 'filename'
        -0, --null                  Use \0 instead of \n
        -F, --field=FIELD           Print only provided FIELD
        -k, --set-version=VERSION   Use VERSION instead of `uname -r`
        -b, --basedir=DIR           Use DIR as filesystem root for /lib/modules
        -V, --version               Show version
        -h, --help                  Show this help

Let's check information about xfs module

[cloud_user@learncloud3c ~]$ modinfo xfs
filename:       /lib/modules/3.10.0-957.12.1.el7.x86_64/kernel/fs/xfs/xfs.ko.xz
license:        GPL
description:    SGI XFS with ACLs, security attributes, no debug enabled
author:         Silicon Graphics, Inc.
alias:          fs-xfs
retpoline:      Y
rhelversion:    7.6
srcversion:     799C7EBA4C499822FD1E465
depends:        libcrc32c
intree:         Y
vermagic:       3.10.0-957.12.1.el7.x86_64 SMP mod_unload modversions 
signer:         CentOS Linux kernel signing key
sig_key:        2C:7C:17:70:5C:86:D4:20:80:50:D3:F5:54:56:9A:7B:D3:BF:D1:BF
sig_hashalgo:   sha256

modprobe

Command used to dynamically load and unload kernel modules at runtime. Listed below the usage of this module

[cloud_user@learncloud3c ~]$ modprobe -h
Usage:
        modprobe [options] [-i] [-b] modulename
        modprobe [options] -a [-i] [-b] modulename [modulename...]
        modprobe [options] -r [-i] modulename
        modprobe [options] -r -a [-i] modulename [modulename...]
        modprobe [options] -c
        modprobe [options] --dump-modversions filename
Management Options:
        -a, --all                   Consider every non-argument to
                                    be a module name to be inserted
                                    or removed (-r)
        -r, --remove                Remove modules instead of inserting
            --remove-dependencies   Also remove modules depending on it
        -R, --resolve-alias         Only lookup and print alias and exit
            --first-time            Fail if module already inserted or removed
        -i, --ignore-install        Ignore install commands
        -i, --ignore-remove         Ignore remove commands
        -b, --use-blacklist         Apply blacklist to resolved alias.
        -f, --force                 Force module insertion or removal.
                                    implies --force-modversions and
                                    --force-vermagic
            --force-modversion      Ignore module's version
            --force-vermagic        Ignore module's version magic

Query Options:
        -D, --show-depends          Only print module dependencies and exit
        -c, --showconfig            Print out known configuration and exit
        -c, --show-config           Same as --showconfig
            --show-modversions      Dump module symbol version and exit
            --dump-modversions      Same as --show-modversions

General Options:
        -n, --dry-run               Do not execute operations, just print out
        -n, --show                  Same as --dry-run
        -C, --config=FILE           Use FILE instead of default search paths
        -d, --dirname=DIR           Use DIR as filesystem root for /lib/modules
        -S, --set-version=VERSION   Use VERSION instead of `uname -r`
        -s, --syslog                print to syslog, not stderr
        -q, --quiet                 disable messages
        -v, --verbose               enables more messages
        -V, --version               show version
        -h, --help                  show this help

I will show how to remove one module using modprobe

[cloud_user@learncloud3c ~]$ sudo modprobe -r floppy
[sudo] password for cloud_user: 

You can re add module using modprobe <modulename>

cloud_user@learncloud3c ~]$ sudo modprobe floppy

Conclusion

I hope you got some information about how to work with Kernel utilities.