Finding Linux Drivers At Runtime-Free Linux Device Drivers Course

Finding Linux Drivers At Runtime

A free Linux device drivers course lecture on inspecting loaded drivers through /proc and /sys on a running system

Free Linux Device Drivers Course
Free Embedded Linux Course
Hands-on Demo Included

You now know how character, block, and network drivers each get identified — major/minor pairs for the first two, names for the third. This lecture, part of our free Linux kernel development course, closes the loop by showing where the kernel exposes all of that information live, once your system is up and running, so you can debug driver issues without touching a single line of source code.

What You Will Learn

Lecture Roadmap
1. Reading /proc/devices for registered character and block majors 2. Reading /proc/partitions for live block/partition numbering 3. Walking /sys/class to see drivers organized by subsystem 4. Using /sys/dev/char and /sys/dev/block to reverse major:minor -> driver 5. lsmod, modinfo, and dmesg as companion tools 6. A worked debugging walkthrough tying it all together

Prerequisites

This lecture assumes you have worked through the character, block, and network device numbering lectures earlier in this free embedded Linux course.

/proc/devices: The Registration Table

The most direct view into the kernel’s driver registration tables is /proc/devices. It lists every currently registered character major, followed by every currently registered block major, exactly as they exist in the two separate namespaces discussed in earlier lectures.

$ cat /proc/devices
Character devices:
  1 mem
  4 /dev/vc/0
  4 tty
  4 ttyS
 13 input
 89 i2c
180 usb
253 ep_blockdemo

Block devices:
  8 sd
  9 md
259 blkext

Notice this file only tells you that a major number is taken and which name the driver registered it under — it says nothing about minors in use or about how many instances exist. For that, you need the two files below.

/proc/partitions: Live Block Numbering

As covered in the block device lecture, /proc/partitions lists every block device and partition the kernel currently knows about, with its exact major:minor pair and size:

$ cat /proc/partitions
major minor  #blocks  name

   8        0  244190646 sda
   8        1     524288 sda1
   8        2  243665920 sda2
 179        0   15558144 mmcblk0
 179        1     262144 mmcblk0p1

/sys/class: Drivers Organized by Subsystem

Where /proc/devices is a flat registration list, /sys/class presents the same information organized by what kind of device each driver manages, which is usually far more useful when you know what you are looking for but not which major number it uses.

$ ls /sys/class/
block  gpio  hwmon  i2c-dev  input  net  power_supply  tty  ...

$ ls /sys/class/net/
eth0  lo  wlan0

$ ls /sys/class/block/
sda  sda1  sda2  mmcblk0  mmcblk0p1

Each entry under a class directory is a symlink into the real device hierarchy under /sys/devices, and reading files inside it exposes live driver state without ever needing to write a debug print into the driver itself.

$ cat /sys/class/net/eth0/address
02:42:ac:11:00:02

$ cat /sys/class/net/eth0/operstate
up

$ cat /sys/class/block/sda/size
488397168

/sys/dev: Reversing a Major:Minor Pair Back to a Device

If you already have a major:minor pair — say, from ls -l on a device node — and want to find which sysfs device it corresponds to, /sys/dev/char and /sys/dev/block give you a direct reverse lookup, since both are laid out as MAJOR:MINOR symlinks.

$ ls -l /dev/mmcblk0
brw-rw---- 1 root disk 179, 0 Aug 19 09:00 /dev/mmcblk0

$ ls -l /sys/dev/block/179:0
lrwxrwxrwx 1 root root 0 Aug 19 09:00 /sys/dev/block/179:0 -> ../../devices/platform/soc/.../mmcblk0

This is the fastest way to confirm exactly which physical device a number you found elsewhere actually refers to, and it works identically for character devices under /sys/dev/char.

Companion Tools: lsmod, modinfo, dmesg

Three user-space tools round out the picture once you are past the raw /proc and /sys files:

# Which loadable kernel modules are currently resident?
$ lsmod
Module                  Size  Used by
ep_blockdemo           16384  0
ep_netdemo             16384  0

# What does a given module claim to provide/depend on?
$ modinfo ep_blockdemo
filename:       /lib/modules/6.x/extra/ep_blockdemo.ko
license:        GPL
depends:

