How to check if a specific driver is loaded in Linux

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to check if a specific driver is loaded in Linux. Drivers, often implemented as kernel modules, are essential for interacting with hardware. You will explore three methods to achieve this: listing all loaded modules using lsmod, examining the /proc/modules file for detailed status, and verifying specific driver information with modinfo.

By completing these steps, you will gain practical skills in identifying and understanding the status of drivers within your Linux system, which is crucial for troubleshooting hardware issues and system administration.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/BasicFileOperationsGroup(["Basic File Operations"]) linux(("Linux")) -.-> linux/SystemInformationandMonitoringGroup(["System Information and Monitoring"]) linux(("Linux")) -.-> linux/BasicSystemCommandsGroup(["Basic System Commands"]) linux/BasicSystemCommandsGroup -.-> linux/echo("Text Display") linux/BasicSystemCommandsGroup -.-> linux/printf("Text Formatting") linux/BasicFileOperationsGroup -.-> linux/ls("Content Listing") linux/BasicFileOperationsGroup -.-> linux/cat("File Concatenating") linux/SystemInformationandMonitoringGroup -.-> linux/ps("Process Displaying") subgraph Lab Skills linux/echo -.-> lab-558755{{"How to check if a specific driver is loaded in Linux"}} linux/printf -.-> lab-558755{{"How to check if a specific driver is loaded in Linux"}} linux/ls -.-> lab-558755{{"How to check if a specific driver is loaded in Linux"}} linux/cat -.-> lab-558755{{"How to check if a specific driver is loaded in Linux"}} linux/ps -.-> lab-558755{{"How to check if a specific driver is loaded in Linux"}} end

List drivers with lsmod

In this step, you will learn how to list the currently loaded kernel modules, which are often referred to as drivers in the context of hardware. Kernel modules are pieces of code that can be loaded and unloaded into the kernel as needed, extending the kernel's functionality without requiring a system reboot.

The command we will use is lsmod. This command is used to display the status of modules in the Linux kernel.

Open your terminal if it's not already open. You can find the Xfce Terminal icon on the left side of your desktop.

Type the following command and press Enter:

lsmod

You will see output similar to this:

Module                  Size  Used by
...
snd_hda_codec_generic    ...   ...
ledtrig_audio          ...   ...
snd_hda_codec_hdmi     ...   ...
snd_hda_intel          ...   ...
snd_intel_dspcfg       ...   ...
snd_hda_codec          ...   ...   snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hda_intel
snd_hda_core           ...   ...   snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec
snd_hwdep              ...   ...   snd_hda_codec
snd_pcm                ...   ...   snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec,snd_hda_core,snd_hwdep
snd_seq_midi           ...   ...
snd_seq_midi_event     ...   ...   snd_seq_midi
snd_rawmidi            ...   ...   snd_seq_midi,snd_seq_midi_event
snd_seq                ...   ...   snd_seq_midi,snd_seq_midi_event
snd_seq_device         ...   ...   snd_seq_midi,snd_rawmidi,snd_seq
snd_timer              ...   ...   snd_pcm,snd_seq
snd                    ...   ...   snd_hda_codec_generic,ledtrig_audio,snd_hda_codec_hdmi,snd_hda_intel,snd_intel_dspcfg,snd_hda_codec,snd_hda_core,snd_hwdep,snd_pcm,snd_rawmidi,snd_seq,snd_seq_device,snd_timer
soundcore              ...   ...   snd
...

The output of lsmod has three columns:

  • Module: The name of the kernel module.
  • Size: The size of the module in bytes.
  • Used by: A list of other modules that are using this module, and the number of times it is being used.

This command is very useful for seeing which drivers are currently active on your system.

Click Continue to proceed to the next step.

Check driver status with cat /proc/modules

In this step, you will explore another way to view information about loaded kernel modules by examining the /proc/modules file. The /proc filesystem is a virtual filesystem that provides information about processes and other system information.

The /proc/modules file contains similar information to the output of lsmod, but in a slightly different format. We will use the cat command to display the contents of this file.

Type the following command in your terminal and press Enter:

cat /proc/modules

You will see output similar to this:

