A Look Inside Linux series
A series of short topics on how Linux works and how to make it work the way you want it to, which I present during the weekly sessions of the Linux User Net. The target audience is Hams who are new to Linux and want to know more about it, as well as experienced Linux users who can learn more about their chosen operating system. These are my notes for the presentations. (Russ, KC7MM)
One of the stellar features of Linux is the way it manages devices:
Today we'll look at that second item: the device interfaces. They are all located in The Linux /dev directory. And, there are a lot of them. We'll confine our discussion to the ones we users are most likely to work with.
The /dev directory is the home of hardware interfaces. These interfaces work in a variety of ways, each one depending on the nature of the device driver that sits behind it.
The purpose of an interface is to allow programs to interact with the device by passing data. The nature of that data interchange depends on function of the device.
We'll start by looking at /dev
directories that you're likely to encounter:
/dev/ttyS
X for UART devices and /dev/ttyUSB
X for USB. (The X is a sequential integer: ttyS0
, ttyS1
…)/dev/ttyACM
X. /dev/hidraw
X/dev/sd
XX, /dev/mmcblk
XX, etclsblk
in a terminal.Most current Linux systems use Udev to manage devices.
Devices that are present at the time the system boots are detected by the kernel, and Udev creates /dev
subdirectories for them:
/dev
subdirectory.Udev rules control the mapping of devices to /dev directories.
Some Udev rules are put in place when a Linux system is installed. These set the default behavior of Udev. The system administrator – you – can create additional rules to suit your particular needs. As we'll see, this comes in handy when you need to consistently map a device to a specific directory.
Recall that the Udev daemon does its job in response to events that it receives from the kernel. Those events can occur at any time, in any order.
Udev creates device directories in numerical order, starting at zero (0): for example, tty0
, followed by tty1
, tty2
, etc.
Since the incoming device events have no fixed order, devices may be assigned to any /dev
subdirectory. Thus, a device that's using /dev/ttyUSB0
now could be assigned to /dev/ttyUSB3
the next time the system is rebooted.
This is fine much of the time, but doesn't work very well in the case in which software is configured to work with a particular device, say /dev/ttyACM3
. What you need, then, is for Udev to assign the device to /dev/ttyACM3
every time it is connected. The way to make that happen is to create a Udev rule for the device.
I wish I could tell you that setting up Udev rule is a trivial process but, alas, it takes some effort – although simply setting a directory mapping for a device is pretty straightforward and shouldn't resent a problem to neophytes. For help with that, look at this excellent post by Johnathan, KI7UEZ, on our groups.io site.
Doing something more esoteric can be tricky. I needed to set group permissions on a /dev/hidraw
directory for USB control box for my SDR transceiver. I found it to be a significant challenge, but I was able to make it happen in the end. YMMV, depending on what you need the rule to do.
(BTW, we saw when looking at the Linux file system that access to system hardware is controlled through file permissions on device directories. /dev
is where that is done, and Udev rules are the way to set those permissions.)
In any case, the process of creating Udev rules is not something I can cover over the radio. Fortunately, there's a lot of information on it on the Web. The Arch Linux wiki is an excellent source that I found to be most helpful. And here's another good source.
Regarding the Arch Linux wiki, I've found it to be an excellent source of information on Linux technical topics, particularly system configuration. I have benefited from it numerous times, and suggest that a trip there when you're confronting a technical conundrum might be just the thing you need.
We've seen that:
/dev
directory.