# What did the driver log during probe/registration?
$ dmesg | grep -i ep_
[ 1234.567] ep_blockdemo: registered with major 253

A Worked Debugging Walkthrough

Suppose a USB storage stick you plugged in never gets a /dev/sdb node, and you want to find out why using only these tools, in order:

Debug Flow: Missing /dev/sdb
1. dmesg | tail -30 -> Confirm the kernel even saw the USB insertion event 2. cat /proc/devices | grep sd -> Confirm the sd driver’s major (8) is registered at all 3. cat /proc/partitions -> Confirm whether a device at major 8 shows up with any minor 4. ls /sys/class/block/ -> Confirm whether sysfs sees a new block device entry 5. ls /sys/dev/block/8:16 -> If step 3 showed 8:16, confirm which real device it maps to

Each step narrows the problem to a specific layer: no dmesg entry points at a USB or power problem before the driver is even involved; a registered major with no partition entry points at a probe failure inside the driver; a partition entry with no /dev node points at a udev/device-manager problem rather than a kernel problem at all. This layered approach — kernel log, then registration table, then live numbering, then sysfs — is the same one experienced kernel developers reach for before ever opening driver source.

Comparison of the Key Files

File/PathShowsBest for
/proc/devicesRegistered major numbers“Is my driver’s major even registered?”
/proc/partitionsLive block major:minor + size“Did my disk actually create a device?”
/sys/class/<subsystem>Devices grouped by type“What network/block/etc devices exist right now?”
/sys/dev/char, /sys/dev/blockReverse major:minor lookup“Which real device does this number belong to?”
lsmod / modinfoLoaded modules and their metadata“Is my module even loaded, and what does it depend on?”

Common Mistakes

  • Only checking /proc/devices and assuming a registered major guarantees a working device node — registration and successful probing are two different steps.
  • Forgetting that /proc/devices shows nothing about network devices, since they never register a major/minor at all.
  • Ignoring dmesg and jumping straight to sysfs, missing an early error that explains everything.
  • Confusing a symlink under /sys/class with the real device path — always follow it back to /sys/devices for the authoritative hierarchy.

Best Practices

  • Build a habit of checking dmesg, /proc/devices, and the relevant /sys/class directory in that order before suspecting driver source code.
  • Use /sys/dev/char/MAJOR:MINOR and /sys/dev/block/MAJOR:MINOR whenever you only have a number and need the real device identity.
  • Keep modinfo in your toolkit for confirming exactly which .ko file and version is actually loaded, especially on boards with multiple kernel builds around.

Summary

Once a system is running, /proc/devices, /proc/partitions, and the /sys/class / /sys/dev hierarchies give you a complete, code-free view of every character, block, and (through /sys/class/net) network driver active on the box. Combined with lsmod, modinfo, and dmesg, these files form the standard first line of debugging for any “why isn’t my device showing up” question in embedded Linux development, and they tie together everything covered across this chapter of the free Linux kernel development course.

Frequently Asked Questions

What is the fastest way to check if my driver’s major number is registered?

Run cat /proc/devices and grep for either your driver’s name or the major number you expect; it lists both character and block registrations.

Why doesn’t my network driver show up in /proc/devices?

Network devices never register a major or minor number, so they never appear there; check /sys/class/net instead.

How do I find which real device a major:minor pair belongs to?

Look it up under /sys/dev/char/MAJOR:MINOR or /sys/dev/block/MAJOR:MINOR, which are symlinks into the real /sys/devices hierarchy for that device.

My block major is registered but no partition appears — what does that mean?

It usually means the driver registered successfully but failed during probe or disk creation; check dmesg for errors logged after the registration message.

Is lsmod enough to confirm a driver is working correctly?

No, lsmod only confirms the module is loaded into memory; it says nothing about whether the driver successfully probed a device, which is why you also need dmesg and /proc/devices.

Does this lecture complete the free Linux device drivers course chapter on driver introduction?

Yes, this lecture closes out the introductory chapter on driver types and runtime inspection within this free Linux kernel development course.

Keep Going With This Free Linux Kernel Development Course

You now know how to identify and debug every major driver class covered in this chapter. The next chapter moves into writing a complete character driver from scratch.

Next Lecture Back to Course Index