When the Linux kernel detects a new device, it sends a message to udev. The job of udev is to make the new device accessible to user land. For many devices, all udev needs to do is to create entries in /dev
. For block devices, this allows the device to be mounted. For character devices such as serial ports and sound ports, this allows dedicated applications to use the device. For network interfaces, udev may set a name. For keyboards, udev may also define additional scancodes. If udev doesn't create a device entry, this effectively causes the device to be unused.
Udev can be controlled by rules; default rules are present in /lib/udev/udev.d
and they can be overridden by the administrator via files in /etc/udev/udev.d
. Each udev rule has conditions of the form VARIABLE==VALUE
; the rule applies if all of these rules are met. You can see the conditions that apply to a device by running udevadm info -a -n /dev/…
or udevadm info -a /sys/…
.
As far as I know, there's no generic mechanism to ignore a device. If it isn't a network interface (which doesn't use a device node under /dev
), you can make it effectively unusable by giving it no permissions:
CONDITIONS, MODE="000"
USB devices have an authorization mechanism: if the authorized
attribute is set to 0 (false), the system will not access the device. With this rule, no USB device will be available other than USB storage devices.
ACTION=="add", SUSYSTEMS=="usb", DRIVERS!="usb-storage", ATTR{authorized}="0"
It's also possible to disable USB devices after the boot sequence by disabling all USB host ports with this snippet in /etc/rc.local
:
for x in /sys/bus/usb/devices/usb*; do
echo 0 >"$x/authorized_default"
done
Individual devices can be enabled via a udev rule (or manually) that sets the authorized
attribute to 1.
If you want to make a storage device read-only, set its ro
attribute to 1.
If you want to run a command, use the RUN
key in a udev rule (note that you need the full path to the command, and see the manual for available escape sequences and environment variables). If you want that command to access the GUI, see
Open a window on a remote X display (why "Cannot open display")?