Udev

USB 驅動器設備名稱缺少分區號

  • February 5, 2020

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 嘗試過

$$ a-z $$* 獨自的)。 當我執行 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.

`

至少可以從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,但我老了,可能有一個時髦的工具可用),格式化該分區並將數據複製回來。

引用自:https://unix.stackexchange.com/questions/565978