A better way of managing device nodes

Creating device nodes statically with mknod is quite hard work and inflexible. There are other ways to create device nodes automatically on demand:

If you have booted up one of the earlier ramdisk examples, trying out devtmpfs is as simple as entering this command:

You should see that /dev is full of device nodes. For a permanent fix, add this to /etc/init.d/rcS:

In point of fact, kernel initialization does this automatically unless you have supplied an initramfs ramdisk as we have done! To see the code, look in the init/do_mounts.c, function prepare_namespace().

While mdev is a bit more complex to set up, it does allow you to modify the permissions of device nodes as they are created. Firstly, there is a startup phase, selected by the -s option, when mdev scans the /sys directory looking for information about current devices and populates the /dev directory with the corresponding nodes.

If you want to keep track of new devices coming on line and create nodes for them as well, you need to make mdev a hotplug client by writing to /proc/sys/kernel/hotplug. These additions to /etc/init.d/rcS will achieve all of that:

The default mode is 660 and ownership is root:root. You can change that by adding rules in /etc/mdev.conf. For example, to give the null, random, and urandom devices their correct modes, you would add this to /etc/mdev.conf:

The format is documented in the BusyBox source code in docs/mdev.txt and there are more examples in the directory named examples.

Statically created device nodes do have one advantage: they don't take any time during boot to create, whereas the other methods do. If minimizing boot time is a priority, using statically-created device nodes will save a measurable amount of time.