Hello,
I'm having some trouble with device names on Cubieboard - the device has a SATA port and two USB 2.0 host ports. When a HDD is connected via the SATA port it appears as /dev/sda. When I connect an extra USB flash key it appears as /dev/sdb. But when cubieboard boots with both devices attached (it boots from a sd-card), the device names switch - usb is now sda, and the disk is sdb.
Is there a way to make the SATA disk always appear as /dev/sda (with a
catch*)? I read this can be done with appropriate udev rules. I'm writing my own udev rules for the first time, so I'm having some trouble understanding them, and I don't want the rule to interfere with other devices. There is only one sata port and therefore only one scsi disk. Unfortunately, there's a
catch* - the HDD is going to be replaced regularly, so no unique disk identifiers are allowed. All other devices should start at sdb, sdc, sdd, etc even when the SATA HDD is not connected.
The disk symlink also appears:
/dev/disk/by-path/platform-sw_ahci.0-scsi-0:0:0:0
/dev/disk/by-path/platform-sw_ahci.0-scsi-0:0:0:0-part1
And the usb key:
/dev/disk/by-path/platform-sw-ehci.1-usb-0:1:1.0-scsi-0:0:0:0
/dev/disk/by-path/platform-sw-ehci.1-usb-0:1:1.0-scsi-0:0:0:0-part1
Here's the udev info when there's only SATA disk attached.
Code:
root@cubie:/lib/udev/rules.d# udevadm info -a -n /dev/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/sw_ahci.0/ata1/host0/target0:0:0/0:0:0:0/block/sda':
KERNEL=="sda"
SUBSYSTEM=="block"
DRIVER==""
ATTR{ro}=="0"
ATTR{size}=="312581808"
ATTR{stat}==" 336 3 2778 1270 5 1 48 60 0 830 1330"
ATTR{range}=="16"
ATTR{discard_alignment}=="0"
ATTR{events}==""
ATTR{ext_range}=="256"
ATTR{events_poll_msecs}=="-1"
ATTR{alignment_offset}=="0"
ATTR{inflight}==" 0 0"
ATTR{removable}=="0"
ATTR{capability}=="50"
ATTR{events_async}==""
looking at parent device '/devices/platform/sw_ahci.0/ata1/host0/target0:0:0/0:0:0:0':
KERNELS=="0:0:0:0"
SUBSYSTEMS=="scsi"
DRIVERS=="sd"
ATTRS{rev}=="04.0"
ATTRS{type}=="0"
ATTRS{scsi_level}=="6"
ATTRS{model}=="WDC WD1600BEVS-2"
ATTRS{state}=="running"
ATTRS{unload_heads}=="0"
ATTRS{queue_type}=="simple"
ATTRS{iodone_cnt}=="0x17f"
ATTRS{iorequest_cnt}=="0x17f"
ATTRS{queue_ramp_up_period}=="120000"
ATTRS{timeout}=="30"
ATTRS{evt_media_change}=="0"
ATTRS{ioerr_cnt}=="0x1"
ATTRS{queue_depth}=="31"
ATTRS{vendor}=="ATA "
ATTRS{device_blocked}=="0"
ATTRS{iocounterbits}=="32"
looking at parent device '/devices/platform/sw_ahci.0/ata1/host0/target0:0:0':
KERNELS=="target0:0:0"
SUBSYSTEMS=="scsi"
DRIVERS==""
looking at parent device '/devices/platform/sw_ahci.0/ata1/host0':
KERNELS=="host0"
SUBSYSTEMS=="scsi"
DRIVERS==""
looking at parent device '/devices/platform/sw_ahci.0/ata1':
KERNELS=="ata1"
SUBSYSTEMS==""
DRIVERS==""
looking at parent device '/devices/platform/sw_ahci.0':
KERNELS=="sw_ahci.0"
SUBSYSTEMS=="platform"
DRIVERS=="sw_ahci"
looking at parent device '/devices/platform':
KERNELS=="platform"
SUBSYSTEMS==""
DRIVERS==""
And here it is again when there is another HDD attached to USB. The SATA disk gets renamed to sdb:
Code:
root@cubie:/var/log# udevadm info -a -n /dev/sdb
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/sw_ahci.0/ata1/host1/target1:0:0/1:0:0:0/block/sdb':
KERNEL=="sdb"
SUBSYSTEM=="block"
DRIVER==""
ATTR{ro}=="0"
ATTR{size}=="312581808"
ATTR{stat}==" 336 3 2778 1140 8 36 352 60 0 910 1200"
ATTR{range}=="16"
ATTR{discard_alignment}=="0"
ATTR{events}==""
ATTR{ext_range}=="256"
ATTR{events_poll_msecs}=="-1"
ATTR{alignment_offset}=="0"
ATTR{inflight}==" 0 0"
ATTR{removable}=="0"
ATTR{capability}=="50"
ATTR{events_async}==""
looking at parent device '/devices/platform/sw_ahci.0/ata1/host1/target1:0:0/1:0:0:0':
KERNELS=="1:0:0:0"
SUBSYSTEMS=="scsi"
DRIVERS=="sd"
ATTRS{rev}=="04.0"
ATTRS{type}=="0"
ATTRS{scsi_level}=="6"
ATTRS{model}=="WDC WD1600BEVS-2"
ATTRS{state}=="running"
ATTRS{unload_heads}=="0"
ATTRS{queue_type}=="simple"
ATTRS{iodone_cnt}=="0x182"
ATTRS{iorequest_cnt}=="0x182"
ATTRS{queue_ramp_up_period}=="120000"
ATTRS{timeout}=="30"
ATTRS{evt_media_change}=="0"
ATTRS{ioerr_cnt}=="0x1"
ATTRS{queue_depth}=="31"
ATTRS{vendor}=="ATA "
ATTRS{device_blocked}=="0"
ATTRS{iocounterbits}=="32"
looking at parent device '/devices/platform/sw_ahci.0/ata1/host1/target1:0:0':
KERNELS=="target1:0:0"
SUBSYSTEMS=="scsi"
DRIVERS==""
looking at parent device '/devices/platform/sw_ahci.0/ata1/host1':
KERNELS=="host1"
SUBSYSTEMS=="scsi"
DRIVERS==""
looking at parent device '/devices/platform/sw_ahci.0/ata1':
KERNELS=="ata1"
SUBSYSTEMS==""
DRIVERS==""
looking at parent device '/devices/platform/sw_ahci.0':
KERNELS=="sw_ahci.0"
SUBSYSTEMS=="platform"
DRIVERS=="sw_ahci"
looking at parent device '/devices/platform':
KERNELS=="platform"
SUBSYSTEMS==""
DRIVERS==""
How to create a rule match for the sata port? I've checked the dmesg, and it shows that the USB driver loads first. Afterwards the sata driver loads. I'm guessing this is the reason that the USB disk gets placed as /dev/sda. I tried a rule like this, but it doesn't work because the kernel subsystem changes too.
Code:
KERNEL=="sd[a-z]", SUBSYSTEM=="block", KERNELS=="0:0:0:0", SUBSYSTEMS=="scsi", NAME="sda"