Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a problem with an udev-rule, that gets matched always twice when i connect my device. I wouldn't ask here if was not very sure that i made up an absolutely correct rule. I think the problem is not in the rule itself, but anyway, here is my rule:

ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="4e21", ENV{ID_FS_TYPE}=="vfat", OWNER="...me...", SYMLINK+=".../nexus", RUN+="/home/.../myscript"

Its a nexus s by google, which shall be backed up by rsync once i plug it in. This is done like that: phone gets connected and asks if it shall turn to storage mode, which i accept. Now the first problem was, that i can't use something like ACTION="add", since the device gets added by udev, while it does not yet provide the filesystem. i have to turn it in storage mode, udev triggers new events recognizing more information about the the filesystem (e.g. beeing vfat). So, to not match my rule too early, i used the fs-type environment variable. The final device-node for the phones filesystem is (in this case) "/dev/sdg" (without a number!)

Now the rule gets matched always twice, and when i monitor udev activity it says:

KERNEL[33252.434094] add      /devices/pci0000:00/0000:00:16.2/usb3/3-2 (usb)
KERNEL[33252.434722] add      /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0 (usb)
KERNEL[33252.435005] add      /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18 (scsi)
KERNEL[33252.435139] add      /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/scsi_host/host18 (scsi_host)
UDEV  [33252.448355] add      /devices/pci0000:00/0000:00:16.2/usb3/3-2 (usb)
UDEV  [33252.450621] add      /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0 (usb)
UDEV  [33252.452331] add      /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18 (scsi)
UDEV  [33252.453618] add      /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/scsi_host/host18 (scsi_host)
KERNEL[33253.434071] add      /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/target18:0:0 (scsi)
KERNEL[33253.434133] add      /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/target18:0:0/18:0:0:0 (scsi)
KERNEL[33253.434289] add      /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/target18:0:0/18:0:0:0/scsi_disk/18:0:0:0 (scsi_disk)
KERNEL[33253.434353] add      /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/target18:0:0/18:0:0:0/scsi_device/18:0:0:0 (scsi_device)
KERNEL[33253.434396] add      /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/target18:0:0/18:0:0:0/scsi_generic/sg7 (scsi_generic)
KERNEL[33253.434528] add      /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/target18:0:0/18:0:0:0/bsg/18:0:0:0 (bsg)
UDEV  [33253.435261] add      /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/target18:0:0 (scsi)
KERNEL[33253.436359] add      /devices/virtual/bdi/8:96 (bdi)
UDEV  [33253.436418] add      /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/target18:0:0/18:0:0:0 (scsi)
KERNEL[33253.437187] add      /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/target18:0:0/18:0:0:0/block/sdg (block)
UDEV  [33253.437724] add      /devices/virtual/bdi/8:96 (bdi)
UDEV  [33253.438335] add      /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/target18:0:0/18:0:0:0/scsi_disk/18:0:0:0 (scsi_disk)
KERNEL[33253.438867] change   /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/target18:0:0/18:0:0:0/block/sdg (block)
UDEV  [33253.439476] add      /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/target18:0:0/18:0:0:0/scsi_device/18:0:0:0 (scsi_device)
UDEV  [33253.440782] add      /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/target18:0:0/18:0:0:0/scsi_generic/sg7 (scsi_generic)
UDEV  [33253.441059] add      /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/target18:0:0/18:0:0:0/bsg/18:0:0:0 (bsg)
KERNEL[33253.446210] change   /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/target18:0:0/18:0:0:0/block/sdg (block)
UDEV  [33253.465723] add      /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/target18:0:0/18:0:0:0/block/sdg (block)
UDEV  [33253.489562] change   /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/target18:0:0/18:0:0:0/block/sdg (block)
UDEV  [33253.499913] change   /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/target18:0:0/18:0:0:0/block/sdg (block)

and after activating storage mode:

KERNEL[33311.201180] change   /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/target18:0:0/18:0:0:0/block/sdg (block)
KERNEL[33311.231579] change   /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/target18:0:0/18:0:0:0/block/sdg (block)
UDEV  [33315.817190] change   /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/target18:0:0/18:0:0:0/block/sdg (block)
UDEV  [33315.885089] change   /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/target18:0:0/18:0:0:0/block/sdg (block)

