What guarantees does Linux make regarding the mapping of device names to the physical hard drives?
Which rules does it use to map physical hard drives to files in /dev/?
I cannot speak for every linux distribution but I can speak for how SUSE does it, in SUSE there is available these options
mount by
- device name
- device id
- volume label
- device path
- UUID
by device name I will say is bad because it causes linux to check the hardware and the order in which it sees drives connected is how it does the mapping to sda, sdb, and so on. So if your boot device and partition is called out as sda and you simply switch the order of drives in removable slots (on a server) or switch the sata cables in a home computer between two drives it will upset things. Also my experience has been (on servers with 8, 16, or 24 drive bays) that it often goes backwards that drive slot 0 does NOT map to sda... if you had 3 drives then slot 2 is sda, slot 1 sdb, and slot 0 sdc. AND add any temporary hardware that gets mapped as /dev/sda
and pushes the drives down a letter upsetting things. But I will say this method is good when setting up a gold image operating system drive that you plan to clone... you don't have to worry about hard drive id's or WWN's changing on a new disk a least for a little while... if it is the only disk in system it is likely that it will always show up as sda.
FSTAB syntax:**
/dev/sdc2 / EXT3 acl,user_xattr 1 1
/dev/sdc1 /boot/efi VFAT
/dev/sdb1 /data XFS defaults 1 0
by device id is what I always use because it solves basically all the problems mentioned for "by device name", and it has worked well for me over the years which just about everything. Once mounting is configured by device id the drives just need to be present or connected. If drives get moved around or new hardware gets mapped as some /dev/sd?
it does not affect anything that was previously configured.
FSTAB syntax:
/dev/disk/by-id/scsi-35000aab12345a30-part2 / EXT3 acl,user_xattr 1 1
/dev/disk/by-id/scsi-35000aab12345a30-part1 /boot/efi VFAT
/dev/disk/by-id/scsi-3600404abc123def456-part1 /data XFS defaults 1 0
by UUID {universally unique identifier} I think is also a good one, it works much like "by device-id" however I do not know how the UUID is created and made unique, or if it ends up being the same as by device id?
by volume label can also work well provided you or someone has made a good volume label to whatever filesystem or partition or volume that is to be mounted. I am sure it would be problematic if two partitions had the same volume label, such as "boot" for example I suspect whichever volume lablel linux finds first is the one it would use if it does not report duplicate volume labels.
Also, this is all based on linux Udev (to sort of answer which algorithm is used). I believe it is the same from older Init linux as well as on the newer Systemd linux, since Udev is the package used in most all linux distributions. And I think it is mostly the syntax in /etc/fstab
specifically the first field or column on each line is what determines the mount method that will happen (not algorithm), that there is not some other config file somewhere and I say this because you can have multiple lines in /etc/fstab
each mounting something different by a different mount method (by name, id, uuid, or label) and as far as I know nothing else anywhere has changed except for the syntax in the fstab file.
alias list_disks='find /dev/disk/by-id/ -iname ata-* -o -iname usb-* -o -iname dm-name* | grep -v -- -part | while read disk ; do echo $(basename $(readlink $disk)) $(basename $disk); done | sed -re "s/(usb|ata)-// ; s/(SATA|Generic)_//" | sort'
– cas May 06 '16 at 04:56/dev/sd*
? – Konstantin Schubert May 06 '16 at 04:59search
command to find the device with correct UUID. – sourcejedi Jul 29 '18 at 08:23