Identifying flash drive in /dev/sdX
In linux, when a new device is inserted, a new file will be created at /dev to handle it. When a storage device is inserted, It’ll be created /dev/sdX, where X is a letter between a and z that will increase as we insert more devices. If we only have one, we’ll have /dev/sda. If that device had two partitions, we would have /dev/sda, /dev/sda1 and /dev/sda2. If we insert another device we’ll have /dev/sdb too.
Is very important to know the file at /dev associated to the device that we want to handle because we could format or delete data from another disk by mistake. There are several ways to check:
- I usually use gparted, it’s a partition editor for gnome. There are all disks with its partitions, called /dev/sda, /dev/sdb, etc. So checking the partitions and size of the device that we’ve just inserted, we can deduce its letter, which should be the last one.
- Another way to do it is to navigate through a file manager to /dev, to order by “date of modification” and select all with Ctrl+A. Now, when inserting the new storage device, a new file will appear at the end, and won’t be selected, so that’s our file.
- Another way would be with dmesg | tail command. We type it in a terminal and we’ll see the log of the last events, including the insertion of the pendrive and its associated letter.
- Another way would be with df command. We type it in a terminal and we’ll see all partitions. There we can deduce which one corresponds to the device that we’ve just inserted looking at its size.