Without really knowing what happens in the last two lines, their resemblance makes me think it might be a problem in udev repeating some events ... here is the output of udevadm info -q all -n /dev/... :

P: /devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/target18:0:0/18:0:0:0/block/sdg
N: sdg
S: christian/nexus
S: disk/by-id/usb-Google_File-CD_Gadget_30309C8C04B300EC-0:0
S: disk/by-label/NEXUS_S
S: disk/by-path/pci-0000:00:16.2-usb-0:2:1.0-scsi-0:0:0:0
S: disk/by-uuid/829D-18DB
E: DEVLINKS=/dev/.../nexus /dev/disk/by-id/usb-Google_File-CD_Gadget_30309C8C04B300EC-0:0 /dev/disk/by-label/NEXUS_S /dev/disk/by-path/pci-0000:00:16.2-usb-0:2:1.0-scsi-0:0:0:0 /dev/disk/by-uuid/829D-18DB
E: DEVNAME=/dev/sdg
E: DEVPATH=/devices/pci0000:00/0000:00:16.2/usb3/3-2/3-2:1.0/host18/target18:0:0/18:0:0:0/block/sdg
E: DEVTYPE=disk
E: ID_BUS=usb
E: ID_FS_LABEL=NEXUS_S
E: ID_FS_LABEL_ENC=NEXUS_S
E: ID_FS_TYPE=vfat
E: ID_FS_USAGE=filesystem
E: ID_FS_UUID=829D-18DB
E: ID_FS_UUID_ENC=829D-18DB
E: ID_FS_VERSION=FAT32
E: ID_INSTANCE=0:0
E: ID_MEDIA_PLAYER=google_nexus-s
E: ID_MODEL=File-CD_Gadget
E: ID_MODEL_ENC=File-CD\x20Gadget\x20\x20
E: ID_MODEL_ID=4e21
E: ID_PATH=pci-0000:00:16.2-usb-0:2:1.0-scsi-0:0:0:0
E: ID_PATH_TAG=pci-0000_00_16_2-usb-0_2_1_0-scsi-0_0_0_0
E: ID_REVISION=0000
E: ID_SERIAL=Google_File-CD_Gadget_30309C8C04B300EC-0:0
E: ID_SERIAL_SHORT=30309C8C04B300EC
E: ID_TYPE=disk
E: ID_USB_DRIVER=usb-storage
E: ID_USB_INTERFACES=:080650:
E: ID_USB_INTERFACE_NUM=00
E: ID_VENDOR=Google
E: ID_VENDOR_ENC=Google\x20\x20
E: ID_VENDOR_ID=18d1
E: MAJOR=8
E: MINOR=96
E: SUBSYSTEM=block
E: UDEV_LOG=3
E: UDISKS_PRESENTATION_ICON_NAME=multimedia-player
E: UDISKS_PRESENTATION_NOPOLICY=0
E: USEC_INITIALIZED=33253437171

I have tried a lot of other combinations (with e.g. KERNEL=..). Now i need help. Every hint is much apreciated! If you need more output (like syslog), i'll be glad to provide it...

#

Postscriptum:

I think the problem is probably that the filesystem gets the device node for example "sdg", and not "sdg1". Other android smartphones seem to not show this problem, with an galaxy ace for ex., everything was just fine...

The output of fdisk -l /dev/sdg (with the nexus s):

Disk /dev/sdg: 14.3 GB, 14314094080 bytes
64 Köpfe, 32 Sektoren/Spur, 13650 Zylinder, zusammen 27957215 Sektoren
Einheiten = Sektoren von 1 × 512 = 512 Bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Festplattenidentifikation: 0x00000000

Gerät  boot.     Anfang        Ende     Blöcke   Id  System

and then nothingness.

Anyway, i solved this for me by creating a pidfile and let the script check for it...

share|improve this question

1 Answer 1

I think you are right with the assumption of getting two events triggered by first sdg and later sdg1. I had the same problem with an usb-memory stick.

Just add to your rule

KERNEL=="sd?[0-9]"

This will only fire for the second event. Worked well for me.

share|improve this answer

Your Answer

 
discard

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.