Quote:
Of course, be VERY CAREFUL to specify the correct device
|
There are many links created by udev in the /dev/disk directory that you could use instead of specifying raw devices, a much safer approach. The following is for a Kingston flash drive.
Code:
$ ll /dev/disk/by-id/usb*
lrwxrwxrwx 1 root root 9 Sep 9 16:48 /dev/disk/by-id/usb-Kingston_DataTraveler_2.0-0:0 -> ../../sdf
lrwxrwxrwx 1 root root 10 Sep 9 16:48 /dev/disk/by-id/usb-Kingston_DataTraveler_2.0-0:0-part1 -> ../../sdf1
The links in /dev/disk/by-id are prefixed by protocol so all USB devices would be usb-*. All SATA drives would be ata-*. If you only have one USB device plugged in there would be no trouble differentiating it from all of your SATA drives. If you have multiple then the device name
Kingston_DataTraveler_2.0 in this case would be useful.
Code:
$ readlink -f /dev/disk/by-id/usb-Kingston_DataTraveler_2.0-0\:0-part1
/dev/sdf1
$ lsblk -f /dev/disk/by-id/usb-Kingston_DataTraveler_2.0-0\:0-part1
NAME FSTYPE LABEL UUID MOUNTPOINT
sdf1 vfat KINGSTON 0000-3781
To perform a mount:
Code:
mkdir /mnt/usb_flash
sudo mount /dev/disk/by-id/usb-device-name-0\:0-part1 /mnt/usb_flash
You wouldn't need to type out the full name as you could use tab completion after entering /dev/disk/by-id/usb-. With udev there is no need to specify drive letters at all, a safer approach. There is a thread about an OP who erased their HDD by typing the wrong letter when they were trying to write to a flash drive with dd to create a bootable USB. Using these udev links instead of drive letters would have saved their whole drive.
A permanent solution for a drive you use often would be to create udev rules to give a fixed link name, such as /dev/lexar for a Lexar flash drive and to automount it to a location in your fstab.