2

file /dev/* prints the description of a bunch of files as "block special (M/N)" and "character special (M/N)", where M and N are numbers. For example:

$ file /dev/null
/dev/null: character special (1/3)

man file doesn't seem to document these, but refers vaguely to man stat, which seems to refer to these as major and minor device types. apropos 'device type' finds nothing. So what do these numbers mean?

5

Devices on Unix have a type (e.g. character or block), a major number (which typically refers to a driver), and a minor number (which typically refers to an instance).

So, for example:

% ls -l /dev/vda
brw-rw---- 1 root disk 253, 0 Feb  3 09:09 /dev/vda

This is a block device, major 253, minor 0.

If we look at /proc/devices we see it ends with something similar to

Block devices:
  2 fd
259 blkext
  9 md
253 virtblk
254 mdp

So we can see that 253 is "virtblk". Which makes sense, since this is a virtual machine with virtual disks!

The minor number, for this driver, refers to the block device and partition in the device

% ls -l /dev/vd*
brw-rw---- 1 root disk 253,  0 Feb  3 09:09 /dev/vda
brw-rw---- 1 root disk 253,  1 Feb  3 09:09 /dev/vda1
brw-rw---- 1 root disk 253,  2 Feb  3 09:09 /dev/vda2
brw-rw---- 1 root disk 253,  3 Feb  3 09:09 /dev/vda3
brw-rw---- 1 root disk 253, 16 Feb  3 09:09 /dev/vdb
brw-rw---- 1 root disk 253, 32 Feb  3 09:09 /dev/vdc
brw-rw---- 1 root disk 253, 33 Feb  3 09:09 /dev/vdc1

There are some special drivers which don't refer to "real" hardware. eg

% ls -l /dev/null
crw-rw-rw- 1 root root 1, 3 Feb  3 09:09 /dev/null

This is a character device, major 1, minor 3. /proc/devices tells us driver 1

  1 mem

We can see this "mem" driver handles a few other devices as well

% ls -l /dev | grep ' 1, '
crw-rw-rw- 1 root root      1,   7 Feb  3 09:09 full
crw-r--r-- 1 root root      1,  11 Feb  3 09:09 kmsg
crw-r----- 1 root kmem      1,   1 Feb  3 09:09 mem
crw-rw-rw- 1 root root      1,   3 Feb  3 09:09 null
crw------- 1 root root      1,  12 Feb  3 09:09 oldmem
crw-r----- 1 root kmem      1,   4 Feb  3 09:09 port
crw-rw-rw- 1 root root      1,   8 Feb  3 09:09 random
crw-rw-rw- 1 root root      1,   9 Feb  3 09:09 urandom
crw-rw-rw- 1 root root      1,   5 Feb  3 09:09 zero
  • That gives me a nice short name and index. Do you know what those short names mean? Some of them are pretty obvious, but I have no idea what "ttyS", "vcs", "sg", and many of the others mean in this context. – l0b0 Feb 6 at 3:06
  • 2
    The names are picked by the drivers. Many of them have manpages; eg man vcs. Others don't. ttyS is serial; vcs is virtual console memory; sg is raw scsi (I think). – Stephen Harris Feb 6 at 3:08
  • @StephenKitt That would work very well as an answer. – l0b0 Feb 6 at 7:08
2

Each device node’s type (block or character) and numbers (known as the major and minor number) serve as identifiers for the kernel.

On Linux, the canonical list of devices, with a brief explanation of their function, is maintained in the kernel. You can see there that a major number typically identifies a driver (e.g. the TTY device driver) and a minor number identifies a device managed by that driver.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.