6

Can someone tell me what's behind the hdX and sdX naming convention for hard disks under Linux? I understand it's a "convention" but what does that mean? Does that mean, for example, that a SCSI drive must be called sdX or it won't work?

The background is that I'm mucking around with a custom linux-based OS and vmware, and so I can call the drives whatever I want. I know the convention is nice for the users, I'm just wondering if it's required by the kernel.

3 Answers 3

6

The kernel deals with two types of drives:

  • IDE drives, like old hard drives and many CD/DVD drives -- these use the name hd$x
  • SCSI drives -- these use the name sd$x

SATA, SAS, and USB drives all use the SCSI subsystem because it has certain advantages that the older IDE drivers do not have. So these controller devices are abstracted to look like SCSI controllers, containing SCSI devices, to the hosting computer.

With IDE drives, the naming convention is pretty rigid:

  • hda is the master drive on the first bus
  • hdb is the slave drive on the first bus
  • hde is the master drive on the third bus

...and so on. (And yes it's possible to have more than two IDE buses.) So when you have a CD or DVD drive on an IDE bus, it is not uncommon to see those drives hung on the second IDE bus (because that's the way it has always been done -- but that's another discussion). So it is quite possible to have hdc without having hda and hdb.

This is important to know because the SCSI subsystem is different. Drives are labelled in the order in which they are detected.

So say you had an old-school SCSI bus, and hung disks at SCSI ID 0, 3, and 5. Those drives would get detected as sda, sdb, and sdc respectively.

Now assume you've bought a fourth drive, and for reasons only known to yourself, you assign it to SCSI ID 4. This new drive now gets detected as sdc, whereas the pre-existing drive on SCSI ID 5 is now sdd. This could cause all kinds of hilarity if you are refering to partitions by absolute name -- after booting with the inserted new drive, /dev/sdc1 isn't what it used to be, you mean /dev/sdd1 now.

This is one reason why RedHat (and others) like the e2label functionality, where you assign a unique label to the partition and mount it by reference to that.

I don't know why Linux was built like this. Older-school OSs like Solaris force you to refer to the disk by SCSI address -- so /dev/dsk/c0t0d0s0 (controller 0, target (or ID) 0, disk 0 (legacy, don't ask), slice (or partition) 0) will be absolute, no matter what other disks are on the bus. It does suffer the same problem if you insert a new scsi controller, introducing a new bus ID, but that's relatively rare and most computers know to prefer their internal controllers over ones added later. The linux way can be simpler -- you don't need to know, or care about, your controller/id information. You just know it is the first, or second disk. And for most users this is true, you only have at most a couple of drives to deal with, so you don't really care what it is named as long as you can find it.

Partition numbers are something else again. The standard MS (DOS) partition table that is used on PCs has four primary partitions in it. No more, no less. They can be 0-length, and there's no need to start by defining partition 1. You can start with partition 3 if you want. I don't think they even have to be contiguous on the disk -- you can define partition 3 to start at block 0, and partition 1 to start somewhere after that. Most linux partitioning tools will write the partition tables starting with partition 1, and so on. Most linux kernels will treat an 0-length partition as an empty or non-existent partition and won't announce its existence.

If you need more partitions, you have to mark one of you primary a container for "extended" partitions. Then you can subdivide that into as many extended partitions as you like (subject to some limit which I don't know off the top of my head). The difference is that extended partitions are always enumerated by the kernel starting at partition number 5. So if you have a disk hda with two primary partitions and two extended partitions (for whatever reason), they would get enumerated as hda1, hda2, hda5, and hda6. Partition 3 would be marked as containing extended partitions and wouldn't be enumerated.

So that's a lot of words to explain the device names. It is really just to signal you that a device is a IDE or a SCSI-controlled device and to give you some idea how the device is partitioned.

Unless there's a compelling reason to do otherwise, I wouldn't mess with them. Changing them will only later confuse users who think they know what they are doing.

1
  • Note that in newer Linux versions IDE drivers also use sd?.
    – kinokijuf
    Dec 16, 2013 at 13:32
2

AFAIK all that's required by the kernel is that the device have the right major and minor device numbers.

So long as the major and minor device numbers were right, something called /dev/sda3 might NOT be the third partition of the first SCSI device on the chain (or whatever); it could actually be the Nth partition of the 2nd IDE drive instead.

Note that some supporting utility programs may or may not be happy to handle non-"standard" dev names. Every programmer has their own notion of what makes a sensible "sanity check".

1

IDE drives are prefixed with hd, while SCSI, SATA and SAS drives are prefixed with sd.

eg:

first partition on first SCSI drive:

/dev/sda1

third partition on third IDE drive:

/dev/hdc3

these prefixes are determined by Linux in the order they are attached. The device naming convention cannot be changed, although you can change the names they appear as (the label) using e2label:

e2label /dev/sdb1 /Docs
3
  • 1
    Everything that is addressed through the SCSI subsystem is usually sd*. That is why SATA drives show up as sd*. Dec 9, 2009 at 20:15
  • You're forgetting scd/sr (cdrom) and st (scsi tape). Dec 10, 2009 at 3:03
  • 2
    Now that everything is sd* named in the order it's detected, the names are basically useless, since they can change after a kernel upgrade. unlike the old hda1, hdc3. So you have to do everything by label, or by id, or something. udev sets up /dev/disk/by-/ for different names. You can use /dev/disk/by-id in /etc/fstab if you like. Dec 10, 2009 at 3:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .