Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I write a udev rule that whitelists specific vendors and doesn't allow other USB drives? Do I put it in /etc/udev/rules.d, or /lib/udev/rules.d? What command do I run to test if the rule is working?

share|improve this question

You use the udevadm utility to retrieve the relevant information for your device, filtering for the vendor details should narrow down your return, eg.,

udevadm info -a -n /dev/sdc | grep vendor

You can then use the information to build a udev rule to perform, or restrict, actions dependant upon the type of device that is mounted.

The Arch Wiki has a good entry on writing udev rules and there is a much fuller description (although some of it is outdated) on the Writing udev rules page maintained by Daniel Drake.

The rule is placed in /etc/udev/rules.d/ and is named according to this convention: number-name.rules where the number indicates precedence and the name is for identifiability. See man udev:

Rules files
The udev rules are read from the files located in the system rules directory /usr/lib/udev/rules.d, the volatile runtime directory /run/udev/rules.d and the local administration directory /etc/udev/rules.d. All rules files are collectively sorted and processed in lexical order, regardless of the directories in which they live. However, files with identical file names replace each other.

Files in /etc have the highest priority, files in /run take precedence over files with the same name in /lib. This can be used to override a system-supplied rules file with a local file if needed; a symlink in /etc with the same name as a rules file in /lib, pointing to /dev/null, disables the rules file entirely.

Rule files must have the extension .rules; other extensions are ignored.

Ensure that your rule to mount the vendor-specific drives has precedence over the accompanying rule to disallow mounting with OPTIONS+="ignore_device".

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.