USB 驱动器设备名称缺少分区号

USB 驱动器设备名称缺少分区号

Linux 如何确定 USB 驱动器上的分区号 (/dev/sdX**#**)?

有一种品牌的 USB 驱动器在插入 Linux 时不会安装分区号。例如,它们显示为/dev/sdb代替/dev/sdb1。驱动器已格式化,我可以手动将其挂载并写入为 /dev/sdb。问题是自动挂载不起作用。我的 udev 规则用于KERNEL=="sd[a-z]*[0-9]*", SUBSYSTEMS=="usb", ACTION=="add",RUN...触发我的安装规则,但它永远不会触发(我确实仅使用 sd[az]* 尝试过)。

当我运行 blkid 时,它缺少 ID_PART 参数。

$ 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

我见过的所有其他 USB 驱动器都是这样的:

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

ID_PART 值由什么设置?是USB本身的信息还是由驱动程序生成的?该制造商是否未遵循某些规范,或者这是格式化驱动器的可接受方式吗?我想知道我是否需要投入时间来解决这个问题,或者我是否可以告诉用户我的应用程序根本不支持该驱动器,因为它是一种罕见的边缘情况。

我目前正在运行 Ubuntu 18.04 最低版本... 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,但我在所有系统上都看到过这种情况返回 Ubuntu 14 的方法。

这是我测试该驱动器使用的规则时的输出。它最后运行的内容(unshare 和 hdparm)不是我的规则的一部分。

$ 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

至少你的部分答案可以推断出来https://superuser.com/questions/1052723/format-usb-flash-drive-without-partitions

基本上,您可以直接在设备上创建文件系统,而无需创建分区表。

你问题的第二部分涉及KERNEL=="sd[a-z]*[0-9]*", SUBSYSTEMS=="usb", ACTION=="add",RUN...

你可能必须尝试一下,KERNEL=="sd[a-z]*", SUBSYSTEMS=="usb", ACTION=="add",RUN...我确信这会带来一些长期问题,但我无法立即想到它。

或者,您可以备份 USB 驱动器上的数据,创建一个带有一个分区的分区表(我会使用parted,但我老了,可能有一种更时髦的工具可用),格式化该分区并将数据复制回来。

相关内容