share
Unix & LinuxI cannot create symlink for USB mobile hard disk using udev
[0] [1] chrismayo
[2020-04-15 08:47:30]
[ ubuntu udev hot-plug ]
[ https://unix.stackexchange.com/questions/580171/i-cannot-create-symlink-for-usb-mobile-hard-disk-using-udev ]

I have a problem on use udev: I want to realize USB hot plug on Ubuntu16.04, so I wrote a udev rule as follow:

KERNEL=="sd[a-z]*", ACTION=="add",SUBSYSTEM=="block",SYMLINK+="USB",RUN+="/bin/sh /root/load_device.sh %k"

When I use a USB stick, it works, and the symlink /dev/USB direct to /dev/sda1 or /dev/sdb1,2,3 ...

But, when I use a USB mobile hard disk, the /dev/USB direct to /dev/sdb, or /dev/sdc, but not to the partition. I test the rules trigger sequence, and it does trigger 2 times, first sdb, second is sdb1.

Why does the /dev/USB link point to sdb and not sdb1?

This is the system log:

Apr 16 09:28:40 ntfs-3g[1928]: Version 2015.3.14AR.1 integrated FUSE 28 Apr 16 09:28:40 ntfs-3g[1928]: Mounted /dev/sdb1 (Read-Write, label "BOOTCAMP", NTFS 3.1)
Apr 16 09:28:40 ntfs-3g[1928]: Cmdline options: rw Apr 16 09:28:40 ntfs-3g[1928]: Mount options: rw,allow_other,nonempty,relatime,fsname=/dev/sdb1,blkdev,blksize=4096
Apr 16 09:28:40 ntfs-3g[1928]: Ownership and permissions disabled, configuration type 7
Apr 16 09:28:40 systemd[1029]: dev-USB.device: Dev dev-USB.device appeared twice with different sysfs paths /sys/devices/pci0000:00/0000:00:15.0/usb2/2-4/2-4:1.0/host2/target2:0:0/2:0:0:0/block/sdb and /sys/devices/pci0000:00/0000:00:15.0/usb2/2-4/2-4:1.0/host2/target2:0:0/2:0:0:0/block/sdb/sdb1
Apr 16 09:28:40 systemd[869]: dev-USB.device: Dev dev-USB.device appeared twice with different sysfs paths /sys/devices/pci0000:00/0000:00:15.0/usb2/2-4/2-4:1.0/host2/target2:0:0/2:0:0:0/block/sdb and /sys/devices/pci0000:00/0000:00:15.0/usb2/2-4/2-4:1.0/host2/target2:0:0/2:0:0:0/block/sdb/sdb1
Apr 16 09:28:40 systemd[1]: dev-USB.device: Dev dev-USB.device appeared twice with different sysfs paths /sys/devices/pci0000:00/0000:00:15.0/usb2/2-4/2-4:1.0/host2/target2:0:0/2:0:0:0/block/sdb and /sys/devices/pci0000:00/0000:00:15.0/usb2/2-4/2-4:1.0/host2/target2:0:0/2:0:0:0/block/sdb/sdb1

This is udevinfo:

P: /devices/pci0000:00/0000:00:15.0/usb2/2-4/2-4:1.0/host3/target3:0:0/3:0:0:0/block/sdc
N: sdc
S: USB
S: disk/by-id/ata-Samsung_SSD_840_EVO_120GB_S1D5NSBF494918T
S: disk/by-id/wwn-0x50025388a03b9a88
S: disk/by-path/pci-0000:00:15.0-usb-0:4:1.0-scsi-0:0:0:0
E: DEVLINKS=/dev/disk/by-id/ata-Samsung_SSD_840_EVO_120GB_S1D5NSBF494918T /dev/disk/by-id/wwn-0x50025388a03b9a88 /dev/disk/by-path/pci-0000:00:15.0-usb-0:4:1.0-scsi-0:0:0:0 /dev/USB
E: DEVNAME=/dev/sdc E: DEVPATH=/devices/pci0000:00/0000:00:15.0/usb2/2-4/2-4:1.0/host3/target3:0:0/3:0:0:0/block/sdc
E: DEVTYPE=disk
E: ID_ATA=1
E: ID_ATA_DOWNLOAD_MICROCODE=1
E: ID_ATA_FEATURE_SET_HPA=1
E: ID_ATA_FEATURE_SET_HPA_ENABLED=1
E: ID_ATA_FEATURE_SET_PM=1
E: ID_ATA_FEATURE_SET_PM_ENABLED=1
E: ID_ATA_FEATURE_SET_SECURITY=1
E: ID_ATA_FEATURE_SET_SECURITY_ENABLED=0
E: ID_ATA_FEATURE_SET_SECURITY_ENHANCED_ERASE_UNIT_MIN=8
E: ID_ATA_FEATURE_SET_SECURITY_ERASE_UNIT_MIN=2
E: ID_ATA_FEATURE_SET_SMART=1
E: ID_ATA_FEATURE_SET_SMART_ENABLED=1
E: ID_ATA_ROTATION_RATE_RPM=0
E: ID_ATA_SATA=1
E: ID_ATA_SATA_SIGNAL_RATE_GEN1=1
E: ID_ATA_SATA_SIGNAL_RATE_GEN2=1
E: ID_ATA_WRITE_CACHE=1
E: ID_ATA_WRITE_CACHE_ENABLED=1
E: ID_BUS=ata
E: ID_MODEL=Samsung_SSD_840_EVO_120GB
E: ID_MODEL_ENC=Samsung\x20SSD\x20840\x20EVO\x20120GB\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20
E: ID_PART_TABLE_TYPE=dos
E: ID_PART_TABLE_UUID=5be6511f
E: ID_PATH=pci-0000:00:15.0-usb-0:4:1.0-scsi-0:0:0:0
E: ID_PATH_TAG=pci-0000_00_15_0-usb-0_4_1_0-scsi-0_0_0_0
E: ID_REVISION=EXT0BB6Q
E: ID_SERIAL=Samsung_SSD_840_EVO_120GB_S1D5NSBF494918T
E: ID_SERIAL_SHORT=S1D5NSBF494918T
E: ID_TYPE=disk
E: ID_WWN=0x50025388a03b9a88
E: ID_WWN_WITH_EXTENSION=0x50025388a03b9a88
E: MAJOR=8
E: MINOR=32
E: SUBSYSTEM=block
E: TAGS=:systemd:
E: USEC_INITIALIZED=1066199633

when i try KERNEL=="sd[a-z][1-9]", it cannot create symlink /dev/USB

Apr 18 01:35:31  kernel: [ 1059.884210] usb 2-4: new SuperSpeed USB device number 9 using xhci_hcd
Apr 18 01:35:31  kernel: [ 1059.909016] usb 2-4: New USB device found, idVendor=152d, idProduct=9561
Apr 18 01:35:31  kernel: [ 1059.909021] usb 2-4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Apr 18 01:35:31  kernel: [ 1059.909023] usb 2-4: Product: Fanxiang P101/240GB
Apr 18 01:35:31  kernel: [ 1059.909025] usb 2-4: Manufacturer: Fanxiang P101/240GB
Apr 18 01:35:31  kernel: [ 1059.909026] usb 2-4: SerialNumber: 000000000443
Apr 18 01:35:31  kernel: [ 1059.914003] scsi host2: uas
Apr 18 01:35:31  mtp-probe: checking bus 2, device 9: "/sys/devices/pci0000:00/0000:00:15.0/usb2/2-4"
Apr 18 01:35:31  mtp-probe: bus: 2, device: 9 was not an MTP device
Apr 18 01:35:31  kernel: [ 1059.916507] scsi 2:0:0:0: Direct-Access     Fanxiang P101/240GB       1508 PQ: 0 ANSI: 6
Apr 18 01:35:31  kernel: [ 1059.917452] sd 2:0:0:0: Attached scsi generic sg1 type 0
Apr 18 01:35:32  kernel: [ 1060.658766] sd 2:0:0:0: [sdb] 468862128 512-byte logical blocks: (240 GB/224 GiB)
Apr 18 01:35:32  kernel: [ 1060.658770] sd 2:0:0:0: [sdb] 4096-byte physical blocks
Apr 18 01:35:32  kernel: [ 1060.659275] sd 2:0:0:0: [sdb] Write Protect is off
Apr 18 01:35:32  kernel: [ 1060.659280] sd 2:0:0:0: [sdb] Mode Sense: 53 00 00 08
Apr 18 01:35:32  kernel: [ 1060.659617] sd 2:0:0:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
Apr 18 01:35:32  kernel: [ 1060.667689]  sdb: sdb1
Apr 18 01:35:32  kernel: [ 1060.669525] sd 2:0:0:0: [sdb] Attached SCSI disk
Apr 18 01:35:33  ntfs-3g[2768]: Version 2015.3.14AR.1 integrated FUSE 28
Apr 18 01:35:33  ntfs-3g[2768]: Mounted /dev/sdb1 (Read-Write, label "longtian", NTFS 3.1)
Apr 18 01:35:33  ntfs-3g[2768]: Cmdline options: rw
Apr 18 01:35:33  ntfs-3g[2768]: Mount options: rw,allow_other,nonempty,relatime,fsname=/dev/sdb1,blkdev,blksize=4096
Apr 18 01:35:33  ntfs-3g[2768]: Ownership and permissions disabled, configuration type 7
Welcome to the site. In order to help you figure out the problem, we would need more information (e.g. an excerpt of the system log for the events, or the output of udevadm monitor ...). Also, what does the load_device.sh script do? - AdminBee
Thank you for your reply, i am trying to post the log and udevadm monitor to you - chrismayo
Thank you. If you do, please edit your question rather than posting that information as a comment; it is much easier to read that way. - AdminBee
Could it be that the hard drive per se and the partition on it have the same filesystem label? I'm wondering because of the Dev <...> appeared twice message. - AdminBee
i try another hard disk, it show same message - chrismayo
[0] [2020-04-16 11:52:16] AdminBee

Leaving aside the effort to solve the mystery of the different behaviour for USB stick and hard drive, you could try to make the udev rule specific so it can only apply to partitions, i.e. device identifiers ending in a number, by specifying

KERNEL=="sd[a-z][1-9]"

as condition.


i try this, but it not works, the usb device cannot work too,and the system log i have posted to my question, thank you very much - chrismayo
1