Reputation: 121
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.
Upvotes: 3
Views: 4722
Reputation: 35998
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
Upvotes: 1
Reputation: 3464
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.
Upvotes: 1