9

I've written file 90-usb.rules under /etc/udev/rules.d/ containing:

ACTION=="add", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="2008", RUN+="/bin/mkdir /home/pandya/Desktop/testdir"
ACTION=="remove", ATTR{idVendor}=="0bb4", ATTR{idProduct}=="2008", RUN+="/bin/rmdir /home/pandya/Desktop/testdir"

When I plugged in device udev ACTION=="add" creates directory by means of RUN+="/bin/mkdir /home/pandya/Desktop/testdir" (which works fine)

BUT when I unplugged device similar udev ACTION=="remove doesn't removes directory by means of RUN+="/bin/rmdir /home/pandya/Desktop/testdir"

There is no problem with /bin/rmdir because I've also checked by replacing it with another mkdir (RUN+="/bin/mkdir /home/pandya/Desktop/testdir2") but this also not working.

So, I want to know that Why removal action is not working? How do I fix it?

  • @don_crissti Yes, action by using ENV is working. I tried ENV{ID_MODEL} which is working fine. Thank-you (BTW if you are interested to post answer, then ask me to add udevadm monitor --property output in question OR I will continue for answer?) – Pandya Jan 10 '15 at 12:50
  • @don_crissti Done! – Pandya Jan 10 '15 at 13:08
8

As per this suggestion, (here) commented by @don_crissti I am providing solution that worked for me.


Following is output of udevadm monitor --property while removing device (KERNEL lines are skipped and only last UDEV remove is attached below)

UDEV  [1380.287343] remove   /devices/pci0000:00/0000:00:1d.7/usb1/1-4 (usb)
ACTION=remove
BUSNUM=001
DEVNAME=/dev/bus/usb/001/013
DEVNUM=013
DEVPATH=/devices/pci0000:00/0000:00:1d.7/usb1/1-4
DEVTYPE=usb_device
ID_BUS=usb
ID_MODEL=Micromax_A74
ID_MODEL_ENC=Micromax\x20A74
ID_MODEL_ID=2008
ID_REVISION=0255
ID_SERIAL=MediaTek_Micromax_A74_0123456789ABCDEF
ID_SERIAL_SHORT=0123456789ABCDEF
ID_USB_INTERFACES=:ffff00:
ID_VENDOR=MediaTek
ID_VENDOR_ENC=MediaTek
ID_VENDOR_FROM_DATABASE=HTC (High Tech Computer Corp.)
ID_VENDOR_ID=0bb4
MAJOR=189
MINOR=12
PRODUCT=bb4/2008/255
SEQNUM=2017
SUBSYSTEM=usb
TYPE=0/0/0
USEC_INITIALIZED=446266

From above I've used Environment ID_MODEL=Micromax_A74 in my udev rule for ACTION=="remove" and now udev rule becomes:

ACTION=="remove", ENV{ID_MODEL}=="Micromax_A74", RUN+="/bin/rmdir /home/pandya/Desktop/testdir"

Now it is removing testdir by means of ACTION=="remove"

Hence, The solution is: Use suitable environment such as ID_MODEL instead of ATTR{idVendor} & ATTR{idProduct} in ACTION=="remove"

  • What an ...interesting caveat... :( Thanks udev! And thanks @Pandya :) – Michael Yoo Mar 29 '17 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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