197 Commits

Author SHA1 Message Date
Lennart Poettering
8e880e3b61 hostnamed: allow setting machine tags via udev rules (#42390)
This gives hostnamed a lot of love, and makes it possibly to "auto-tag"
a machine via a udev rule.

It builds on the machine tag concept added in v261.
2026-06-19 20:38:42 +02:00
Daan De Meyer
d8a625875c udev: only trigger the boot-disk loop device for optical drives
probe_gpt_boot_disk_needs_loop() sets ID_PART_GPT_AUTO_ROOT_DISK_NEEDS_LOOP
for any whole disk that holds the boot ESP/XBOOTLDR but whose partition table
the kernel cannot parse. Until now the udev rule turned that into a
systemd-loop@.service for every block device.

That is too broad: device-mapper devices also report kernel partition
scanning as disabled, but their partitions are managed in userspace by kpartx
(see 66-kpartx.rules). Setting up a loop device on top of them re-exposes the
same partition table a second time and only causes trouble.

Restrict the rule to optical drives, the one class that genuinely needs a
kernel-side loop device (El Torito GPT sector size mismatch, or drives that do
not support partition scanning) and that has no userspace partition manager of
its own.

Co-developed-by: Claude Fable 5 <noreply@anthropic.com>
2026-06-15 16:00:39 +02:00
Lennart Poettering
4a05010532 rules: auto-tag host from the SYSTEMD_MACHINE_TAG udev property
When a device carries a SYSTEMD_MACHINE_TAG udev property, tag it for
systemd and pull in systemd-machine-tag@<tag>.service, which adds the
given tag to the host's machine tags. In other words, attaching the
property to a device makes the host auto-tag itself with the specified
machine tag.
2026-06-01 10:56:16 +02:00
Diego Viola
5d17215c7e treewide: fix typos in the entire codebase
Signed-off-by: Diego Viola <diego.viola@gmail.com>
2026-05-05 17:22:26 +02:00
Daan De Meyer
4e0eabd401 udev: also trigger loop device for boot disk when partition scanning is unsupported
Previously, probe_gpt_sector_size_mismatch() would bail out early when
the GPT sector size matched the device sector size. However, some
devices (e.g. certain CD-ROM drives) do not support kernel partition
scanning even when sector sizes match. In that case, the kernel still
cannot parse the partition table, and we need to set up a loop device to
expose the partitions — just as we do for the sector size mismatch case.

Check blockdev_partscan_enabled() when sector sizes match, and only skip
the boot partition check if partition scanning is actually supported.

Also rename the function, udev property, and log messages to reflect the
broader scope:

- probe_gpt_sector_size_mismatch() -> probe_gpt_boot_disk_needs_loop()
- ID_PART_GPT_AUTO_ROOT_DISK_SECTOR_SIZE_MISMATCH -> ID_PART_GPT_AUTO_ROOT_DISK_NEEDS_LOOP
2026-04-04 22:24:47 +00:00
Daan De Meyer
047ae265cc udev: probe GPT sector size and trigger loop device on mismatch
When the GPT partition table uses a different sector size than the
device's native block size (e.g. 512-byte GPT on a 2048-byte CD-ROM
booted via El Torito), the kernel cannot parse the partition table.

Probe the GPT sector size upfront and configure blkid with the correct
value so it always finds the partition table. If a sector size mismatch
is detected, trigger a loop device to re-expose the device with the
correct sector size and skip root partition discovery on the original
device — it will happen on the loop device instead.

Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-04 20:03:44 +02:00
Lennart Poettering
56356c9dec udev: tag DMI id device with "systemd", so that we can order units after it
For various usecases it is useful to read relevant data from the DMI
udev device, but this means we need a way to wait for it for this to be
probed to be race-free. Hence tag it with "systemd", so that
sys-devices-virtual-dmi-id.device can be used as synchronization point.
2026-03-20 11:53:33 +01:00
Lennart Poettering
f2eed3fa25 hwdb: introduce hwdb for tpm2 devices
This hwdb is can carry hw quirks and similar for us, in particular tell
us if nvpcrs have a chance of working.
2026-03-04 08:28:41 +01:00
Lennart Poettering
dc75e54270 udev: add tpm2_id builtin
We need to be able to look up tpm2 metadata from hwdb, hence add a way
to synthesize a whdb lookup key from with udev rules.
2026-03-04 08:28:29 +01:00
David Santamaría Rogado
3e7b9b7462 udev: rules: improve usb integration detection
usb hubs tend to expose removable attribute as unknown. This makes some
problems like a hub for external usb ports in pogo pins is unknown and
also soldered hubs in laptops for keyboard+touchpad.

