Skip to content

Linux: Device Management

Kernel Module Management

Kernel modules allows the extension of a linux system. Linux allows adding and removing kernel modules.

insmod is used to manually install module into the kernel.

modprobe is used to install module with their dependencies.

rmmod is used to remove a module.

insmod

insmod requires the full path of the .ko file. It does not resolve dependencies so user is required to make sure that all the dependencies are already present in the system before using insnod to install a module. Ex: insmod /lib/modules/$(uname -r)/extra/custom_module.ko used to install custom_module.ko into the kernel located in /lib/modules/$(uname -r)/extra/ directory. $(uname -r) is used to retrieve the kernel current version. insmod is recommended for specific situation since it does not resolve dependencies.

modprobe

modprobe manages kernel modules and automatically handle dependency resolution. It requires only the module name unlike insmod which requires the full path of the module.

Use modprobe <module_name> to load a module in the kernel.

modprobe support multiple options.

  • -a allows loading multiple modules at once
  • -r removes a module and its dependencies
  • -f to force-load a module
  • -n to perform a dry-run to see eventual events if the module is to be loaded
  • -v to enable verbose mode

rmmod

Allows the removal of kernel modules. It does not check for dependencies. So, if a module is a dependency, rmmod will still remove it without warning. It must be used only if necessary. modprobe -r is convenient for safely removing modules.

lsmod

lsmod is used to view loaded modules.

modinfo

modinfo is used to view module information. Ex: modinfo mymod.ko

depmod

depmod scan all available kernel module and generate a dependency map file that is used by modprobe to load them correctly. It analyzes the directory /lib/modules/$(uname -r)/ to build the list of module dependencies. Running depmod in the terminal updates the depmod.dep file, which list all the dependencies.

To find which module depends on mymod for exemple use the command cat /lib/modules/$(uname -r)/depmod.dep | grep mymod

Harware Information

dmidecode provides information about the hardware from the DMI table (Desktop Management Interface table). It provides details about the BIOS, motherboard, CPU, Memory. dmidecode -t [TYPE] for specific information. Option TYPE could be system, processor, bios, memory, baseboard, chassis, cache, slot.

lscpu provides details about the CPU. Use lscpu -e for details of each core of the cpu

lsmem provides details about the system memory allocation

lspci list PCI-connected devices. PCI=Peripheral Component Interconnect.

lsusb list USB connected devices

lshw List hardware component information. Use lshw -short to get a summary of the report. lshw provide information included in lspci and lsusb.

System Monitoring and Diagnosis Commands

dmesg displays system messages, hardware logs, and boot messages. Use dmesg -TH --level-err --follow to follow system level error messages. It is useful for troubleshooting boot issues and hardware crashes.

lm_sensors is a package used for hadrware monitoring such as CPU temperature, fan speed, voltage level, and more. It provides commands for monitoring sensors via sensors, and watch sensors commands.

ipmitool is a tool for IPMI. IPMI=Intelligent Platform Management Interface.

initrd Management

mkinitrd is a tool used in RPM distro to manually create the initial RAM disk. Use mkinitrd [options] <initrd image> <kernel version>. Ex: mkinitrd -f /boot/initrd-$(uname -r).img $(uname -r) to force the creation of a new initrd

dracut is modern and more flexible alternative to mkinitrd. It automates the creation of initramfs images and provides better dependency management. Ex: dracut -f /boot/initramfs-$(uname -r).img $(uname -r) to force the creation of a new initramfs.