Kernel modules, devices and udev
Objective 101.1 names modprobe, lsmod, /dev, /sys and udev as things you should be able to talk about. This guide lists what the running kernel has loaded, reads a module's own description off disk, loads and removes one that cannot affect anything, and then looks at where device nodes and predictable interface names actually come from.
101: System Architecture Guide 33 of 33 Beginner
- OSUbuntu 26.04 LTS
- Kernel7.0.0-30-generic
- systemd259
- TimeAbout 22 min
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| LPIC1-A01 | 192.168.0.76 | Ubuntu 26.04 LTS | Debian-family host - dpkg and apt, which objective 102.4 names | 2 Core | 4 GB | 50 GB |
This guide includes
Use this when hardware is present and not working, or when you need to know whether support for something is compiled in, loadable, or blacklisted. This matters because a device that does not appear is usually a module question, and because /dev and /sys are the two places the answer is written down.
- reading
lsmodincluding theUsed bycolumn - finding a module's file on disk and reading its description with
modinfo - previewing what
modprobewould do before doing it - loading and removing a module, and confirming both with a count
- reading a major and minor device number out of
ls -l - knowing where a module is blacklisted and where one is requested at boot
Before you start
- targets-runlevels-and-what-the-kernel-found
-
What the kernel has loaded right now
A count, a table, and the directory the files came from.
bash Example session lsmod | wc -l; echo "modules loaded"; lsmod | head -452modules loadedModule Size Used byudp_diag 12288 0tcp_diag 20480 0inet_diag 24576 2 tcp_diag,udp_diaguname -r; ls -d /lib/modules/$(uname -r); ls /lib/modules/$(uname -r)/kernel/ | head -5; echo "--- modules are files on disk, grouped like the kernel source"7.0.0-30-generic/lib/modules/7.0.0-30-genericarchblockcryptodriversfs--- modules are files on disk, grouped like the kernel sourceExpected result52 modules, with
inet_diagshowing2 tcp_diag,udp_diagin its Used by column - kernel7.0.0-30-generic, and its module tree grouped intoarch,block,crypto,drivers,fs.Success conditionYou can list a running kernel's modules and find them on disk.
-
What one module says about itself
The file, its description, and a dry run.
bash Example session modinfo dummy | grep -E "^(filename|description|license|depends|parm)" | head -6filename: /lib/modules/7.0.0-30-generic/kernel/drivers/net/dummy.ko.zstdescription: Dummy netdevice driver which discards all packets sent to itlicense: GPLdepends:parm: numdummies:Number of dummy pseudo devices (int)modprobe -n -v dummy; echo "--- -n is a dry run: this is what WOULD be loaded, dependencies first"insmod /lib/modules/7.0.0-30-generic/kernel/drivers/net/dummy.ko.zst numdummies=0--- -n is a dry run: this is what WOULD be loaded, dependencies firstExpected result
filename: /lib/modules/7.0.0-30-generic/kernel/drivers/net/dummy.ko.zst, described asDummy netdevice driver which discards all packets sent to it,depends:empty, and aparm:fornumdummies. The dry run prints theinsmodit would perform.Success conditionYou can find out what a module does before loading it.
-
Loading one that cannot affect anything
A module in, an interface out, and what the kernel then exposes about it.
bash Example session lsmod | grep -c "^dummy "; echo "dummy modules loaded before"; sudo modprobe dummy numdummies=1 && lsmod | grep "^dummy"; ip -br link show type dummy 2>/dev/null | head -20dummy modules loaded beforedummy 16384 0dummy0 DOWN 6e:75:0d:1e:13:9e <BROADCAST,NOARP>ls /sys/module/dummy/; echo "--- refcnt:"; cat /sys/module/dummy/refcnt; ls /sys/module/dummy/parameters/ 2>/dev/null || echo "(this module exposes no parameters at runtime)"coresizeholdersinitsizeinitstatenotesrefcntsectionssrcversiontaintuevent--- refcnt:0(this module exposes no parameters at runtime)Expected result0 before - then
dummyloaded at 16384 bytes and a newdummy0 DOWNinterface with<BROADCAST,NOARP>- and/sys/module/dummy/holdingrefcnt,coresize,initstateand others, with refcnt 0 and noparametersdirectory at all.Success conditionYou can load a module and see the device it creates.
-
The device tree that is not on a disk
Two numbers instead of a size, and one file per attribute.
bash Example session ls -l /dev/null /dev/zero | awk '{print $1, $5, $6, $NF}'; echo "--- the two numbers where a size would be are the major and minor device numbers"crw-rw-rw- 1, 3 /dev/nullcrw-rw-rw- 1, 5 /dev/zero--- the two numbers where a size would be are the major and minor device numbersls /sys/class/net/; echo "---"; cat /sys/class/net/eth0/address; cat /sys/class/net/eth0/mtu; echo "--- one file per attribute, which is what sysfs is"dummy0eth0lo---00:15:5d:01:11:721500--- one file per attribute, which is what sysfs isudevadm info -q property -p /sys/class/net/eth0 2>/dev/null | grep -E "ID_NET_NAME|DEVPATH|INTERFACE" | head -4DEVPATH=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A03:00/device:07/VMBUS:01/1c3c68f3-d116-4fbe-9f64-e4dcdca05832/net/eth0INTERFACE=eth0ID_NET_NAME_MAC=enx00155d011172ID_NET_NAME=eth0Expected result
crw-rw-rw-with 1, 3 for/dev/nulland 1, 5 for/dev/zero-/sys/class/net/listingdummy0,eth0,lowith the MAC and MTU each in its own file - andudevadmreportingID_NET_NAME=eth0alongsideID_NET_NAME_MAC=enx00155d011172.Success conditionYou can read a device node's identity and find its attributes in sysfs.
-
What stops a module loading
Two directories - one that prevents, one that requests.
bash Example session ls /etc/modprobe.d/ | head -4; grep -rhE "^(blacklist|install|options)" /etc/modprobe.d/ 2>/dev/null | head -4; echo "--- blacklist and options both live here"amd64-microcode-blacklist.confblacklist-ath_pci.confblacklist-firewire.confblacklist-framebuffer.confblacklist evbugblacklist usbmouseblacklist usbkbdblacklist eepro100--- blacklist and options both live herels /etc/modules-load.d/ 2>/dev/null; cat /etc/modules 2>/dev/null | grep -vE "^#|^$" | head -3; echo "--- and this is where a module is asked for at boot"modules.conf--- and this is where a module is asked for at bootExpected result
blacklist-*.conffiles under/etc/modprobe.d/with entries such asblacklist evbug,blacklist usbmouse,blacklist eepro100- andmodules.confunder/etc/modules-load.d/.Success conditionYou can find out whether a module is being prevented from loading.
-
Putting the machine back
The module out, and the counts on both sides of it.
bash Example session sudo ip link del dummy0 2>/dev/null; sudo modprobe -r dummy && lsmod | grep -c "^dummy "; echo "dummy modules loaded after"; ip -br link show type dummy 2>&1 | tail -10dummy modules loaded afterlsmod | wc -l; echo "modules loaded"; ip -br link show | head -2; ls /sys/module/dummy 2>&1 | tail -152modules loadedlo UNKNOWN 00:00:00:00:00:00 <LOOPBACK,UP,LOWER_UP>eth0 UP 00:15:5d:01:11:72 <BROADCAST,MULTICAST,UP,LOWER_UP>ls: cannot access '/sys/module/dummy': No such file or directoryExpected result0 dummy modules after removal, back to 52 modules,
loandeth0alone witheth0stillUP, and/sys/module/dummyNo such file or directory.Success conditionThe kernel is carrying exactly what it was before.
Troubleshooting
A device is present and no driver seems to be handling it.
Why: The module is not loaded, not installed, or blacklisted.
Fix:
lspci -kshows the kernel driver in use per device. If none,modinfo <module>to check it exists,modprobe <module>to try it, andgrep -r <module> /etc/modprobe.d/to see whether something is blocking it.modprobe -rreports the module is in use.Why: Its reference count is above zero - another module or an open device depends on it.
Fix:
lsmod | grep <module>and read theUsed bycolumn, which names the dependants. Remove those first, or stop whatever has the device open.A blacklisted module loads anyway.
Why:
blacklistonly prevents automatic loading by alias. A dependency or an explicitmodprobestill loads it, and early-boot modules come from the initramfs.Fix:Use
install <module> /bin/falsein/etc/modprobe.d/, then rebuild the initramfs:sudo update-initramfs -uorsudo dracut -f.A module parameter set with
modprobeis gone after a reboot.Why: It applied to that load only.
Fix:Put
options <module> key=valuein a file under/etc/modprobe.d/, and rebuild the initramfs if the module loads during early boot.A network interface changed name after a hardware or kernel change.
Why: Predictable interface names are derived by udev from the PCI slot, firmware index or MAC, and the inputs changed.
Fix:
udevadm info -q property -p /sys/class/net/<name>lists every candidate name. Pin one with a rule in/etc/systemd/network/, or usenet.ifnames=0on the kernel command line to keep the old scheme.A module file cannot be found under /lib/modules.
Why: Modules are compressed as
.ko.zstor.ko.xz, and are per kernel version.Fix:
modinfo -F filename <module>resolves the real path regardless of compression. Check you are looking under/lib/modules/$(uname -r)/and not an older kernel's tree.