0

How does Linux determine the partition number on USB drives (/dev/sdX**#**)?

There is a brand of USB drives that when inserted into Linux don't install with a partition number. For example, they show up as /dev/sdb instead of /dev/sdb1. The drive is formatted, and I can manually mount and write to it as /dev/sdb. The problem is that automounting doesn't work. My udev rule uses KERNEL=="sd[a-z]*[0-9]*", SUBSYSTEMS=="usb", ACTION=="add",RUN... to trigger my mounting rule, that never triggers (and I did try it with just sd[a-z]* alone).

When I run blkid, it's missing the ID_PART parameters.

$ sudo blkid -o udev -p /dev/sdb
ID_FS_UUID=EED9-8A61
ID_FS_UUID_ENC=EED9-8A61
ID_FS_VERSION=FAT32
ID_FS_TYPE=vfat
ID_FS_USAGE=filesystem

All other USB drives I've seen look like this:

ID_FS_UUID=932A-E6F0
ID_FS_UUID_ENC=932A-E6F0
ID_FS_VERSION=FAT32
ID_FS_TYPE=vfat
ID_FS_USAGE=filesystem
ID_PART_ENTRY_SCHEME=dos
ID_PART_ENTRY_TYPE=0xc
ID_PART_ENTRY_NUMBER=1
ID_PART_ENTRY_OFFSET=32
ID_PART_ENTRY_SIZE=30031840
ID_PART_ENTRY_DISK=8:16

What sets the ID_PART values? Is it information on the USB itself or is it generated by the driver? Is this manufacturer not following some specification or is this an acceptable way of formatting a drive? I'd like to know if I need to invest time in working around this or if I can tell a user that the drive simply isn't supported by my application because its such a rare edge case.

I'm currently running Ubuntu 18.04 minimum... Linux 4.15.0-70-generic #79-Ubuntu SMP Tue Nov 12 10:36:11 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux, but I've seen this on systems all the way back to Ubuntu 14.

Here's the output when I test the rules used for this drive. The stuff it runs at the end (unshare & hdparm) is not part of my rules.

$ sudo udevadm test $(sudo udevadm info -q path -n /dev/sdb)
calling: test
version 237
This program is for debugging only, it does not run any program
specified by a RUN key. It may show incorrect results, because
some values may be different, or not available at a simulation run.

Load module index
Parsed configuration file /lib/systemd/network/99-default.link
Created link configuration context.
Reading rules file: /lib/udev/rules.d/39-usbmuxd.rules
Reading rules file: /lib/udev/rules.d/40-usb_modeswitch.rules
Reading rules file: /lib/udev/rules.d/40-vm-hotadd.rules
Reading rules file: /lib/udev/rules.d/50-apport.rules
Reading rules file: /lib/udev/rules.d/50-firmware.rules
Reading rules file: /lib/udev/rules.d/50-udev-default.rules
Reading rules file: /lib/udev/rules.d/55-dm.rules
Reading rules file: /lib/udev/rules.d/55-ippusbxd.rules
Reading rules file: /lib/udev/rules.d/60-block.rules
Reading rules file: /lib/udev/rules.d/60-cdrom_id.rules
Reading rules file: /lib/udev/rules.d/60-crda.rules
Reading rules file: /lib/udev/rules.d/60-drm.rules
Reading rules file: /lib/udev/rules.d/60-evdev.rules
Reading rules file: /lib/udev/rules.d/60-gnupg2.rules
Reading rules file: /lib/udev/rules.d/60-input-id.rules
Reading rules file: /lib/udev/rules.d/60-libgphoto2-6.rules
Reading rules file: /lib/udev/rules.d/60-libsane1.rules
Reading rules file: /lib/udev/rules.d/60-persistent-alsa.rules
Reading rules file: /lib/udev/rules.d/60-persistent-input.rules
Reading rules file: /lib/udev/rules.d/60-persistent-storage-dm.rules
Reading rules file: /lib/udev/rules.d/60-persistent-storage-tape.rules
Reading rules file: /lib/udev/rules.d/60-persistent-storage.rules
Reading rules file: /lib/udev/rules.d/60-persistent-v4l.rules
Reading rules file: /lib/udev/rules.d/60-sensor.rules
Reading rules file: /lib/udev/rules.d/60-serial.rules
Reading rules file: /lib/udev/rules.d/61-gnome-settings-daemon-rfkill.rules
Reading rules file: /lib/udev/rules.d/61-persistent-storage-android.rules
Reading rules file: /lib/udev/rules.d/64-btrfs.rules
Reading rules file: /lib/udev/rules.d/64-xorg-xkb.rules
Reading rules file: /lib/udev/rules.d/65-libwacom.rules
Reading rules file: /lib/udev/rules.d/66-snapd-autoimport.rules
Reading rules file: /lib/udev/rules.d/69-cd-sensors.rules
Reading rules file: /lib/udev/rules.d/69-libmtp.rules
Reading rules file: /lib/udev/rules.d/69-wacom.rules
Reading rules file: /lib/udev/rules.d/70-joystick.rules
Reading rules file: /lib/udev/rules.d/70-mouse.rules
Reading rules file: /lib/udev/rules.d/70-power-switch.rules
Reading rules file: /lib/udev/rules.d/70-printers.rules
Reading rules file: /lib/udev/rules.d/70-touchpad.rules
Reading rules file: /lib/udev/rules.d/70-uaccess.rules
Reading rules file: /lib/udev/rules.d/71-power-switch-proliant.rules
Reading rules file: /lib/udev/rules.d/71-seat.rules
Reading rules file: /lib/udev/rules.d/73-seat-late.rules
Reading rules file: /lib/udev/rules.d/73-special-net-names.rules
Reading rules file: /lib/udev/rules.d/73-usb-net-by-mac.rules
Reading rules file: /lib/udev/rules.d/75-net-description.rules
Reading rules file: /lib/udev/rules.d/75-probe_mtd.rules
Reading rules file: /lib/udev/rules.d/77-mm-cinterion-port-types.rules
Reading rules file: /lib/udev/rules.d/77-mm-dell-port-types.rules
Reading rules file: /lib/udev/rules.d/77-mm-ericsson-mbm.rules
Reading rules file: /lib/udev/rules.d/77-mm-fibocom-port-types.rules
Reading rules file: /lib/udev/rules.d/77-mm-haier-port-types.rules
Reading rules file: /lib/udev/rules.d/77-mm-huawei-net-port-types.rules
Reading rules file: /lib/udev/rules.d/77-mm-longcheer-port-types.rules
Reading rules file: /lib/udev/rules.d/77-mm-mtk-port-types.rules
Reading rules file: /lib/udev/rules.d/77-mm-nokia-port-types.rules
Reading rules file: /lib/udev/rules.d/77-mm-pcmcia-device-blacklist.rules
Reading rules file: /lib/udev/rules.d/77-mm-qdl-device-blacklist.rules
Reading rules file: /lib/udev/rules.d/77-mm-sierra.rules
Reading rules file: /lib/udev/rules.d/77-mm-simtech-port-types.rules
Reading rules file: /lib/udev/rules.d/77-mm-telit-port-types.rules
Reading rules file: /lib/udev/rules.d/77-mm-ublox-port-types.rules
Reading rules file: /lib/udev/rules.d/77-mm-usb-device-blacklist.rules
Reading rules file: /lib/udev/rules.d/77-mm-usb-serial-adapters-greylist.rules
Reading rules file: /lib/udev/rules.d/77-mm-x22x-port-types.rules
Reading rules file: /lib/udev/rules.d/77-mm-zte-port-types.rules
Reading rules file: /lib/udev/rules.d/78-graphics-card.rules
Reading rules file: /lib/udev/rules.d/78-sound-card.rules
Reading rules file: /lib/udev/rules.d/80-debian-compat.rules
Reading rules file: /lib/udev/rules.d/80-drivers.rules
Reading rules file: /lib/udev/rules.d/80-iio-sensor-proxy.rules
Reading rules file: /lib/udev/rules.d/80-libinput-device-groups.rules
Reading rules file: /lib/udev/rules.d/80-mm-candidate.rules
Reading rules file: /lib/udev/rules.d/80-net-setup-link.rules
Reading rules file: /lib/udev/rules.d/80-udisks2.rules
Reading rules file: /lib/udev/rules.d/84-nm-drivers.rules
Reading rules file: /lib/udev/rules.d/85-hdparm.rules
Reading rules file: /lib/udev/rules.d/85-nm-unmanaged.rules
Reading rules file: /lib/udev/rules.d/85-regulatory.rules
Reading rules file: /lib/udev/rules.d/90-console-setup.rules
Reading rules file: /lib/udev/rules.d/90-libinput-model-quirks.rules
Reading rules file: /lib/udev/rules.d/90-pulseaudio.rules
Reading rules file: /lib/udev/rules.d/95-cd-devices.rules
Reading rules file: /lib/udev/rules.d/95-dm-notify.rules
Reading rules file: /lib/udev/rules.d/95-upower-csr.rules
Reading rules file: /lib/udev/rules.d/95-upower-hid.rules
Reading rules file: /lib/udev/rules.d/95-upower-wup.rules
Reading rules file: /lib/udev/rules.d/97-hid2hci.rules
Reading rules file: /etc/udev/rules.d/99-automount-usb.rules
Reading rules file: /lib/udev/rules.d/99-systemd.rules
rules contain 393216 bytes tokens (32768 * 12 bytes), 32795 bytes strings
24061 strings (201804 bytes), 21012 de-duplicated (172059 bytes), 3050 trie nodes used
GROUP 6 /lib/udev/rules.d/50-udev-default.rules:56
IMPORT builtin 'usb_id' /lib/udev/rules.d/60-persistent-storage.rules:47
/sys/devices/pci0000:00/0000:00:15.0/usb1/1-4/1-4:1.0: if_class 8 protocol 6
LINK 'disk/by-id/usb-General_UDisk-0:0' /lib/udev/rules.d/60-persistent-storage.rules:52
IMPORT builtin 'path_id' /lib/udev/rules.d/60-persistent-storage.rules:73
LINK 'disk/by-path/pci-0000:00:15.0-usb-0:4:1.0-scsi-0:0:0:0' /lib/udev/rules.d/60-persistent-storage.rules:75
IMPORT builtin 'blkid' /lib/udev/rules.d/60-persistent-storage.rules:90
probe /dev/sdb raid offset=0
LINK 'disk/by-uuid/EED9-8A61' /lib/udev/rules.d/60-persistent-storage.rules:93
RUN '/usr/bin/unshare -m /usr/bin/snap auto-import --mount=/dev/%k' /lib/udev/rules.d/66-snapd-autoimport.rules:3
RUN '/lib/udev/hdparm' /lib/udev/rules.d/85-hdparm.rules:1
handling device node '/dev/sdb', devnum=b8:16, mode=0660, uid=0, gid=6
preserve permissions /dev/sdb, 060660, uid=0, gid=6
preserve already existing symlink '/dev/block/8:16' to '../sdb'
found 'b8:16' claiming '/run/udev/links/\x2fdisk\x2fby-id\x2fusb-General_UDisk-0:0'
creating link '/dev/disk/by-id/usb-General_UDisk-0:0' to '/dev/sdb'
preserve already existing symlink '/dev/disk/by-id/usb-General_UDisk-0:0' to '../../sdb'
found 'b8:16' claiming '/run/udev/links/\x2fdisk\x2fby-path\x2fpci-0000:00:15.0-usb-0:4:1.0-scsi-0:0:0:0'
creating link '/dev/disk/by-path/pci-0000:00:15.0-usb-0:4:1.0-scsi-0:0:0:0' to '/dev/sdb'
preserve already existing symlink '/dev/disk/by-path/pci-0000:00:15.0-usb-0:4:1.0-scsi-0:0:0:0' to '../../sdb'
found 'b8:16' claiming '/run/udev/links/\x2fdisk\x2fby-uuid\x2fEED9-8A61'
creating link '/dev/disk/by-uuid/EED9-8A61' to '/dev/sdb'
preserve already existing symlink '/dev/disk/by-uuid/EED9-8A61' to '../../sdb'
ACTION=add
DEVLINKS=/dev/disk/by-uuid/EED9-8A61 /dev/disk/by-id/usb-General_UDisk-0:0 /dev/disk/by-path/pci-0000:00:15.0-usb-0:4:1.0-scsi-0:0:0:0
DEVNAME=/dev/sdb
DEVPATH=/devices/pci0000:00/0000:00:15.0/usb1/1-4/1-4:1.0/host2/target2:0:0/2:0:0:0/block/sdb
DEVTYPE=disk
ID_BUS=usb
ID_FS_TYPE=vfat
ID_FS_USAGE=filesystem
ID_FS_UUID=EED9-8A61
ID_FS_UUID_ENC=EED9-8A61
ID_FS_VERSION=FAT32
ID_INSTANCE=0:0
ID_MODEL=UDisk
ID_MODEL_ENC=UDisk\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20
ID_MODEL_ID=1234
ID_PATH=pci-0000:00:15.0-usb-0:4:1.0-scsi-0:0:0:0
ID_PATH_TAG=pci-0000_00_15_0-usb-0_4_1_0-scsi-0_0_0_0
ID_REVISION=5.00
ID_SERIAL=General_UDisk-0:0
ID_TYPE=disk
ID_USB_DRIVER=usb-storage
ID_USB_INTERFACES=:080650:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=General
ID_VENDOR_ENC=General\x20
ID_VENDOR_ID=abcd
MAJOR=8
MINOR=16
SUBSYSTEM=block
TAGS=:systemd:
USEC_INITIALIZED=1863301153
run: '/usr/bin/unshare -m /usr/bin/snap auto-import --mount=/dev/sdb'
run: '/lib/udev/hdparm'
Unload module index
Unloaded link configuration context.

`

1

At least part of your answer can be inferred from https://superuser.com/questions/1052723/format-usb-flash-drive-without-partitions

Basically you can create a filesystem directly on a device without creating a partition table.

The second part of your question, relating to KERNEL=="sd[a-z]*[0-9]*", SUBSYSTEMS=="usb", ACTION=="add",RUN...

Is that you'll probably have to try KERNEL=="sd[a-z]*", SUBSYSTEMS=="usb", ACTION=="add",RUN... I'm sure there's some longer term problem with that, but I can't think of it off the top of my head.

Alternately you can backup the data on the USB drive, create a partition table (I would used parted for that, but I'm old and there may be a hipper tool available) with one partition, format that partition and copy the data back.

| improve this answer | |
  • In a nutshell: The device number suffix is inferred from the partition number according to the partition table. No partition table results in device names without numbers suffixes. – Hermann Feb 5 at 20:59
  • I thought I had tried sd[a-z]*, but apparently not... when I tried it again it works. I thought * is supposed to match "0 or more", so its annoying that it doesn't. You'd think "sd[a-z]*[0-9]*" would match sd & sda & sd1 & sda1. – Ed K Feb 5 at 21:05
  • Sorry, I misread your initial post where you'd said you tried it. And no, I wouldn't expect sd[a-z]*[0-9]*" to match sd without numbers--it's globbing, not RE. – Petro Feb 6 at 0:09
  • Well, it's a good thing you did misread it, because it made me retry it. :-) I was driven astray by this site that says * - match any character, zero or more times and I didn't think globbing was that different from RE. I suppose I should have just used sd* like the site shows in examples. – Ed K Feb 6 at 14:14
  • D'oh, I just realized my misunderstanding about glob vs RE, lol. [a-z] is independent of *... – Ed K Feb 6 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.