Results 1 to 2 of 2

Thread: udev rules for USB don't work for the "remove" action

  1. #1
    Join Date
    May 2006
    Beans
    133

    udev rules for USB don't work for the "remove" action

    Hello,

    I'm running Ubuntu Server Edition 10.04.1 LTS, and I'm having trouble with udev rules. I want to run a script each time I connect or remove a particular external USB drive.

    I've added a file 10-custom.rules to /etc/udev/rules.d/ containing the following line:

    Code:
    KERNEL=="sd??", SUBSYSTEM=="block", DRIVERS=="usb", ATTRS{serial}=="2HAA5201", SYMLINK+="off-site-backup", RUN+="/usr/local/share/backuppc/bin/prepare_usb.sh"
    For now, prepare_usb.sh contains just this code:
    Code:
    #!/bin/bash
    /usr/bin/touch /home/pstains/udev.test
    /bin/echo "${ACTION}" > /home/pstains/udev.test
    exit 0
    prepare_usb.sh is run (and, as a result, /home/pstains/udev.test is updated) every time I plug in the external drive, but it never runs when I unplug the drive.

    For debugging purposes, I ran the following command:

    Code:
    sudo udevadm test --action="add" /block/sdc/sdc1/
    ... which gave me a whole bunch of output, including the following line:

    Code:
    udev_rules_apply_to_event: RUN '/usr/local/share/backuppc/bin/prepare_usb.sh' /etc/udev/rules.d/10-custom.rules:2
    However, when I ran it with the action set to "remove," i.e.:
    Code:
    sudo udevadm test --action="remove" /block/sdc/sdc1/
    ... there were no udev_rules_apply_to_event lines at all in the output.

    Any thoughts on how I can rewrite my rules to match both cases? Or suggestions for getting more useful debugging info?

    Thanks,
    -Pitt

  2. #2
    Join Date
    Apr 2012
    Beans
    2

    Re: udev rules for USB don't work for the "remove" action

    Hi ,

    i am facing the same problem .

    i wrote my customized rule to mount and umount usb drive to the board.

    my mount rule is working and umount rule is not working please suggest me where i am missing.

    i have created my rule using udevadm info -a -p /sys/block/sdb

    Thanks,
    nagaraju.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •