0

Possible Duplicate:
Device names on hotswap server. (Name by port rather than insert order?)

I need a way to access the drive in sata port ?? on a hotswappable server. I was previously trying to access by a /dev/ name and find the port it belongs to but I cannot seem do that. The drives will basically be assembly lined through the server so I can not do anything drive specific (rename by uuid etc...).

I will need to be able to use hdparm and dd on the drive.

1 Answers1

0

On most modern distros, you'll have a /dev/disk directory. Inside will be a handful of other directories, each corresponding to one way to find a disk device.

Inside by-id, you'll see drives and partition "names" as made up by the kernel. Usually these names will include the disk model number and serial number. For example, a name I have on one of my systems is scsi-SATA_ST3808110AS_5LR187B2 is a SCSI (SATA) Seagate ST3808110AS with the serial number 5LR187B2.

Inside by-label, you'll see partition labels, as discussed in your earlier question. You might not have labels, and they're for partitions, not drives.

Inside by-path, you'll see path name built from the chain of devices that lead to the device. For example, I have one called pci-0000:00:1f.2-scsi-3:0:0:0 -- the fourth (counting from zero) SCSI device attached to a SCSI adapter attached to the PCI bus.

Finally, by-uuid contains the UUIDs assigned to each partition on the available drives.

All of these are simple symlinks back to the appropriate device in /dev.

If you're trying to find a device on a specific SATA port, using the device names in by-path is probably going to work for you.

Charles
  • 1,214
  • 2
  • 13
  • 22
  • Is there a way to make by-path work with hot-swapped sata drives? For some reason it works with usb, but not the sata. – Duke Silver Aug 08 '12 at 15:40
  • @DukeSilver, at least on the systems I'm working with here (CentOS 5 and 6), hot-swap drives appear correctly inside the `/dev/disk` hierarchy. The device names I gave above are hot-swap devices on that machine. – Charles Aug 08 '12 at 15:41
  • For some reason the contents of by-path do not change when I add drives to the system. Every other folder seems to change, but not by-path. Ubuntu 10.04 – Duke Silver Aug 08 '12 at 15:44
  • Hmm. Well, the node *names* in there won't change, but do the drive letters that they point at change? I'm assuming that `by-id` changes, right? Given that the names in there are generated based on the model and serial of the drive, I'd certainly hope so. You can use the combined data between the two to derive the port number for any given disk device. Don't forget that hot-swaps are likely to appear in your syslog. – Charles Aug 08 '12 at 15:51
  • (If it isn't clear, you can watch `by-id` for changes, look up the device it points to, then look in `by-path` for the name in there that points at the same device; the `by-path` name will contain the actual port number the drive is attached to, and you get the serial number of the device for free! Given that you seem to be doing something like drive testing here (assumption), having that information available to you easily may be very useful.) – Charles Aug 08 '12 at 15:53
  • the problem is that by-path list all the usb connections fine but only has 1 entry other than usb and it is 0:0:0:0 or something like that. How do I use the syslog? – Duke Silver Aug 08 '12 at 16:07
  • Found dmesg, I'm going to go see what it brings up on the server, because the usb here keeps incrementing each time I add it. (34:0:0:0, 35:0:0:0, 36:0:0:0 etc...) – Duke Silver Aug 08 '12 at 16:14
  • You can find `syslog` in /var/log. On some distros, it's called `messages` instead. `dmesg` is for *boot* messages. Same thing, really, just the others get updated. – Charles Aug 08 '12 at 16:28
  • 1
    @Charles, dmesg is for more then just boot processes. The dmesg command displays the kernel ring buffer. Basically anything the kernel wants to log. When the system boots, this has the messages from when the kernel loads, but if your system is up long enough and it is active enough the boot messages will fall out of the list to be replaced by other kernel messages. – Zoredache Aug 08 '12 at 16:35
  • So I found this sas_addr in the log and it has a pointer 0x122100000[port number] and then some more zeroes. Is this safe to use or will this number change when the system is booted/updated/changed in any way? – Duke Silver Aug 08 '12 at 16:43
  • Because once again the num:num:num:num just keeps incrementing whenever a drive changes – Duke Silver Aug 08 '12 at 16:44
  • @DukeSilver, unfortunately I'm out of suggestions. I've never actually had to do more than one hot-swap at a time to test what happens... – Charles Aug 08 '12 at 17:59
  • @Zoredache, thank you for your information, I wasn't aware of that. – Charles Aug 08 '12 at 17:59
  • That's ok you gave me a lot to work with by telling me to check the logs. For these systems I may have to hardcode the port address (0x12....) in my software until I find a more portable solution. Thank you – Duke Silver Aug 08 '12 at 18:02
  • That number even stayed the same when I used another boot disk in the machine so I think I can manage off of that. – Duke Silver Aug 08 '12 at 18:18