How does Linux know which USB hard drive is which

automountinghard-diskmount

Currently I have Linux Mint installed on my PC with a USB hard drive partition mounted as /home. This is working well.

If I install a second USB hard drive, is there any chance Linux will get confused between the two, and try mount the second hard drive's partition as /home on boot? That would be bad.

Coming from Windows, I've seen it happen often that drive letters are not "remembered" correctly causing all sorts of issues.

I guess the main question is: How does Linux actually know which USB hard drive is /dev/sdb and which is /media/misha/my_2nd_drive?

Best Answer

Usually the location of the USB port (Bus/Device) determines the order it's detected on. However, don't rely on this.

Each file system has a UUID which stands for universally unique identifier (FAT and NTFS use a slightly different scheme, but they also have an identifier that can be used as a UUID). You can rely on the (Linux) UUID to be unique. For more information about UUIDs, see this Wikipedia article.

Use the disk UUID as a mount argument. To find out what the UUID is, run this:

$ sudo blkid /dev/sdb1

(blkid needs to read the device, hence it needs root powers, hence the sudo. If you've already become root, the sudo is not needed.)

You can then use that UUID in /etc/fstab like this:

UUID=7e839ad8-78c5-471f-9bba-802eb0edfea5 /home ext4 defaults 0 2

There can then be no confusion about what disk is to be mounted on /home.

For manual mounting you can use /dev/disk/by-uuid/.....

Related Question