My main ssd is sdb while my backup ssd is sda. I want my main ssd to be on sda and my backup on sdb. How do I control this? What determine sda, sdb or sdc? Is it the plug its on or the order of installation? How can I identify them so I am sure not to get them confused?
As a preliminary: the "sd" of /dev/sda naming is derived from "scsi disk" or "scsi drive" which came to be used in device names after "hd" of /dev/hda (for "hard disk" or "hard drive"), was changed years ago when the kernel software was changed to make everything look like a scsi disk. Check out the libata software if interested.
To the actual issue, here are some notes from the linux-scsi mailing list in my notes:
Beginning with kernel 5.3 the order in which SCSI devices (which includes HDDs)
are probed and named has become non-deterministic. This is a result of a patch
that was submitted to add asynchronous device probing (specifically, commit
f049cf1a7b6737c75884247c3f6383ef104d255a). Previously, devices would always be
probed in the order in which they exist on the bus, resulting in the first
device being named 'sda', the second device 'sdb', and so on. .... (so)
Normally you can't rely on device names being consistent between boots
The situation is not a difficult one to manage because one can decide which disk will hold the operating system, and which may be a data disk, and once installed, those installations do not change, rather the change is only in the device name in the form of /dev/sd# which the kernel allocates non-deterministically.
I guess you are familiar with the changes, but for clarification and to enable explanation, the following examples will do.
In this example, the first boot up shows that the disk with the root partition and the system are on
/dev/sda
Code:
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 931.5G 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 930G 0 part /
sdb 8:16 0 1.8T 0 disk
└─sdb1 8:17 0 1.8T 0 part /mnt/data
sr0 11:0 1 1024M 0 rom
The following shows the same machine on another boot where the root partition and the system are on
/dev/sdb:
Code:
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:16 0 1.8T 0 disk
└─sda1 8:17 0 1.8T 0 part /mnt/data
sdb 8:0 0 931.5G 0 disk
├─sdb1 8:1 0 512M 0 part /boot/efi
├─sdb2 8:2 0 1G 0 part /boot
└─sdb3 8:3 0 930G 0 part /
sr0 11:0 1 1024M 0 rom
The disks have not changed, only the names. It's quite invisible to the user of the machine if they are just using it without looking into the names. In normal usage of the machine there are no functional consequences in terms of performance.
The disks in modern times are actually identified by the system with UUID numbers which can be seen in the
/etc/fstab file which shows all the disks which are mounted or to be mounted for the system. Significantly, the UUID can show the user which disk is allocated to /dev/sda or /dev/sdb, or any other disk.
Apart from the UUID there are multiple ways of identifying the disks and they are all in the /dev filesystem which can be seen here:
Code:
$ ls -al /dev/disk
total 0
drwxr-xr-x 8 root root 160 Sep 14 07:24 .
drwxr-xr-x 18 root root 3720 Sep 14 07:24 ..
drwxr-xr-x 2 root root 80 Sep 14 07:24 by-designator
drwxr-xr-x 2 root root 140 Sep 14 07:24 by-diskseq
drwxr-xr-x 2 root root 300 Sep 14 07:24 by-id
drwxr-xr-x 2 root root 100 Sep 14 07:24 by-partuuid
drwxr-xr-x 3 root root 180 Sep 14 07:24 by-path
drwxr-xr-x 2 root root 100 Sep 14 07:24 by-uuid
To look at identification by UUID:
Code:
$ ls -al /dev/disk/by-uuid
<snip>
lrwxrwxrwx 1 root root 15 Sep 14 07:24 1c2xxxx8-3xx6-4a8b-b9fa-4fxxxxx39534 -> ../../sda3
lrwxrwxrwx 1 root root 15 Sep 14 07:24 12345678-1234-1234-4321-098765432123 -> ../../sdb1
<snip>
The UUID numbers show the disks that are linked to the respective /dev/sd# names.
These same UUID numbers will be the ones that appear in the /etc/fstab file to show the particular disks which are mounted at boot time. Whilst years ago when the /dev/sd# identifications were stable, they appeared in
/etc/fstab, but that's no longer workable in most distros because of the variability, hence they default to the UUID numbers.
A straightforward means of telling which disk is /dev/sda and which is /dev/sdb is to use the serial numbers in the output of the lsblk command. First, one can become acquainted with the disks' serial numbers, so for example there might be a Western Digital with serial number 1234 and a Seagate with serial number 9876, so one can run the following command and get something like the output shown (in this example with the made-up numbers):
Code:
$ lsblk -o NAME,SERIAL
NAME SERIAL
sda 1234
└─sda1
sdb 9876
├─sdb1
├─sdb2
└─sdb3
sr0
The results show which disk is /dev/sda and which is /dev/sdb, as long as one is aware of the serial numbers which are usually written on the disks somewhere. In this case the Western Digital is shown as /dev/sda etc.
To the point of:
I want my main ssd to be on sda and my backup on sdb.
it should be clear that this is unnecessary because one has the means of never losing track of the names of the disks (shown above), so it's a rather profitless exercise which would require extra software to achieve that and would provide information of no technical functional value.
Note, I haven't dealt with using e2label which is another means of identification.