I have a USB stick with two partitions. After plugging the stick I use the following command to find the device.
dmesg
Example output
[11195.236020] usb 2-2: new high-speed USB device number 9 using ehci-pci
[11195.375432] usb 2-2: New USB device found, idVendor=058f, idProduct=6387
[11195.375436] usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[11195.375439] usb 2-2: Product: Mass Storage
[11195.375441] usb 2-2: Manufacturer: Generic
[11195.375444] usb 2-2: SerialNumber: 605DD851
[11195.375968] usb-storage 2-2:1.0: USB Mass Storage device detected
[11195.376732] scsi host10: usb-storage 2-2:1.0
[11196.377830] scsi 10:0:0:0: Direct-Access Generic Flash Disk 8.07 PQ: 0 ANSI: 4
[11196.378159] sd 10:0:0:0: Attached scsi generic sg3 type 0
[11196.379647] sd 10:0:0:0: [sdc] 15769600 512-byte logical blocks: (8.07 GB/7.51 GiB)
[11196.381548] sd 10:0:0:0: [sdc] Write Protect is off
[11196.381552] sd 10:0:0:0: [sdc] Mode Sense: 23 00 00 00
[11196.383579] sd 10:0:0:0: [sdc] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[11196.390454] sdc: sdc1 sdc2
[11196.394696] sd 10:0:0:0: [sdc] Attached SCSI removable disk
Therefore, my device is /sdc
and my partitions /dev/sdc1
and /dev/sdc2
I used the both commands to get their UUIDs
udevadm info /dev/sdc1 | grep ID_FS_UUID=
Example output
E: ID_FS_UUID=dbf323e9-8d63-444c-9c11-76b9b9a0fed4
and
udevadm info /dev/sdc2 | grep ID_FS_UUID=
Example output
E: ID_FS_UUID=0eeb7004-8955-4358-a205-07d7376adb8c
Therefore my UUIDs are dbf323e9-8d63-444c-9c11-76b9b9a0fed4
and 0eeb7004-8955-4358-a205-07d7376adb8c
or per partition
/dev/sdc1
>> dbf323e9-8d63-444c-9c11-76b9b9a0fed4
/dev/sdc2
>> 0eeb7004-8955-4358-a205-07d7376adb8c
Now I created a file /etc/udev/rules.d/100-myusb.rules
sudo nano /etc/udev/rules.d/100-myusb.rules
and added the rule below
KERNEL=="sd??", ENV{ID_FS_UUID}=="0eeb7004-8955-4358-a205-07d7376adb8c", ENV{UDISKS_IGNORE}="1"
and restarted udev
sudo service udev restart
But after plugging the stick again, both partitions are shown in Files aka Nautilus
What I'm doing wrong?
Edit So 6. Sep 21:07:50 CEST 2015
The rule
KERNEL=="sd??", ENV{ID_FS_UUID}=="0eeb7004-8955-4358-a205-07d7376adb8c", RUN+="/bin/mkdir /tmp/folder1"
creates the folder /tmp/folder1
And for @Sneetsher
KERNEL=="sd??", ENV{ID_FS_UUID}=="0eeb7004-8955-4358-a205-07d7376adb8c", RUN+="/usr/bin/env > /tmp/udev-partition-env.log"
works, but the output file is env_root.output
? o_O
Edit Mo 7. Sep 20:31:06 CEST 2015
Tested and doesn't works
KERNEL=="sd??", ENV{ID_FS_UUID}=="0eeb7004-8955-4358-a205-07d7376adb8c", ENV{UDISKS_AUTO}="0", ENV{UDISKS_SYSTEM}="0"
and
KERNEL=="sd??", ENV{ID_FS_UUID}=="0eeb7004-8955-4358-a205-07d7376adb8c", ENV{UDISKS_AUTO}="0"
Finally, I setup same environment Ubuntu 15.04 in a VirtualBox machine.
It works as perfectly as expected.
:D I hate 3 digits prefix
100-
(common/standard is 2), So I'm using99-
's most the time. I never tried it before, renaming it to be similar to yours:Voila! Now It does not work.
The rule is overridden by other rules, pretty sure the system ones from
/lib/udev/rules.d/
You may try listing all rules files, to check:
Source:
man udev
May be this is the best way to check using
udevadm test <path>
, example:Test it for both names
100-myusb.rules
&99-myusb.rules
, you will see which order the rules files read and which rules triggered.Reference: Which udev rule triggered?