use*_*301 3 boot usb-drive usb device-name
我想获取(最终在systemd
脚本中)已连接的 USB 驱动器(USB 记忆棒或 SSD 驱动器)的设备名称。我怎样才能可靠地做到这一点?我们可以假设只有一个驱动器连接,但UUID
在这种情况下我们不知道它或其他任何信息。我的意思是这样的:
lsblk | grep disk | awk '{print $1}' | tail -n1
但是,我不确定 USB 驱动器是否总是该列表中的最后一个。
如果我理解正确的话,请使用available columns
oflsblk
打印 USB 的完整信息:
例如:
lsblk -p -o NAME,SERIAL,VENDOR,MODEL,TRAN | grep usb
Run Code Online (Sandbox Code Playgroud)
给出输出:
/dev/sdc 000FEA0AB9F5BA60641508A8 Kingston DT 101 G2 usb
Run Code Online (Sandbox Code Playgroud)
Available columns (for --output):
NAME device name
KNAME internal kernel device name
MAJ:MIN major:minor device number
FSTYPE filesystem type
MOUNTPOINT where the device is mounted
LABEL filesystem LABEL
UUID filesystem UUID
PARTTYPE partition type UUID
PARTLABEL partition LABEL
PARTUUID partition UUID
PARTFLAGS partition flags
RA read-ahead of the device
RO read-only device
RM removable device
HOTPLUG removable or hotplug device (usb, pcmcia, ...)
MODEL device identifier
SERIAL disk serial number
SIZE size of the device
STATE state of the device
OWNER user name
GROUP group name
MODE device node permissions
ALIGNMENT alignment offset
MIN-IO minimum I/O size
OPT-IO optimal I/O size
PHY-SEC physical sector size
LOG-SEC logical sector size
ROTA rotational device
SCHED I/O scheduler name
RQ-SIZE request queue size
TYPE device type
DISC-ALN discard alignment offset
DISC-GRAN discard granularity
DISC-MAX discard max bytes
DISC-ZERO discard zeroes data
WSAME write same max bytes
WWN unique storage identifier
RAND adds randomness
PKNAME internal parent kernel device name
HCTL Host:Channel:Target:Lun for SCSI
TRAN device transport type
SUBSYSTEMS de-duplicated chain of subsystems
REV device revision
VENDOR device vendor
Run Code Online (Sandbox Code Playgroud)