Skip to main content

Managing Kernel and Modules

1. Viewing Loaded Modules

Command Description Example Output
lsmod Lists all currently loaded kernel modules
Module                  Size  Used by
snd_hda_intel          57344  1
snd_hda_codec         139264  1
snd_hda_core           81920  2
cat /proc/modules Displays loaded modules with additional details like size and reference count
snd_hda_intel 57344 1 - Live 0x0000000000000000
snd_hda_codec 139264 1 - Live 0x0000000000000000
snd_hda_core 81920 2 - Live 0x0000000000000000
modinfo <module_name> Shows metadata and details about a specific module
filename:       /lib/modules/5.15.0-1027-oem/kernel/sound/pci/hda/snd-hda-intel.ko
alias:          pci:v00008086d00002668sv*sd*bc*sc*i*
version:        1.0.0
license:        GPL

Example: Check if a specific module is loaded

lsmod | grep snd_hda_intel

2. Loading Modules Manually

Command Description Notes
modprobe Load or unload kernel modules dynamically Automatically handles dependencies
insmod Insert a module into the kernel Does not handle dependencies; requires full path
rmmod Remove a module from the kernel Can specify module name or path

Example: Load a module with modprobe

sudo modprobe e1000

Example: Load a module with insmod

sudo insmod /lib/modules/$(uname -r)/kernel/drivers/net/e1000/e1000.ko

Example: Unload a module with rmmod

sudo rmmod e1000
Note: Use modprobe when possible as it handles dependencies and is safer than insmod.

3. Removing Modules

Command Description Notes
rmmod Removes a module from the kernel Module must be unloaded first if in use
modprobe -r Removes a module and its dependencies Automatically handles dependency removal

Example: Removing a Kernel Module

# Remove a specific module
sudo rmmod e1000

# Remove module and dependencies
sudo modprobe -r e1000
Note: Ensure the module is not in use before removal to avoid system instability.
Warning: Removing critical kernel modules like network drivers can cause system crashes or loss of connectivity.

4. Viewing Module Information

Command Description Example
lsmod Lists currently loaded kernel modules lsmod
modinfo Displays detailed information about a specific module modinfo e1000
cat /proc/modules Shows all loaded modules with their reference counts and size cat /proc/modules

Example: Check module details

modinfo snd_hda_intel
Note: The modinfo command can show version, author, description, and parameters of a module.

5. Configuring Module Parameters

Parameter Description Values Default
module.param Module-specific parameter value None

Example: Setting Module Parameter

# Load module with parameter<br>modprobe module_name.param=value

Example: Persistent Parameter Configuration

# Add to /etc/modprobe.d/module.conf<br>options module_name.param=value

6. Blacklisting Modules

Module Name Blacklist Location Description
snd_hda_intel /etc/modprobe.d/blacklist.conf Prevents loading of Intel HDA audio driver
nouveau /etc/modprobe.d/blacklist.conf Disables open-source NVIDIA GPU driver

Example: Blacklisting a Module

# Add to /etc/modprobe.d/blacklist.conf
blacklist snd_hda_intel
Note: Changes take effect after reboot or module reload.

7. Updating Kernel

Method Description Notes
apt update & apt upgrade Update kernel packages via APT (Debian/Ubuntu-based systems) May require reboot after update
dnf update kernel Update kernel using DNF (Fedora/RHEL-based systems) System will prompt to reboot if new kernel is installed
yum update kernel Update kernel using YUM (older RHEL/CentOS systems) Reboot required to use new kernel
pacman -Syu Update kernel on Arch-based systems May update all packages; reboot needed to switch kernels

Example: Update kernel on Ubuntu

$ sudo apt update
$ sudo apt upgrade
Note: Always ensure you have a backup or recovery method before updating the kernel.
Warning: Kernel updates can cause system instability or hardware incompatibility if not properly tested.

Update Process Summary

  • Check current kernel version: uname -r
  • Update package lists: apt update
  • Upgrade kernel packages: apt upgrade
  • Reboot system to use new kernel

8. Viewing Available Kernels

Command Description Notes
uname -r Displays the running kernel version Shows current kernel in use
ls /boot List files in boot directory Includes kernel images and initrd files
ls /lib/modules Lists installed kernel modules Shows available kernel versions
cat /proc/version Displays kernel version info Includes compiler and build details
dpkg -l | grep linux-image List installed Linux kernel images (Debian/Ubuntu) Shows all installed kernels
rpm -qa | grep kernel List installed kernels (RHEL/CentOS/Fedora) Lists all kernel packages

Example: Check running kernel version

$ uname -r
5.15.0-1028-oem

Example: List installed kernels (Debian/Ubuntu)

$ dpkg -l | grep linux-image
ii  linux-image-5.15.0-1028-oem  5.15.0-1028.32  amd64  Linux kernel image for version 5.15.0-1028-oem
ii  linux-image-5.15.0-1030-oem  5.15.0-1030.34  amd64  Linux kernel image for version 5.15.0-1030-oem

9. Removing Old Kernels

Command Description Notes
dpkg --list | grep linux-image List all installed Linux kernel images Use to identify which kernels are currently installed
apt autoremove Remove old kernel packages that are no longer needed Automatically removes unused kernels and dependencies
apt purge linux-image-<version> Manually remove a specific kernel version Replace <version> with the desired kernel version to remove

Example: Remove Old Kernels

# List installed kernels
dpkg --list | grep linux-image

# Remove old kernels (keeping current and previous)
sudo apt autoremove
Note: Always ensure that at least one kernel is retained to avoid system boot issues.
Warning: Removing kernels can lead to system instability if the current kernel is removed. Always verify that the running kernel is not being removed.

10. Managing initramfs

Command Description Notes
update-initramfs Creates or updates the initramfs image Used to regenerate initramfs after kernel/module changes
mkinitramfs Creates a new initramfs image from scratch More manual control over the process
dracut Tool for generating initramfs images Alternative to update-initramfs, used in some distributions

Example: Update initramfs after kernel update

sudo update-initramfs -u

Example: Create a new initramfs image

sudo mkinitramfs -o /boot/initrd.img-$(uname -r) $(uname -r)
Note: The initramfs is a temporary filesystem loaded into memory during boot. It contains necessary drivers and tools to mount the root filesystem.

Was this article helpful?