5

Spun off from a small exchange in chat.

One of the primary advantages of udev is that you don't have to worry about major and minor device number exhaustion anymore. But the devices created by udev still have these numbers associated with them. How does udev cooperate with the kernel to create device files with the proper major and minor device numbers?

5

The kernel allocates a major:minor number, either statically (in drivers that do have a static allocation and haven't run out) or dynamically (in drivers that support dynamic allocation and have used up their static allotment). This number is listed in the message that the kernel sends to udev.

You can see the variables that udev sees about a device in /sys/devices/…/uevent. For example:

$ cat /sys/devices/virtual/mem/null/uevent 
MAJOR=1
MINOR=3
DEVNAME=null
DEVMODE=0666
$ cat /sys/block/sda/sda1/uevent 
MAJOR=8
MINOR=1
DEVNAME=sda1
DEVTYPE=partition

The udev rules determine the name(s) and permissions of the device files. The device number comes from the kernel (it has to, since the kernel has already taken a decision and udev's job is to ensure that applications accessing the device by name will reach the number chosen by the kernel).

| improve this answer | |
0

The device numbers aren't chosen at random, no matter what subsystem creates the devices. There is a device number standard, called the LANANA Linux Device List. If you install the kernel-documentation, check out Documentation/devices.txt.

| improve this answer | |
  • 2
    While the choice isn't random, it is sometimes dynamic, in the blocks marked “local/experimental use” in the device list. – Gilles 'SO- stop being evil' Dec 13 '13 at 0:27

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.