3

I'm working on Linux Kernel 3.14.28 build with Buildroot for an embedded device.

In /dev/, all ttys are root:root and not root:dialout like a standard Linux. So it is not possible to access any ttyX without being logged as root.

How can I change the tty group permanently to root:dialout? I try to change it with chown command, but it became root:root again on reboot.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
AntoineC
  • 111
  • 1
  • 2
  • 10
  • I'm using /devtmpfs and I do not know if there is a way to configure driver permission with it. There are solution with udev or static table for /dev management. But I would prefer to keep devtmpfs – AntoineC Jun 15 '15 at 14:45
  • 1
    With just devtmpfs, you cannot customize the permissions, except by running a shell script or something like that at boot time. Indeed the permissions do not persist accross reboots: devtmpfs is a virtual filesystem, so it only exist for the duration of the system life. If you want to customize permissions, you should use mdev or udev. – Thomas Petazzoni Jun 15 '15 at 21:37

2 Answers2

1

devtmpfs always sets permissions to 0600 and makes it up to udev (or whatever runs after it) to maintain them. Its source confirms there's no way to override this explicitly (tty device driver overrides mode unconditionally in some cases).

Assuming you're using the Buildroot's default busybox as init, there's a way to do this with the following additional line in busybox's inittab (additional=must be present in addition to the essential lines (or their replacements) that are implied when there's no inittab - as they are no longer implied then there is):

::sysinit:<path_to_your_script>

with the script calling chown and chmod in loop.

But, it's better to handle this within the existing /etc/init.d/rcS (which is also run by BusyBox's init at sysinit by default).

As you can see from the stock buildroot's /etc/init.d/rcS, all you need to do is create a script /etc/init.d/S<whatever>.sh (where "whatever" places it into the desired position in the /etc/init.d/S??* output) with your commands:

for tty in /dev/tty*; do
    chown root:dialout "$tty"
    chmod ug+rw "$tty"   #do not touch other bits
done
unset tty
ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
1

TL;DR: choose mdev as your device manager, and use the tty group instead of dialout.

The kernel's devtmpfs creates device nodes with a default name, owner and permissions. It also sends out a uevent when the node is created, which allows a uevent handler to change the name, ownership or permissions, or do anything else it wants. Previously this was called the hotplug system, but nowadays it's much more generic.

Buildroot offers the choice between three uevent handlers: mdev, which is part of busybox, eudev which is a standalone udev fork, and udev which is part of the systemd init system. These handlers are configured with rules files that specify what to do with a specific type of device when it appears.

For your specific need, mdev is the best choice since it is very simple, easy to understand, doesn't take up much space, and the default configuration is sufficient. In Buildroot's menuconfig, go to System configuration/dev management and select Dynamic using mdev. Then rebuild your root filesystem. It will now be populated with the mdev binary (part of busybox), an init script to start it, and a default rules file in /etc/mdev.conf. This default file contains:

tty[0-9]*       root:tty 660

This means that the tty devices will get their group changed to tty and their permissions to group read and write. So you can just make sure that the logged in user belongs to the tty group, and Bob's your uncle.

If the default mdev.conf file is not sufficient for you (for instance, if you really need the group to be dialout), then you can create a filesystem overlay, copy package/busybox/mdev.conf to /etc/mdev.conf and modify it as needed. Full documentation on the mdev.conf format can be found in the busybox sources.

Arnout
  • 2,927
  • 16
  • 24