udev
"udev supplies the system software with device events, manages permissions of device nodes and may create additional symlinks in the /dev directory, or renames network interfaces." - man udev
Tips
- Default rules are in
/lib/udev/rules.d
Monitor udev events in real time
udevadm monitor
View udev environment for a given disk
This is helpful when writing udev rules.
udevadm info /dev/sda
View human readable information about a disk
udisksctl info -b /dev/sda
Mount namespace problems
In Ubuntu and probably other linuxes udevd runs in its own mount namespace. This means if you mount things using udev rules, by default they will be in an isolated namespace where users and other processes cannot access them. You can view this with:
root@bionic:~# lsblk -o NAME,MOUNTPOINT /dev/sdc
NAME MOUNTPOINT
sdc
└─sdc1
root@bionic:~# nsenter --all -t $(pgrep systemd-udevd) lsblk -o NAME,MOUNTPOINT /dev/sdc
NAME MOUNTPOINT
sdc
└─sdc1 /mnt/adea64ca-e340-4961-8a4d-75d8a5970664
To solve this, run systemctl edit systemd-udevd
and input the following config:
[Service]
MountFlags=shared
Then run systemctl daemon-reload ; service systemd-udevd --full-restart ;
See man 7 mount_namespaces
for more info.
Trigger a disk add event for a disk that has already been inserted
udevadm trigger -t devices --name /dev/sda1 --action=add
List builtin modules
udevadm test-builtin --help