

Focus on the first block of info for now. Now that you have established where your drive is located in your filesystem, you can view udev information about that device with this command: # udevadm info -a -n /dev/sdb | less If that command returned sdb: sdb1, for instance, you know the kernel has assigned your thumb drive the sdb label.Īlternately, you can use the lsblk command to see all drives attached to your system, including their sizes and partitions. If not, unplug and plug your thumb drive back in, then immediately issue this command: $ su -c 'dmesg | tail | fgrep -i sd*' The udevadm monitor command provides a lot of good info, but you can see it with prettier formatting with the command udevadm info, assuming you know where your thumb drive is currently located in your /dev tree. That's a good way to identify what type of event you want. Notice that the type of event is an ADD event. With udevadm monitor running, plug in a thumb drive and watch as all kinds of information is spewed out onto your screen. UDEV: the event udev sends out after rule processing.The monitor function prints received events for: Open your favorite text editor and enter this simple script: For testing, use /tmp, which is accessible by normal users and usually gets cleaned out with a reboot. The usual place for log files is in the /var directory, but that's mostly the root user's domain. Don't write the entire script upfront, but instead start with something that simply confirms that udev triggers some custom event.ĭepending on your goal for your script, you can't guarantee you will ever see the results of a script with your own eyes, so make sure your script logs that it was successfully triggered.


The best way to work with udev is in small chunks. Once you understand the process for working with udev, you can use it to do all manner of things, like loading a specific driver when a gamepad is attached, or performing an automatic backup when you attach your backup drive. This article teaches you how to create a udev script triggered by some udev event, such as plugging in a specific thumb drive. That makes it a potentially useful utility, and it's well-enough exposed that a standard user can manually script it to do things like performing certain tasks when a certain hard drive is plugged in. In plain English, that means it's the code that detects when you have things plugged into your computer, like a network card, external hard drives (including USB thumb drives), mouses, keyboards, joysticks and gamepads, DVD-ROM drives, and so on.

Udev is the Linux subsystem that supplies your computer with device events.
