Two HDDs are switching their device names in Ubuntu Linux

grigory

Member
Jan 31, 2016
41
0
66
Hello!

Not like it's a problem so far, but mostly my curiosity. I have 2 disks -- internal and external. The latter is connected via USB3 cable. My Ubuntu install is on the external drive. W10 is inside my laptop (it's a dual-boot system). So usually my internal drive is sda and my external one is sdb in Ubuntu (they're both SATA drives, of course). But today they switched their device names, so the internal became sdb and external became sda. After the reboot everything got back to normal. I personally haven't done anything in this regard. To me that's strange. Maybe someone could explain that to me, please.
 

lxskllr

No Lifer
Nov 30, 2004
57,426
7,612
126
It happens. I can't give a technical explanation, but I think it occurs at start up, when device names are assigned. It's a bad idea to rely on those when scripting recurring tasks, or making big changes to hard drives(partitioning, mass deletion...) without confirming first. Instead, uuid should be used.
 

Essence_of_War

Platinum Member
Feb 21, 2013
2,650
4
81
It happens. I can't give a technical explanation, but I think it occurs at start up, when device names are assigned.

I believe the kernel assigns device handles to the SATA ports in the order that they are initialized and presented to it, and in theory, there is no reason why they MUST have the same device label each time the system is booted.

It's a bad idea to rely on those when scripting recurring tasks, or making big changes to hard drives(partitioning, mass deletion...) without confirming first. Instead, uuid should be used.
Agree 100%.

Everything important that relies on paths to devices/volumes (GRUB, fstab, LLVM, dm-crypt/LUKS) should be using UUIDs so OP, there is no reason to worry if your SATA ports switch their initialization each time you boot. Just don't rely on the label /dev/sdX corresponding to a specific device. Rely on the UUIDs. You can check these by typing 'blkid' at a bash terminal.