== The many names of Linux SATA devices If you have SATA devices on your Linux system, the kernel gives them no less than four different names in four different namespaces (although arguably one of the namespaces is not really a kernel one). Because I recently had to deal with this, I feel like running down all of them. The four namespaces are: * Traditional _sdX_ names like _sdj_. Unless udev is playing around with them for you, these are allocated sequentially in the order that the SATA (or SCSI-like) drives are encountered. If you hotswap or hot-add a new drive, it will generally (but not always) get the next highest unused drive name. These names start from _sda_ and go up. (If you hotswapped the highest drive, it will sometimes reuse its old name.) As I have found out the hard way, there is no particular guarantee that what Linux sees as _sda_ will be either the first BIOS drive or the drive plugged into the SATA connector on your motherboard that is labeled 'SATA 1', and there is equally no guarantee that the first BIOS drive is what is plugged into 'SATA 1'. This gets [[very fun GrubBiosMapping]]. _sdX_ names also appear in sysfs as the primary name of drives, in _/sys/block_. None of the following three naming schemes for drives change if and when you hotswap a drive, unlike _sdX_ names; they are always constant. * What I will call 'SCSI host names' that look like '_sd 4:3:0:0_' or '_scsi 4:3:0:0_' (kernel messages use both forms). Note that 'host' here does not mean what you think it might mean; it is special SCSI terminology that roughly corresponds to what I would call a channel. The first number is the SCSI host (for SATA, a single port) and for SATA the second is the drive on that host. If the port doesn't have a SATA port multiplier, the second number is always 0; if it does, as we have on [[some machines LinuxISCSITargets]], it counts up for each disk reached through the port. Note that a single SATA adaptor card can have multiple ports; each port is numbered separately. (The actual definition of the numbers can be seen in _/proc/scsi/scsi_. Note that non-SATA drivers can do numbering quite differently than SATA drivers; on our Dell 2950s using the _mptsas_ driver, there is only one SCSI host, the second number is always 0, and the third number counts up for individual disks.) SCSI host numbers start from 0 and are allocated in the order the system encounters disk 'adaptors', broadly construed. They are never reused. Because USB materializes and de-materializes host adaptors as well as the hard drives themselves, on systems where you frequently insert and remove things like USB drives or camera memory cards you can get very high 'sd NN:...' numbers; my home system routinely reaches 'sd 20' (despite the actual memory card generally showing up as _sde_). These days Linux treats almost every disk as a SCSI disk regardless of the physical attachment method, so almost every disk gets a name like this. Although the kernel prints no messages about this, SCSI host numbers are allocated for all SCSI-like disk adaptor regardless of whether or not there are any disks attached to it at the time that it is seen. This means that '_scsi X_' numbers for actual disks can be non-contiguous and your first disk is not necessarily '_scsi 0:0:0:0_'. (We have machines where the disk numbering is '_sd 2:0:0:0_', '_sd 3:0:0:0_', '_sd 5:0:0:0_', '_sd 5:1:0:0_', and so on. Yes, this is fun.) Whether IDE devices are pulled into this numbering seems to vary based on the kernel version and device drivers involved. On our SunFire X2100s, Ubuntu 8.04's kernel considers them sufficiently SCSI-like devices to be enumerated this way but a stock 2.6.25.3 kernel does not. SCSI hosts more or less appear in sysfs in ((/sys/class/scsi_host)); their disks appear directly in ((/sys/class/scsi_disk)). You can also see the same information in _/proc/scsi/scsi_. Kernel messages that use SCSI host names usually also include the _sdX_ device names as well. * (s)ATA port and disk names, which look like '_ata5_' and '_ata5.03_'. Unlike SCSI host names, these are only allocated to real (s)ATA ports; USB drives and the like do not get them. The two parts of the name are the port number and the drive on the port; again, if you have no port multiplexer the drive number will always be '_00_'. Just to confuse you, ~~ATA ports are numbered starting from 1~~, unlike SCSI hosts (which start from 0). _sd 4:3:0:0_ is thus _ata5.03_, assuming that sd 0 through sd 4 are all (s)ATA devices. And yes, the Linux kernel will happily mix both sorts of names in drive error messages. SATA port multipliers themselves seem to be called '_ataN.15_' in some kernel versions. These names do not appear in sysfs at all as far as I can see; they only appear in kernel messages. Unfortunately a drive that's experiencing transient problems is sometimes only (clearly) identified by ATA disk name, especially if you're trying to pick out which drive on a port multiplier port is the one that's having problems. * Per-PCI-device names that you find in _/dev/disk/by-path_, which have the form '_pci-0000:03:00.0-scsi-2:3:0:0_'. The bit after the -scsi- has the same general meaning as in SCSI host names except that the host number is *per PCI device*, not global; several different PCI devices can have a '_-scsi-0:0:0:0_' disk. How SATA ports on your motherboard are split between PCI devices is what you could politely call extremely varied. SATA ports on actual PCI cards are usually more predictable; one card is normally one PCI device. Finding the appropriate PCI device identifier for your card is up to you. In sysfs, PCI devices hide out in the depths of _/sys/devices/pci*_ but understanding the layout (and finding your specific device) requires more understanding of PCI bus topology issues than I have. Only _sdX_ names and the per-PCI-device names appear in _/dev_, at least conveniently, and so these are your only real choices for referring to specific drive slots. (Specific physical HDs can be referred to by a number of other ways that appear in _/dev/disk_.) In our case, today we had to deal with a drive under all four names; _sdj_, _sd 4:3:0:0_, _ata5.03_, and _pci-0000:03:00.0-scsi-2:3:0:0_ are (or were) all the same drive. The first three names appeared, intermixed, in various kernel messages about retried errors and then permanent errors; the fourth name we use so that the iSCSI backend software has a stable pathname for the drive and its partitions. (In the case of the _sdj_ name, when we hot-swapped the physical HD the new version of the drive became _sdo_. None of the other three names for it changed.)