Table of Contents
In this article, I will take you through 10 Useful Linux/Unix modprobe command examples. modprobe is an open source command line tool used for adding and removing modules in Linux/Unix. Being a Linux professional you must be aware of the tools that can be used to view, install and remove kernel and other system modules. Usually modprobe command is used in combination with lsmod and modinfo commands.
At the System Level, generally you don't have to load the modules manually, it will loaded on demand by udev (device manager). But there are times when you need to load or remove the modules manually. In those cases, modprobe command can become very handy. We will see all the important examples of modprobe command in Linux/Unix as we go through below.
Syntax
modprobe [-v] [-V] [-C config-file] [-n] [-i] [-q] [-b] [modulename] [module parameters...]
modprobe [-r] [-v] [-n] [-i] [modulename...]
modprobe [-c]
modprobe [--dump-modversions] [filename]
modprobe command examples in Linux/Unix
Also Read: 20 Useful Linux History Command Examples | Bash Command History
Example 1: How to check modprobe command version
If you want to check the modprobe command version, then you need to use modprobe --version
command as shown below. As you can see from below output, current version is 20
.
[root@localhost ~]# modprobe --version kmod version 20
--version : Show version of program and exit.
Example 2: How to dump all the module Configuration using modprobe command in Linux
If you want to dump all the effective configuration from the config directory then you need to use modprobe -c
command as shown below. Please note that output of this command could be little longer so it is always advised to view the output page by page using more
command as specified below.
[root@localhost ~]# modprobe -c | more blacklist dccp blacklist dccp_diag blacklist dccp_ipv4 install snd_pcm /sbin/modprobe --ignore-install snd-pcm && /sbin/modprobe snd-seq install nf_conntrack /usr/sbin/modprobe --ignore-install nf_conntrack $CMDLINE_OPTS && /usr/sbin/sysctl --quiet --pattern 'net[.]netfilter[.]nf_conntrack.*' --system install mlx4_core /sbin/modprobe --ignore-install mlx4_core $CMDLINE_OPTS && (if [ -f /usr/libexec/mlx4-setup.sh -a -f /etc/rdma/mlx4.conf ]; then /usr/libexec/mlx4-set up.sh < /etc/rdma/mlx4.conf; fi; /sbin/modprobe mlx4_en; if /sbin/modinfo mlx4_ib > /dev/null 2>&1; then /sbin/modprobe mlx4_ib; fi) install ib_qib modprobe -i ib_qib $CMDLINE_OPTS && /usr/libexec/truescale-serdes.cmds start options rd lvm.lv=centos/root options rd lvm.lv=centos/swap
-c : Dump out the effective configuration from the config directory and exit.
Example 3: How to remove a module using modprobe command in Linux
First you need to list out and check the module which you want to remove using modprobe
command. In this example, we are grepping the module cxgb3i
from the output of lsmod
command to check the availability of this module.
[root@localhost ~]# lsmod | grep -i cxgb3i cxgb3i 32791 0 cxgb3 156307 2 iw_cxgb3,cxgb3i libcxgbi 58769 1 cxgb3i libcxgb 15319 2 cxgb3i,libcxgbi libiscsi_tcp 25146 2 cxgb3i,libcxgbi libiscsi 57233 4 libiscsi_tcp,cxgb3i,ib_iser,libcxgbi
Now remove the cxgb3i
module from System using modprobe -v -r cxgb3i
command as shown below.
[root@localhost ~]# modprobe -v -r cxgb3i rmmod cxgb3i rmmod libcxgbi rmmod libiscsi_tcp rmmod libcxgb
-v : Print messages about what the program is doing. More info on modprobe Man Page.
-r : This option causes modprobe to remove rather than insert a module.
If you try to list the modules again and verify then you can see that cxgb3i
module is not available anymore and hence removed.
[root@localhost ~]# lsmod | grep -i cxgb3i
Example 4: How to Insert a module using modprobe command
If you want to install a module then you need to use -i
option with modprobe command in Linux. In this example, we are trying to install cxgb3i
module in verbose mode using modprobe -v -i cxgb3i
command.
[root@localhost ~]# modprobe -v -i cxgb3i insmod /lib/modules/3.10.0-1127.10.1.el7.x86_64/kernel/drivers/scsi/libiscsi_tcp.ko.xz insmod /lib/modules/3.10.0-1127.10.1.el7.x86_64/kernel/drivers/net/ethernet/chelsio/libcxgb/libcxgb.ko.xz insmod /lib/modules/3.10.0-1127.10.1.el7.x86_64/kernel/drivers/scsi/cxgbi/libcxgbi.ko.xz insmod /lib/modules/3.10.0-1127.10.1.el7.x86_64/kernel/drivers/scsi/cxgbi/cxgb3i/cxgb3i.ko.xz
-i : Install module in the System.
Example 5: How to search all the modules in Linux
If you want to find the installation path of all your modules installed in the system then you need to use below find
command. In this example, we are trying to search all the files which contains .ko
from /lib/modules/$(uname -r)
file path.
[root@localhost ~]# find /lib/modules/$(uname -r) -type f -name *.ko*
Example 6: How to Find all dependable modules using modinfo command in Linux
If you want to find all the dependent modules of a specific module then you need to use -F
option with modinfo command as shown below. In this example, we are trying to find all the dependent modules of cxgb3i
modules using modinfo -F depends cxgb3i
command.
[root@localhost ~]# modinfo -F depends cxgb3i libiscsi,libcxgbi,libiscsi_tcp,cxgb3,libcxgb
-F : Only print this field value, one per line.. More can be checked on modinfo Man Page.
Example 7: How to List all Blacklisted modules using modprobe command in Linux
If you want to view all Blacklisted modules then you need to grep blacklist from modprobe --showconfig
output using modprobe --showconfig | grep blacklist
command as shown below.
[root@localhost ~]# modprobe --showconfig | grep blacklist blacklist dccp blacklist dccp_diag blacklist dccp_ipv4 blacklist dccp_ipv6 blacklist i8xx_tco blacklist aty128fb blacklist atyfb blacklist radeonfb blacklist i810fb blacklist cirrusfb blacklist intelfb blacklist kyrofb blacklist i2c_matroxfb blacklist hgafb blacklist nvidiafb blacklist rivafb blacklist savagefb blacklist sstfb blacklist neofb blacklist tridentfb blacklist tdfxfb blacklist virgefb blacklist vga16fb blacklist viafb blacklist hisax blacklist hisax_fcpcipnp
--showconfig
: Dump out the effective configuration from the config directory and exit.
Example 8: How to Check Complete Information about a Module using modinfo command
If you want to check the complete information of a module then you need to use modinfo
command as shown below. In this example we are trying to check all the information about cxgb3i
module using modinfo cxgb3i
command as specified below.
[root@localhost ~]# modinfo cxgb3i filename: /lib/modules/3.10.0-1127.10.1.el7.x86_64/kernel/drivers/scsi/cxgbi/cxgb3i/cxgb3i.ko.xz license: GPL version: 2.0.1-ko description: Chelsio T3 iSCSI Driver author: Chelsio Communications, Inc. retpoline: Y rhelversion: 7.8 srcversion: DC3416AB7C42C9138EBF7BA depends: libiscsi,libcxgbi,libiscsi_tcp,cxgb3,libcxgb intree: Y vermagic: 3.10.0-1127.10.1.el7.x86_64 SMP mod_unload modversions signer: CentOS Linux kernel signing key sig_key: 74:65:10:C9:28:48:A8:D6:54:BE:F1:09:D5:44:6F:4B:FE:EC:B7:CA sig_hashalgo: sha256 parm: dbg_level:debug flag (default=0) (uint) parm: cxgb3i_rcv_win:TCP receive window in bytes (default=256KB) (int) parm: cxgb3i_snd_win:TCP send window in bytes (default=128KB) (int) parm: cxgb3i_rx_credit_thres:int parm: rx_credit_thres:RX credits return threshold in bytes (default=10KB) parm: cxgb3i_max_connect:Max. # of connections (default=8092) (uint) parm: cxgb3i_sport_base:starting port number (default=20000) (uint)
Example 9: How to blacklist a Module in Linux from /etc/modprobe.d/local-blacklist.conf file
You need to create a file under /etc/modprobe.d
and add the module as shown below. In this example, we are trying to blacklist cxgb3i
module by providing an entry in local-blacklist.conf
file.
[root@localhost ~]# cat /etc/modprobe.d/local-blacklist.conf blacklist cxgb3i
After performing the above changes you need to restart your system using init 6
or reboot
command to reflect the changes in your system.
[root@localhost ~]# init 6
After restart check again if the module is showing in blacklist by grepping the cxgb3i
module from modprobe
command output as shown below.
[root@localhost ~]# modprobe --showconfig | grep blacklist | grep -i cxgb3i blacklist cxgb3i
Example 10: How to check all the other options available with modprobe command in Linux
If you want to check all the other options available with modprobe command in Linux then you need to use --help
as shown below.
[root@localhost ~]# modprobe --help 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
Popular Recommendations:-
Understanding Kafka Console Producer and Consumer in 10 Easy Steps
Popular firewalld examples to open a port on RedHat/CentOS 7
8 Most Popular mkdir command in Linux with Examples
How to List all Loadable Kernel Modules
Using 3 Steps – How to create an IAM User and attach policy in AWS
10 Best s3cmd Command Examples for AWS Cloud Administrators
Popular Apache Kafka Architecture Explained Using 4 Basic Components
5 Easy Steps to recover LVM2 Partition , PV , VG , LVM metadata in Linux
For Beginners: Create an EC2 Instance in AWS with 7 Easy Steps