LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-17-2013, 06:56 AM   #1
displace
Member
 
Registered: Jan 2013
Location: EU
Distribution: Debian
Posts: 268

Rep: Reputation: 25
Post UDEV - sata HDD always as sda - how?


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"

Last edited by displace; 09-17-2013 at 02:36 PM.
 
Old 09-17-2013, 03:22 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
The real question is why you care what the name is. Any time you have more than one disk you should be mounting by UUID in fstab.
 
Old 09-17-2013, 03:47 PM   #3
zeebra
Senior Member
 
Registered: Dec 2011
Distribution: Slackware
Posts: 1,830
Blog Entries: 17

Rep: Reputation: 638Reputation: 638Reputation: 638Reputation: 638Reputation: 638Reputation: 638
Quote:
Originally Posted by smallpond View Post
The real question is why you care what the name is. Any time you have more than one disk you should be mounting by UUID in fstab.
I second that. Use UUID!

Perhaps the name has something to do with the boot order in his BIOS?
 
Old 09-17-2013, 04:11 PM   #4
displace
Member
 
Registered: Jan 2013
Location: EU
Distribution: Debian
Posts: 268

Original Poster
Rep: Reputation: 25
Because the disks change, UUID's change too, so no unique identifiers. Also, my device has no BIOS. It would seem I will have to settle for symlinks instead. All I needed was a way to identify the port where the disk was connected to, not the disk itself. Looks like the /dev/disk/by-path/platform-sw_ahci.0-scsi-0:0:0:0 symlink will have to do. I'll need to adapt some scripts for this purpose.



I was hoping I could somehow reserve the sda device name for a specific port by using udev rules, but it would seem that what I was trying to do is impossible.

As Kay Sievers just explained to me:
Quote:
It is not possible at all, and unlikely that it will be in the future.

Udev can only add symlinks with names not clashing with the kernel
names, it can never rename the kernel device names.

Stable names are only provided by symlinks, never by the plain kernel names.
 
Old 09-17-2013, 04:27 PM   #5
zeebra
Senior Member
 
Registered: Dec 2011
Distribution: Slackware
Posts: 1,830
Blog Entries: 17

Rep: Reputation: 638Reputation: 638Reputation: 638Reputation: 638Reputation: 638Reputation: 638
Quote:
Originally Posted by displace View Post
Because the disks change, UUID's change too, so no unique identifiers. Also, my device has no BIOS. It would seem I will have to settle for symlinks instead. All I needed was a way to identify the port where the disk was connected to, not the disk itself. Looks like the /dev/disk/by-path/platform-sw_ahci.0-scsi-0:0:0:0 symlink will have to do. I'll need to adapt some scripts for this purpose.



I was hoping I could somehow reserve the sda device name for a specific port by using udev rules, but it would seem that what I was trying to do is impossible.

As Kay Sievers just explained to me:
I wouldn't think it should. That is the whole purpose of UUID, isn't it?

What about disk labels? Can that help?
 
Old 09-18-2013, 12:45 AM   #6
displace
Member
 
Registered: Jan 2013
Location: EU
Distribution: Debian
Posts: 268

Original Poster
Rep: Reputation: 25
Afaik disk labels are derived from partition names. There is no guarantee that different disks will use the same partition layout and names (labels). As I said before, the solution was to mount the disks by port (sata, usb).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] UDev rules and detecting powered up SATA HDD in 5.25 enclosure lpallard Linux - Hardware 4 01-08-2011 06:47 PM
Why is a SATA HDD listed as sda? anthonydonelly Linux - Newbie 7 10-01-2010 12:53 AM
Sata controller seen as hda and not sda B-Boy Linux - Hardware 1 02-28-2009 05:13 AM
sda-hdd-boot-problem morfeo99 Linux - General 1 03-30-2006 08:36 AM
udev likes to delete /dev/sda* but not create them :( edman007 Linux - Software 2 01-18-2005 05:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration