Disk (/dev/sd*) device names change after adding new SATA disks

Back in late 2017, I encountered the following issue in Fedora WS (I think it was version 27 then).

In my desktop PC, I had a SSD disk with 250 GB and three mechanical HDDs (each one of 1 TB)

I installed fedora in the SSD drive (250 GB). The device names were like below and it remained the same across several reboots.

[adrian@duffy ~]$ lsblk
NAME    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda       8:0    0   970G  0 disk /data1
sdb       8:16   0   970G  0 disk /data2
sdc       8:32   0   970G  0 disk /data3
sdd       8:48   0 232.9G  0 disk 
├─sdd1    8:49   0   500M  0 part /boot/efi
├─sdd2    8:50   0   1.3G  0 part /boot
├─sdd3    8:51   0   110G  0 part /home
└─sdd4    8:52   0   110G  0 part /

After a month, I purchased two new 1 TB HDDs and attached these new hard drives to the SATA ports of the motherboard. Upon reboot, all the block device names went berserk. Even the ones where Fedora OS was installed got changed (from sdd to sdf as shown below) and ended up something like below. lsblk output was showing something like below

[adrian@duffy ~]$ lsblk
NAME    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda       8:0    0   970G  0 disk            |---------> The newly attached unformatted disk
sdb       8:16   0   970G  0 disk /data1
sdc       8:32   0   970G  0 disk            |---------> The newly attached unformatted disk
sdd       8:0    0   970G  0 disk /data2
sde       8:0    0   970G  0 disk /data3
sdf       8:48   0 232.9G  0 disk 
├─sdf1    8:49   0   500M  0 part /boot/efi
├─sdf2    8:50   0   1.3G  0 part /boot
├─sdf3    8:51   0   110G  0 part /home
└─sdf4    8:52   0   110G  0 part /

Luckily /etc/fstab looks only at the UUID of a device and mounts it on the mount point specified in the file. So, it didn’t cause any real harm for me. I guess this ‘issue’ exists in Fedora even today. Its Fedora 34 at the time of writing this post (19-June-2021)

Last week, my friend who was running Chia crypto farming in Ubuntu 20.04.2.0 LTS PC faced a similair scenario and he formatted the wrong disk by mistake. And this prompted me to post this.

I have 3 questions :

Question1. Why can’t Mr Torvalds and team fix this device name/drive letter changing upon reboot issue?
I know this is not a Fedora or an Ubuntu issue, as the Linux kernel just names block devices as /dev/sda or /dev/sdb randomly in the order they are discovered. But, don’t you think it is better to have device name/drive letters persistent across reboots to avoid unwanted headaches ?

Question2. In my above example from 2017, the device names did not change for a month (across several reboots). It changed only when I attached 2 new HDDs to the motherboard’s SATA ports. Why ? What suddenly forced Linux kernel to freshly name all the SATA disks ?

Question3. Does adding /dev/sd* device names in /etc/fstab entries a recommended way to make the /dev/sd* names persistent across reboots ? Well, if this actually worked, we wouldn’t be needing to configure udev for this. Right ? :grinning:

Apologies for my first post for being a long one :slight_smile:

2 Likes

Question 1
The fix for the issue you saw was the reason for now using UUIDs on devices, since that never changes, but as you saw the /dev/sdX naming is handled in the order the OS discovers them. Way back when the naming was handled by the order in which the hardware was discovered, with a single cpu that was consistently the same. With multiple cpus and more complex hardware things are not always done in the same order. UUIDs are to address that issue.

Question 2
See the answer to question 1.
Changes in hardware force the system to search again, and not everything is found in the same order.

Question 3
Since the /dev/sdX names are not necessarily consistent across boots then NO, the sdX entry in fstab will not ensure it is handled the same every time. The /dev/sdX name is assigned before fstab is even consulted.

Filesystems in partitions can be labeled and the partition has a UUID. Those are the only way to be 100% certain a device will always be mounted the same every time. You can look in /dev/disk/by-uuid or /dev/disk/by-label to see how they are displayed. The entry in fstab with UUID=XXXXXX or LABEL=??? should always return the same device whereas /dev/sdX does not always return the same device.

Note that using UUIDs or LABELs also makes it possible to remove devices and reinstall them connected to a different port on the controller (or even a totally different controller) without breaking your system.

8 Likes

If the 4 disks you already had were connected to sata ports 3, 4, 5 and 6 on the motherboard and you connected the 2 new disks to sata ports 1 and 2 I can imagine the device names were changed.

2 Likes