snd_hda_codec_generic ... ... - Live 0xffffffff...
ledtrig_audio ... ... - Live 0xffffffff...
snd_hda_codec_hdmi ... ... - Live 0xffffffff...
snd_hda_intel ... ... - Live 0xffffffff...
snd_intel_dspcfg ... ... - Live 0xffffffff...
snd_hda_codec ... ... snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hda_intel, Live 0xffffffff...
snd_hda_core ... ... snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec, Live 0xffffffff...
snd_hwdep ... ... snd_hda_codec, Live 0xffffffff...
snd_pcm ... ... snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec,snd_hda_core,snd_hwdep, Live 0xffffffff...
snd_seq_midi ... ... - Live 0xffffffff...
snd_seq_midi_event ... ... snd_seq_midi, Live 0xffffffff...
snd_rawmidi ... ... snd_seq_midi,snd_seq_midi_event, Live 0xffffffff...
snd_seq ... ... snd_seq_midi,snd_seq_midi_event, Live 0xffffffff...
snd_seq_device ... ... snd_seq_midi,snd_rawmidi,snd_seq, Live 0xffffffff...
snd_timer ... ... snd_pcm,snd_seq, Live 0xffffffff...
snd ... ... snd_hda_codec_generic,ledtrig_audio,snd_hda_codec_hdmi,snd_hda_intel,snd_intel_dspcfg,snd_hda_codec,snd_hda_core,snd_hwdep,snd_pcm,snd_rawmidi,snd_seq,snd_seq_device,snd_timer, Live 0xffffffff...
soundcore ... ... snd, Live 0xffffffff...
...

The columns in /proc/modules represent:

  1. Module name
  2. Size of the module
  3. Number of times the module is being used
  4. Whether the module is loaded (Live) or being unloaded (Loading or Unloading)
  5. Memory offset of the module (this is the 0xffffffff... part)
  6. Dependent modules (similar to the "Used by" column in lsmod)

While lsmod is generally the preferred command for viewing loaded modules, understanding that this information is also available in the /proc filesystem is important for deeper system introspection.

Click Continue to move on.

Verify driver details with modinfo

In this step, you will learn how to get detailed information about a specific kernel module using the modinfo command. This command can provide details like the module's filename, author, description, license, and parameters.

Let's get information about the snd_hda_intel module, which is related to audio drivers.

Type the following command in your terminal and press Enter:

modinfo snd_hda_intel

You will see output similar to this:

filename:       /lib/modules/.../kernel/sound/hda/snd-hda-intel.ko
description:    Intel HDA driver
license:        GPL v2
srcversion:     ...
alias:          pci:v00008086d0000...sv*sd*bc04sc03i00*
alias:          pci:v00008086d0000...sv*sd*bc04sc01i00*
alias:          pci:v00008086d0000...sv*sd*bc04sc03i00*
...
depends:        snd-hda-codec,snd-pcm,snd-hda-core,snd-hwdep,snd-timer,snd
retpoline:      Y
intree:         Y
name:           snd_hda_intel
vermagic:       ... SMP mod_unload
sig_id:         PKCS#7
signer:         Build time autogenerated kernel key
sig_key:        ...
sig_hashalgo:   sha512
signature:      ...
parm:           bdl_pos_adj:Adjust the BDL position (int)
parm:           probe_mask:Bitmask of codec probe options.
                bit 0: force codec probe
                bit 1: allow probing codecs with basic capabilities
                bit 2: allow probing codecs with no capabilities
                (int)
parm:           enable_msi:Enable MSI (int)
parm:           enable_msix:Enable MSI-X (int)
parm:           model:Use the specified codec model.
                See Documentation/sound/kernel-modules-aliases.txt for details. (charp)
parm:           patch:Load the specified patch file. (charp)
parm:           power_save:Automatic power-saving timeout (in ms, 0 to disable). (int)
parm:           power_save_controller:Controller power-saving timeout (in ms, 0 to disable). (int)
parm:           pm_blacklist:Force non-power-save mode (D0) (bool)
parm:           position_fix:DMA pointer position fix (0, 1, 2) (int)
parm:           probe_only_force:Only probe codecs with force option (bool)
parm:           single_cmd:Use single command to communicate with codecs (bool)
parm:           snoop:Enable/disable snoop mode (bool)
parm:           jackpoll_ms:Polling interval for jack events (in ms, 0 to disable). (int)

This output provides a wealth of information about the snd_hda_intel module, including its location on the filesystem (filename), a brief description, the license under which it is distributed, and various parameters that can be used to configure its behavior.

Understanding how to use modinfo is crucial for troubleshooting driver issues or learning more about the specific capabilities and options of a kernel module.

Click Continue to complete this lab.

Summary

In this lab, you learned how to check if a specific driver is loaded in Linux. You started by using the lsmod command to list all currently loaded kernel modules, which are often referred to as drivers. This command provides information about the module name, size, and which other modules are using it.

You also learned that you can check the status of loaded drivers by examining the contents of the /proc/modules file using the cat command. Finally, you discovered how to use the modinfo command to retrieve detailed information about a specific driver, such as its filename, author, description, and parameters. These steps provide a comprehensive approach to verifying the presence and details of drivers loaded in your Linux system.