Identifying major and minor numbers for a block device in Linux

One of the basic features of the Linux kernel is that it abstracts the handling of devices. All hardware devices look like regular files; they can be opened, closed, read and written using the same, standard, system calls that are used to manipulate files. Every device in the system is represented by a file. For block (disk) and character devices, these device files are created by the mknod command and they describe the device using major and minor device numbers.

The kernel needs to be told how to access the device. Not only does the kernel need to be told what kind of device is being accessed but also any special information, such as the partition number if it's a hard disk or density if it's a floppy, for example. This is accomplished by the major number and minor number of that device.

Major Numbers: All devices controlled by the same device driver have a common major device number. The major number is actually the offset into the kernel's device driver table, which tells the kernel what kind of device it is (whether it is a hard disk or a serial terminal).

Minor Numbers: The minor number tells the kernel special characteristics of the device to be accessed. For example, the second hard disk has a different minor number than the first. The COM1 port has a different minor number than the COM2 port, each partition on the primary IDE disk has a different minor device number, and so forth. So, for example, /dev/hda2, the second partition of the primary IDE disk has a major number of 3 and a minor number of 2.

[root@RHEL610 ~]# ls -l /dev/sd*
brw-rw---- 1 root disk  8,  16 Feb  8 17:47 /dev/sdb
brw-rw---- 1 root disk  8,  32 Feb 11 14:32 /dev/sdc
brw-rw---- 1 root disk  8,  48 Feb 11 15:56 /dev/sdd

Note: In the above output "8" is major number for sdb/sdc/sdd devices. Minor number for sdb is "16", "32" for sdc and "48" for sdd block device.

The major numbers for SCSI and IDE disks are fixed:

SCSI disks (/dev/sd*) major number is 8.
IDE disks (/dev/hd*) major number is 3.

Comments

Post a Comment

Popular posts from this blog

Recover or restore initramfs file in RHEL or CentOS 7

Space reclamation / UNMAP on RHEL or CentOS 7

How to recover /boot partition on RHEL or CentOS 7?