Let's set internal when the device removable attribute is fixed and
external when removable, but when it's unknown lets check the parent
ports (not the host devpath!=0) attribute to decide.

This makes us to missdetect pogo ping connected external usb hubs but
let us to correctly detect laptop internal keyboards and touchpads that
are wired through hubs instead directly.

This behaviour is more desirable, as actually there are a bunch of
laptops with this setup.

Fixes: a4381cae8b.
2026-03-04 07:33:51 +09:00
Mario Limonciello
9d3b73d9bf udev: tag kfd devices for xaccess-render (#40888)
The kfd device is used for running compute workloads on AMD
GPUs. Users that are logged in should be able to run compute
so tag them like other DRM and ACCEL devices are.
2026-03-02 12:32:50 +09:00
Yu Watanabe
20ce80436e udev: hwdb: replace ID_INPUT_JOYSTICK_INTEGRATION (#40761)
Could ask to Bastien Nocera who originally commited the joysticks hwdb
integration
https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1429#note_3338386
and stated that was for use in iio-sensor but later anything was done.

As the variable was never used replace it with the new variable actually
in the process to be use in libinput. Even more at least some of the
idea that was planed for ID_INPUT_JOYSTICK_INTEGRATION could be done in
libinput.

Actually ID_INPUT_JOYSTICK_INTEGRATION was never used anywhere, replace
it with ID_INTEGRATION.

Follow up: a4381cae8b.
2026-02-25 00:13:15 +09:00
Alessandro Astone
d0ad8f1175 udev: Trigger uaccess builtin on xaccess-* prefix
Fixup xaccess trigger after the rework.
There's no single `xaccess` tag anymore; instead we match on a prefix.
2026-02-24 11:54:15 +00:00
David Santamaría Rogado
e0684a9abc udev: hwdb: replace ID_INPUT_JOYSTICK_INTEGRATION
Actually ID_INPUT_JOYSTICK_INTEGRATION was never used anywhere, replace
it with ID_INTEGRATION.

Follow up: a4381cae8b.
2026-02-20 18:34:00 +01:00
Carolina Jubran
1e6854e112 udev: grant read access to PTP devices for unprivileged users
Change the default udev rule for /dev/ptp* from 0660 to 0664,
allowing unprivileged users read-only access.

NIC telemetry and hardware logs often use device timestamps that must
be correlated with host time via read-only PTP ioctls (e.g.
cross-timestamp queries). Requiring privileged access makes these
workflows unnecessarily restrictive.

Older kernels lacked proper permission checks in some PTP ioctls.
Kernel commit b4e53b15c04e3852949003752f48f7a14ae39e86 ("ptp: Add PHC
file mode checks. Allow RO adjtime() without FMODE_WRITE.") introduces
the necessary file mode validation, ensuring that read access does not
permit clock modification or configuration changes, which still require
write permissions.

This commit has been backported to all actively maintained stable
kernel branches.

Related to #31034
2026-02-19 14:51:12 +01:00
David Santamaría Rogado
17a3b387ae udev: rules: integration add spi bus for input dev
This bus is used for internal input devices let's set the ID_BUS
property accordingly to tag devices over SPI as internal.

Follow-up for a4381cae8b.
2026-02-19 06:45:13 +09:00
Mario Limonciello (AMD)
e30c044c23 Tag accel devices for uaccess-render
accel devices are used for things like NPUs and should be tagged
for the logged in user just like GPUs are.
2026-02-18 18:22:00 +01:00
David Santamaría Rogado
cad60201fc udev: rules: integration fix
ID_INTEGRATION is not being updated with hwdb entries, asign the new
value to it when hwdb has been imported.

We still need the 65-integration.rule assignment for devices that aren't
in hwdb.

While at it remove unneeded check in 70-touchpad.rules, as it was not
added for 70-joystick.rules with the statement if ID_INPUT_* is set and
ID_INPUT not, there is a bug elsewhere. And remove unneeded gotos in
both files.

Follow-up for a4381cae8b.
2026-02-18 11:51:02 +09:00
Alessandro Astone
2f5279d34b udev: Tag GPU render nodes as xaccess-render 2026-02-17 15:27:24 +01:00
David Santamaría Rogado
a4381cae8b udev: rules: guess devices if internal or external
Set ID_INTEGRATION variable to hint if a device is internal (inherent
part of the system) or external otherwise.
2026-02-16 03:46:25 +01:00
David Santamaría Rogado
155ae657b1 udev: rules: fix camera comparison
actually that is intended to be a comparison
2026-02-12 20:11:27 +00:00
Alessandro Astone
753341a221 rules: Tag DRM render nodes with xaccess
When systemd is compiled with group-render-mode=0660, only the active seat
gets access to the render devices through uaccess. Remote desktop sessions
like gnome-remote-desktop would be left with no hardware rendering, because
those sessions are not associated with a seat.

Tag the render nodes with "xaccess" so that access is also granted to remote
sessions created with XDG_SESSION_EXTRA_DEVICE_ACCESS=1
2026-02-06 16:20:18 +01:00
Alessandro Astone
5a198ad6f8 udev: Grant sessions access to devices tagged with xaccess
Grant access to devices tagged with "xaccess" on session start, if the session
was created with XDG_SESSION_EXTRA_DEVICE_ACCESS=1.

udev-builtin-uaccess is refactored to grant multiple users access to a device,
taking into account the device's seat and all the active EXTRA_DEVICE_ACCESS
sessions.
2026-02-06 16:20:18 +01:00
Rebecca Cran
b159befeae hwdb,rules: add 82-net-auto-link-local.{hwdb,rules} to build
Update hwdb.d/meson.build and rules.d/meson.build to add the
82-net-auto-link-local.{hwdb,rules} files into the build. Commit
ec541c569b in 2023 added the files
but didn't add them to the build system.
2025-12-05 16:03:22 -07:00
João Rodrigues
68ce283c3f Symlink for the /dev/ptp0 in vmware (#39917)
There are rules to create a symlink for the /dev/ptp0 device in KVM and
Hyper-V virtualization infrastructure but not for vmware.
2025-11-27 03:54:03 +09:00
Gero Schwäricke
032ea7ca12 rules: add rule to generate unique symlinks for gpio devices
Regular generated paths make it hard to identify individual GPIO
devices. This is a challenge when using multiple USB-to-GPIO adapters
like Diolan DLN2.

The unique symlinks from this rule can be used, e.g., with gpiod tools.
2025-11-10 23:22:08 +09:00
Mike Yuan
a4dae3c118 rules.d/60-block.rules: fix typo 2025-11-02 10:56:31 +01:00
Lennart Poettering
2103067f25 udev: introduce ID_BLOCK_SUBSYSTEM property
Virtual block devices are a bit weird: they have no parent device, and
thus cannot be related to the subsystem they belong to, except by
pattern matching their name. This is OK to do if one knows what to look
for. However for tools that do not want to carry a list of known
subsystems with their appropriate matching patters this sucks. Let's
introduce a new ID_BLOCK_SUBSYSTEM property we can set on block devices
that carries an explicit string for this. Do so for a small number of
key subsystems: DM, loopback and zram.
2025-11-01 22:01:35 +01:00
Lennart Poettering
6fac8bb9b1 rules: apply loopback block device rule only onto loopback block devices
Fixes: #39426
Follow-up for: 9422ce83c2
2025-10-24 22:21:14 +02:00
Yu Watanabe
5b09b43106 Don't tag i2c mice as pointing sticks (#39264)
There are no real i2c mice but there are i2c `FooBar Mouse` devices that
are an artifact of how the HID kernel drivers split up event nodes.
These nodes will be seen for some i2c keyboards and touchpads, depending
on the HID report descriptor.

Let's not tag those as pointing sticks.

Closes #36677
2025-10-20 15:04:27 +09:00
Peter Hutterer
5b647b84a9 rules: extend 60-input-id.rules to allow for bus/vid/pid/name matches
Same approach as used in 70-mouse.rules, allow for a name-based match
optionally combined with bus/vid/pid (which the existing modalias rule
would already allow us anyway). Note that ID_BUS isn't assigned until
after this rule has run so we need to use the id/bustype attribute
directly.

Related to https://github.com/systemd/systemd/issues/36677
2025-10-20 14:14:39 +10:00
Miroslav Lichvar
4db925d7da udev: create symlinks for s390 PTP devices
Similarly to the udev rules handling KVM and Hyper-V PTP devices, create
symlinks for the s390-specific STCKE and Physical clocks (supported
since Linux 6.13) to have some stable names that can be specified in
default configurations of PTP/NTP applications.
2025-10-14 18:31:17 +02:00
Zbigniew Jędrzejewski-Szmek
7d247d3cb8 meson: drop explicit custom_target names
[1] says:
> Since 0.60.0 the name argument is optional and defaults to the basename of
> the first output
We specify >= 0.62 as the supported version, so drop the duplicate name in all cases
where it is the same as outputs[0], i.e. almost all cases.

[1] https://mesonbuild.com/Reference-manual_functions.html#custom_target
2025-06-28 17:14:50 +02:00
Lennart Poettering
9422ce83c2 udev: reset loopback block device ownership and mode on detach
Loopback block devices are agressively reused, without being removed in
between. This means various inode attributes on their device nodes will
– so far – remain in effect between uses of the devices. Since there are
applications which change access mode/ownership of such devices after
attaching files to them, let's undo this again when we detect them to be
unused again.

Fixes: #37745
2025-06-24 13:10:11 +02:00
Yu Watanabe
a7deadd763 udev/rules.d: import hwdb before calling net_id builtin
The commit cdcb1eeeb8 adds
ID_NET_NAME_INCLUDE_DOMAIN property support in net_id builtin.
The property is basically set through hwdb. However, previously hwdb was
imported after calling net_id builtin, hence when net_id is called, the
property was never set.

This makes hwdb is imported before calling net_id builtin, so that the
property is set when net_id is called if hwdb has an entry about that
for the interface.

Follow-up for cdcb1eeeb8.
Fixes #37758.
2025-06-13 10:43:21 +01:00
Stefan Herbrechtsmeier
29a352e8c1 hostname: add hardware version
Add support for the hardware version. The version describes a distinct
version of compatibility hardware. The value is read from the file
/etc/machine-info or DMI as fallback.

The integration provides an unified interface to collect detail hardware
information. The /etc/machine-info entry enables embedded devices
without UEFI support to read the information from a custom store.
2025-05-22 09:00:14 +02:00
Stefan Herbrechtsmeier
79e9fb68a3 hostname: add hardware Stock-Keeping Unit
Add support for the hardware Stock-Keeping Unit (SKU). The SKU describes
a distinct type of hardware for sale, purchase or inventory management.
The value is read from the file /etc/machine-info or DMI as fallback.

The integration provides an unified interface to collect detail hardware
information. The /etc/machine-info entry enables embedded devices
without UEFI support to read the information from a custom store.
2025-05-22 09:00:14 +02:00
Daan De Meyer
6350d2dbd9 meson: Extract objects instead of creating intermediate static libraries
Currently, when we want to add unit tests for code that is compiled into
an executable, we either compile the code at least twice (once for the
executable, and once for each test that uses it) or we create a static
library which is then used by both the executable and all the tests.

Both of these options are not ideal, compiling source files more than
once slows down the build for no reason and creating the intermediate
static libraries takes a lot of boilerplate.

Instead, let's use the extract_objects() method that meson exposes on
build targets. This allows us to extract the objects corresponding to
specific source files and use them in other executables. Because we
define all executables upfront into a dictionary, we integrate this into
the dictionary approach by adding two new fields:

- 'extract' takes a list of files for which objects should be extracted.
  The extracted objects are stored in a dict keyed by the executable name
  from which they were extracted.
- 'objects' takes the name of an executable from which the extracted
  objects should be added to the current executable.

One side effect of this approach is that we can't build test executables
anymore without building the main executable, so we stop building test
executables unless we're also building the main executable. This allows
us to switch to using subdir_done() in all of these subdirectories to skip
parsing them if the corresponding component is disabled.

These changes get me down from 2439 => 2403 ninja targets on a full rebuild
from scratch.
2025-05-12 13:35:50 +02:00
LuK1337
edc49209f1 rules: Make ADB and fastboot work out-of-the-box
d0db47dcdf/adb.h (199)
7199051aaf/fastboot/fastboot.cpp (244)
2025-04-18 06:06:35 +09:00
Lennart Poettering
a8b2302bc1 udev: add dissect_image builtin
Fixes: #33453 #27897 #18035
2025-04-03 11:08:57 +02:00
Lennart Poettering
e3f6ae1d09 rules: split out gpt-root rules from 99-systemd.rules
All other rules in 99-systemd.rules are pretty much concerned about
SYSTEMD_READY=1 and tagging devices the service manager shall track. But
the gpt-root symlink is different, and it makes sense independently of
the service manager. Hence give it a separate file.

This introduces indentation for inner sections skipped via GOTO=. The
rules parser supports that. In order to make this more readable, let's
maybe make use of this.
2025-04-03 04:32:18 +09:00
Lennart Poettering
dc4cf3e539 rules: tag /dev/tpm0 with "systemd" too
Strictly speaking we don't need to tag these devices, because tpm2-tss
already does so, but given we do this for /dev/tpmrm0, we should
probably do this comprehensively if we rely on this ourselves.

Fixes: #36653
2025-03-07 16:09:32 +01:00
Lennart Poettering
c7da91ff66 gpt-auto symlinks: take factory reset mode into consideration
In relevant factory reset situation the root disk itself is subject to
removal. This somewhat conflicts with automatic root disk discovery,
since the system first comes up with one candidate for the root disk,
which is then replaced by another.

Let's address this by determining at the moment of probing for the
gpt-root logic what the factory reset state currently is. This is then
used to maintain two distinct symlinks to the gpt auto root device: one
which is always available and one that is only available if factory
reset is off or complete.

The new symlinks is not used by anything yet. This will be added in a
later commit.
2025-03-05 12:38:25 +01:00
Jelle van der Waa
7e638ccf59 hostnamed: expose ChassisAssetTag in dbus/varlink
Expose /sys/class/dmi/id/chassis_asset_tag in varlink/dbus commonly used
by companies to track inventory such as laptops.

On desktops and other products the `chassis_asset_tag` can contain
rubbish similar to product_name/product_vendor.

Closes: #36442
2025-02-26 11:29:25 +01:00
Nick Rosbrook
2aa1a265bc udev: add input/by-{id,path} symlinks for hidraw devices
Take some of the same rule structure from 60-persistent-input.rules, and
apply it to hidraw devices in 60-persistent-hidraw.rules.

Since one of the motivations for this is being able to easily reference
FIDO tokens, add a special case when ID_FIDO_TOKEN==1, and add 'fido'
to the symlink.
2025-01-27 18:57:13 +00:00
Nick Rosbrook
16f99f5be9 udev: add systemd tag to devices tagged with security-device
This ensures that device units are created for these, which is
convenient for other units that want to declare dependencies on
such devices.
2025-01-22 21:43:44 +01:00
Miroslav Lichvar
af96ccfc24 udev: set clock group for PTP and RTC devices
Add a new group for clock devices to enable applications like linuxptp
to open clocks without root privileges.
2025-01-16 21:12:47 +01:00
Luca Boccassi
af0a28854d meson: add udev/hwdb build aliases
Allows to do:

meson compile libudev udev hwdb
meson install --no-rebuild --tags libudev,udev,hwdb
2025-01-15 09:48:27 +00:00
Luca Boccassi
8442ac9c02 meson: add install tags for udev and hwdb
Allows building and installing them individually, like
other existing components
2025-01-10 15:15:13 +09:00
Yu Watanabe
a4d1891475 meson: allow to customize the access mode for tty/pts devices
Then, switch the default value to "0600", due to general security
concerns about terminals being written to by other users.

Closing #35599.
2024-12-16 21:36:07 +00:00