Monday, September 14, 2015

linux - simple udev rule not recognizing my drive by uuid


I am having difficulties having udev recognize a drive by uuid. I'll outline the problem with a simpler version of my problem.
If I try this simple rule (in /etc/udev/rules.d/50-backupdrive.rules):


ENV{ID_FS_UUID}=="8eddab0f-de61-4220-bc7f-749665c40758", RUN +="/usr/bin/logger udev rule success, drive: %k with uuid $env{ID_FS_UUID}"

and I insert my USB drive with a partition containing that uuid, I do not see the message outputted to /var/log/syslog as expected.


However, if I run the following more generic command:


KERNEL=="sd?[0-9]",RUN +="/usr/bin/logger udev rule success, drive: %k with uuid $env{ID_FS_UUID}"

I indeed do see text outputted to /var/log:



Apr 22 18:06:35 xxxxxx root: udev rule success, drive: sdd2 with uuid 8eddab0f-de61-4220-bc7f-749665c40758

This included the uuid so indeed the uuid must be correct. Also, this confirms that udev must be working as well.


Does anyone have an idea as to what may be occurring? I have searched on these forums and not found something specific to my problem :-(. Thanks!


Some more details that may help:


Running: udevadm info /dev/sdd2 returns ([...] means omitted text):



P: /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3:1.0/host12/target12:0:0/12:0:0:0/block/sdd/sdd2
N: sdd2
S: disk/by-id/ata-ST1000LM024_HN-M101MBB_S30CJ9CF767710-part2
S: disk/by-id/wwn-0x50004cf20d9dfd11-part2
S: disk/by-path/pci-0000:00:14.0-usb-0:3:1.0-scsi-0:0:0:0-part2
S: disk/by-uuid/8eddab0f-de61-4220-bc7f-749665c40758
E: DEVLINKS=/dev/disk/by-id/wwn-0x50004cf20d9dfd11-part2 /dev/disk/by-uuid/8eddab0f-de61-4220-bc7f-749665c40758 /dev/disk/by-path/pci-0000:00:14.0-usb-0:3:1.0-scsi-0:0:0:0-part2 /dev/disk/by-id/ata-ST1000LM024_HN-M101MBB_S30CJ9CF767710-part2
E: DEVNAME=/dev/sdd2
E: DEVPATH=/devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3:1.0/host12/target12:0:0/12:0:0:0/block/sdd/sdd2
E: DEVTYPE=partition
[...]
E: ID_FS_TYPE=ext4
E: ID_FS_USAGE=filesystem
E: ID_FS_UUID=8eddab0f-de61-4220-bc7f-749665c40758

Also, when I plug in my usb drive, dmesg reads:



[ 551.257166] sd 12:0:0:0: Attached scsi generic sg4 type 0
[ 551.257410] sd 12:0:0:0: [sdd] Spinning up disk...
[ 552.260087] ..ready
[ 553.264377] sd 12:0:0:0: [sdd] 1953525167 512-byte logical blocks: (1.00 TB/932 GiB)
[ 553.264382] sd 12:0:0:0: [sdd] 2048-byte physical blocks
[ 553.438972] sd 12:0:0:0: [sdd] Write Protect is off
[ 553.438979] sd 12:0:0:0: [sdd] Mode Sense: 4f 00 00 00
[ 553.439367] sd 12:0:0:0: [sdd] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[ 553.450360] sdd: sdd1 sdd2
[ 553.452429] sd 12:0:0:0: [sdd] Attached SCSI disk

Finally, fdisk -l gives:



Disk /dev/sdd: 931.5 GiB, 1000204885504 bytes, 1953525167 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 33553920 bytes
Disklabel type: dos
Disk identifier: 0x709da5d9
Device Boot Start End Sectors Size Id Type
/dev/sdd1 2048 102402047 102400000 48.8G b W95 FAT32
/dev/sdd2 102402048 1953523711 1851121664 882.7G 83 Linux

Answer



You need to have your rule run after the built-in rule which learns the UUID in the first place.


i.e. Mine was /etc/udev.rules/30-foo.rules, but changing it to "zz-foo.rules" worked like a charm because it's guaranteed to run near the end of all rules:


udevadm test /devices/pci0000:00/0000:00:16.2/usb3/3-4/3-4:1.0/host13/target13:0:0/13:0:0:0/block/sde/sde1
(snip)
run: '/usr/bin/logger udev rule success, drive: sde1 with uuid 456bBLAH-3399-4fec-a304-BLAH388e2bc3'
(snip)

Figured this out by reading
Use UUID in udev rules and mount usb drive on /media/$UUID


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...