Home » Questions » Computers [ Ask a new question ]

What's behind the Linux disk naming convention with sdX and hdX?

What's behind the Linux disk naming convention with sdX and hdX?

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?

Asked by: Guest | Views: 347
Total answers/comments: 2
Guest [Entry]

"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."
Guest [Entry]

"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"