linux 通过udevadm info检测硬盘位置
我们知道,在linux 中,所有的块设备都以/dev/sd[a-z]的形式表现,如:/dev/sda,/dev/sdb,/dev/sdc等等.但是,在多硬盘中,我们只看设备设点/dev/sda,/dev/sdb是无法分清哪个设备代表是哪个实际硬盘.怎么办呢?我们可以通过检测硬件设备的总线来辨别设备节点代表的是哪个位置.
命令:udevadm info -a -p /sys/block/sda ,这条命条可以打印出设备总线的所有位置的父子关系.如(关键字高亮):
dm814x:/work$ udevadm info -a -p /sys/block/sda
Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.
looking at device '/devices/platform/omap/ti81xx-usbss/musb-hdrc.0/usb1/1-1/1-1:1.0/host1/target1:0:0/1:0:0:0/block/sda': //总线路径和子路径.子路径好像不准确会变.
KERNEL=="sda"
SUBSYSTEM=="block"
DRIVER==""
ATTR{range}=="16"
ATTR{ext_range}=="256"
ATTR{removable}=="0"//设备热插拔,0为不能,1为能. ATTR{ro}=="0"
ATTR{size}=="976773168"
ATTR{alignment_offset}=="0"
ATTR{discard_alignment}=="0"
ATTR{capability}=="50"
ATTR{stat}==" 9 26 280 90 0 0 0 0 0 90 90"
ATTR{inflight}==" 0 0"
looking a