mknod has eluded me for a while. I’ve had to use it a couple of times, in rushed following of tutorials, and I know it’s used to create the device files under /dev. It’s not the preferred way of doing it (which is mkdev), and it’s not the normal way (udev and/or devfs tend to do a good job of doing it automatically).
It needs to be told of the device type (easy enough: block, character or terminal) and be supplied with a major and a minor number.
That’s the bit that’s confused me for a while – major and minor numbers – but I’ve just decided to actually read beyond the man page and find this.
Much as I’d half-expected some peculiar mathematical relationship, it turns out to just be the way the list of devices known to the kernel is ordered.
It’s split into groups, each group is sequentially numbered (the major number), and for each group, every item in it is also sequentially numbered (the minor numbers).
Here’s a handy snippet from mine, showing major number 83, and the listing of minor numbers 0,1,2 and 15:
83 char Matrox mga_vid video driver 0 = /dev/mga_vid0 1st video card 1 = /dev/mga_vid1 2nd video card 2 = /dev/mga_vid2 3rd video card ... 15 = /dev/mga_vid15 16th video card
And that’s basically it. If I install a second matrox mga video card and don’t run anything to automatically create the device for me, I need to run mknod /dev/mga_vid1 c 83 1. The name I supply is not dictated by the file – I could have called it /dev/secod_matrox_video_card if I’d really wanted to – the other parameters must be correct to identify the device, the name supplied is for the user to dictate what the device should be called. It’s wise to name it in such a way as to avoid clashes, though.
In order to get a copy of the file, under Debian running a 2.4.37 kernel, having installed linux-source-2.4.37, you’ll find /usr/src/linux-source-2.4.37.tar.bz2 which you can extract to get at the kernel source. In here, in the Documentation directory is a file called devices.txt, which lists the devices known to your kernel and their numbers.
The current version of the list is maintained here