mdev.txt 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. -------------
  2. MDEV Primer
  3. -------------
  4. For those of us who know how to use mdev, a primer might seem lame. For
  5. everyone else, mdev is a weird black box that they hear is awesome, but can't
  6. seem to get their head around how it works. Thus, a primer.
  7. -----------
  8. Basic Use
  9. -----------
  10. Mdev has two primary uses: initial population and dynamic updates. Both
  11. require sysfs support in the kernel and have it mounted at /sys. For dynamic
  12. updates, you also need to have hotplugging enabled in your kernel.
  13. Here's a typical code snippet from the init script:
  14. [1] mount -t sysfs sysfs /sys
  15. [2] echo /bin/mdev > /proc/sys/kernel/hotplug
  16. [3] mdev -s
  17. Of course, a more "full" setup would entail executing this before the previous
  18. code snippet:
  19. [4] mount -t tmpfs mdev /dev
  20. [5] mkdir /dev/pts
  21. [6] mount -t devpts devpts /dev/pts
  22. The simple explanation here is that [1] you need to have /sys mounted before
  23. executing mdev. Then you [2] instruct the kernel to execute /bin/mdev whenever
  24. a device is added or removed so that the device node can be created or
  25. destroyed. Then you [3] seed /dev with all the device nodes that were created
  26. while the system was booting.
  27. For the "full" setup, you want to [4] make sure /dev is a tmpfs filesystem
  28. (assuming you're running out of flash). Then you want to [5] create the
  29. /dev/pts mount point and finally [6] mount the devpts filesystem on it.
  30. -------------
  31. MDEV Config (/etc/mdev.conf)
  32. -------------
  33. Mdev has an optional config file for controlling ownership/permissions of
  34. device nodes if your system needs something more than the default root/root
  35. 660 permissions.
  36. The file has the format:
  37. <device regex> <uid>:<gid> <octal permissions>
  38. For example:
  39. hd[a-z][0-9]* 0:3 660
  40. The config file parsing stops at the first matching line. If no line is
  41. matched, then the default of 0:0 660 is used. To set your own default, simply
  42. create your own total match like so:
  43. .* 1:1 777
  44. You can rename/relocate device nodes by using the next optional field.
  45. <device regex> <uid>:<gid> <octal permissions> [>path]
  46. So if you want to place the device node into a subdirectory, make sure the path
  47. has a trailing /. If you want to rename the device node, just place the name.
  48. hda 0:3 660 >drives/
  49. This will relocate "hda" into the drives/ subdirectory.
  50. hdb 0:3 660 >cdrom
  51. This will rename "hdb" to "cdrom".
  52. If you also enable support for executing your own commands, then the file has
  53. the format:
  54. <device regex> <uid>:<gid> <octal permissions> [<@|$|*> <command>]
  55. The special characters have the meaning:
  56. @ Run after creating the device.
  57. $ Run before removing the device.
  58. * Run both after creating and before removing the device.
  59. The command is executed via the system() function (which means you're giving a
  60. command to the shell), so make sure you have a shell installed at /bin/sh. You
  61. should also keep in mind that the kernel executes hotplug helpers with stdin,
  62. stdout, and stderr connected to /dev/null.
  63. For your convenience, the shell env var $MDEV is set to the device name. So if
  64. the device "hdc" was matched, MDEV would be set to "hdc".
  65. ----------
  66. FIRMWARE
  67. ----------
  68. Some kernel device drivers need to request firmware at runtime in order to
  69. properly initialize a device. Place all such firmware files into the
  70. /lib/firmware/ directory. At runtime, the kernel will invoke mdev with the
  71. filename of the firmware which mdev will load out of /lib/firmware/ and into
  72. the kernel via the sysfs interface. The exact filename is hardcoded in the
  73. kernel, so look there if you need to want to know what to name the file in
  74. userspace.