2

I've got a GPS module hanging on the TTL UART wires of my Pi 3B. I don't access the module directly, but via gpsd. Now I've got the following issue: At every reboot, Raspbian (Buster) seems to reset the group and the privilege mask of the UART:

pi@autoradio:/import/valen/autoradio $ ls -al /dev/ttyS0
crw--w---- 1 root tty 4, 64 Sep 11 00:06 /dev/ttyS0

Consequence: gpsd can't access the module and quits:

pi@autoradio:/import/valen/autoradio $ sudo systemctl status gpsd
● gpsd.service - GPS (Global Positioning System) Daemon
   Loaded: loaded (/lib/systemd/system/gpsd.service; disabled; vendor preset: enabled)
   Active: active (running) since Sat 2021-09-11 00:05:55 CEST; 17min ago
 Main PID: 608 (gpsd)
    Tasks: 1 (limit: 2059)
   CGroup: /system.slice/gpsd.service
           └─608 /usr/sbin/gpsd /dev/ttyS0

Sep 11 00:05:55 autoradio systemd[1]: Starting GPS (Global Positioning System) Daemon...
Sep 11 00:05:55 autoradio systemd[1]: Started GPS (Global Positioning System) Daemon.
Sep 11 00:13:18 autoradio gpsd[608]: gpsd:ERROR: SER: device open of /dev/ttyS0 failed: Permission denied - retrying read-only
Sep 11 00:13:18 autoradio gpsd[608]: gpsd:ERROR: SER: read-only device open of /dev/ttyS0 failed: Permission denied
Sep 11 00:13:18 autoradio gpsd[608]: gpsd:ERROR: /dev/ttyS0: device activation failed.
Sep 11 00:13:18 autoradio gpsd[608]: gpsd:ERROR: /dev/ttyS0: activation failed, freeing device

As far as I can remember, I had a privilege structure like this before making a new SD card with a fresh Raspbian:

crw-rw---- 1 root dialout

Setting privileges by hand only works until the next shutdown. What's going on here? How can I tell Raspbian to get the hand off the privileges of /dev/ttyS0? Thank you.

3
  • 2
    /dev on modern systems isn't a persistent filesystem, it's a ramdrive populated by udev rules, you probably need to add a udev rule that recognises your GPS device and assigns appropriate permissions. Sep 11 at 2:17
  • askubuntu.com/questions/676007/… make sure to specify the appropriate user and group (dialout)
    – Abel
    Sep 11 at 3:17
  • Why not add the userid for the failing process to the tty group?
    – Dougie
    Sep 11 at 10:56
3

Setting privileges by hand only works until the next shutdown. What's going on here?

As per a comment on the question, files in /dev (and various other places such as /sys and /proc) aren't stored on disk anywhere; if you find stuff there on the card when you put it in another machine (ie., not using it as a root fs), it's there by mistake and in any case will be not be used by anything during runtime as a devfs filesystem is mounted there by the kernel. This filesystem exists only in RAM and is used as an interface with the kernel.

To change how /dev/ttyS0 is configured at boot, create a file in /etc/udev/rules.d owned root and prefixed with a number,1 eg. 00-ttyS0.rules, and the following contents:

KERNEL=="ttyS0", GROUP="dialout", MODE="0660"

You can then test this:

> sudo udevadm control --reload-rules
> sudo udevadm trigger /dev/ttyS0
> stat /dev/ttyS0

You should get the settings you asked for. This will then persist across boots.

Since gpsd is a stock service, I imagine the reason this isn't already done is you could be using any one of a number of serial dev nodes. Udev is a bit awkward to use (IMO) but reasonably well documented; see man udev for a start (and if you are searching online remember, it isn't specific to the Pi or Raspbian/RpiOS, but works the same everywhere).


  1. It doesn't actually have to have a number prefixed, but this is the convention as the files are processed in lexicographical order, earlier takes precedence and there are a great many udev rule files loaded from other places; but an 00- prefix should trump any of them. Doesn't matter much as I think you will have no conflicts for this one.
0

After an outside hint, I re-ran raspi-config. At first glance, the serial port settings were correct, so that I hadn't to change them:

The serial login shell is disabled
The serial interface is enabled

…but there must have been an issue (maybe even with udev), which disappeared when raspi-config saved its settings for a second time. Now the rights on the serial port are correct and remain after reboot:

pi@autoradio:/import/valen/autoradio $ ls -al /dev/ttyS*
crw-rw---- 1 root dialout 4, 64 Sep 11 23:24 /dev/ttyS0

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.