Hardcoded unique(?) ID
Most mass storage devices (maybe not all) have a hardcoded unique ID, that is seen at /dev/disk/by-id
. The following command line will show this ID,
sudo ls -l /dev/disk/by-id|grep -v '[1-9]$'|tr -s ' ' '\t'|cut -f 9- | sed 's#../../#/dev/#'
and also show which block device it is represented by, '-> /dev/sdx
'
Example (my working computer with three USB pendrives connected),
$ sudo ls -l /dev/disk/by-id|grep -v '[1-9]$'|tr -s ' ' '\t'|cut -f 9- | sed 's#../../#/dev/#'
ata-HL-DT-STDVD+-RW_GSA-H21L -> /dev/sr0
ata-KINGSTON_SKC300S37A120G_50026B724703BCA8 -> /dev/sda
ata-WDC_WD4002FYYZ-01B7CB1_K3GWHAEB -> /dev/sdb
usb-Corsair_Voyager_GT_3.0_070883862E1B9719-0:0 -> /dev/sdc
usb-SanDisk_Cruzer_Blade_200429068118E7C2CFFD-0:0 -> /dev/sde
usb-SanDisk_Cruzer_Blade_200429068118F440A09E-0:0 -> /dev/sdd
wwn-0x5000cca25ccc7f97 -> /dev/sdb
wwn-0x50026b724703bca8 -> /dev/sda
UUID of file system(s)
If there are partitions with file systems, there are also UUIDs for each file system, and these are often but not always unique, depending on if they were created individually or cloned from some common original file system or image file. The UUIDs can be shown by blkid
and by lsblk
via the following command line,
lsblk -l -o name,size,UUID,model
Example (my working computer with three USB pendrives connected),
$ lsblk -l -o name,size,UUID,model
NAME SIZE UUID MODEL
sda 111,8G KINGSTON SKC300S
sda1 106,9G 0ac1cb43-1609-4fc3-8c69-3e21299729bc
sda2 5G 6d54c49d-31ac-45fe-917c-2335bcfe7399
sdb 3,7T WDC WD4002FYYZ-0
sdb1 510M 9F05-5B18
sdb2 5G 08b7164f-8852-451b-9624-63b16a66359a
sdb3 10G fa242ddd-90f8-4603-af5c-c89f4b71ac70
sdb4 15G 491a6a2b-4867-44d5-94d8-082f79066a5a
sdb5 1M
sdb6 100G 44156f43-0958-4ea1-800d-b02afbc7d306
sdb7 3,5T 862210fd-a6fd-4fe3-913c-e18e1448ef36
sdb8 5G 6958d86a-57a9-4e40-8376-1e41258e5810
sdc 29,5G Voyager GT 3.0
sdc1 9,1G 38028BF9184E3FB4
sdc2 1M
sdc3 244M 4299-B748
sdc4 1,8G 2018-04-26-18-43-51-00
sdc5 18,4G 033ffb75-518d-4335-89cb-ef7d159cf20b
sdd 3,7G 2016-08-24-07-06-03-00 Cruzer Blade
sdd1 1,3G 2016-08-24-07-06-03-00
sde 3,7G 2016-07-19-21-27-51-00 Cruzer Blade
sde1 1,4G 2016-07-19-21-27-51-00
sde2 2,3M 0F7B-9366
sr0 1024M DVD+-RW GSA-H21L
These methods are enough to help me identify the connected mass storage devices after a quick manual inspection.
It is possible to use the hardcoded ID and/or the UUIDs automatically. For example, you can create a corresponding md5sum for every mass storage device that you have, and store the md5sums in variables in a shellscript, where you can check for matches.