The Linux Concept Journey — <Major:Minor> Numbers

Shlomi Boutnaru, Ph.D.
2 min readDec 29, 2023

--

In the Linux kernel devices (character/block device) are represented as a pair of numbers (<major>:<minor>). There are some major/minor numbers which are reserved while others are assigned dynamically. A major number can be shared between multiple device drivers (https://www.ibm.com/docs/en/linux-on-systems?topic=hdaa-device-nodes-numbers).

Overall, device files are located in “/dev” and they allow accessing the device from user-mode. Those files are “connected” to the device using the major and minor number — as shown in the diagram below on the left side (https://www.ibm.com/docs/en/linuxonibm/com.ibm.linux.z.ufdd/lxnode.jpg). We can see them using “ls -l” — as shown in the shell output in the screenshot below (taken from copy.sh). The major number identifies the drivers associated with the device, while the minor number is used only by the driver which gets the number without the kernel using it (https://www.oreilly.com/library/view/linux-device-drivers/0596000081/ch03s02.html).

Moreover, the kernel code that can assign the name and the major number for a specific device char device can use the “register_chrdev” function (https://elixir.bootlin.com/linux/v6.6.1/source/include/linux/fs.h#L2535). In case of a block device can use the macro “register_blkdev” (https://elixir.bootlin.com/linux/v6.6.1/source/include/linux/blkdev.h#L809).

Lastly, we can use the “mknod” (https://man7.org/linux/man-pages/man1/mknod.1.html) command to create a block/char device file by providing a name, major and minor numbers. We can also list the major numbers of the currently registered devices with their names (https://man7.org/linux/man-pages/man5/procfs.5.html) — as shown in the output of the screenshot below.

See you in my next writeup ;-) You can follow me on twitter — @boutnaru (https://twitter.com/boutnaru). Also, you can read my other writeups on medium — https://medium.com/@boutnaru. You can find my free eBooks at https://TheLearningJourneyEbooks.com.

--

--