Context
I'm automating SD card imaging from an existing dd
factory image. The SD card is always connected through an external USB card reader and thus appears in the system as a SCSI block device /dev/sd*
.
Currently the syntax of my command is: write-image DEVICE
where DEVICE
is the SD card block device, eg. /dev/sdd
.
Problem
I'm already doing a basic check on DEVICE
to verify it is of the form /dev/sd*
but this is not enough: I fear the users (production people not used to Linux) make a mistake and specify another seemingly valid device, eg. /dev/sda
. You can see the looming catastrophe, especially since my imaging script needs root privileges (not to write the image itself, mind you, but to modify the SD card afterwards, including adjusting a partition's size depending on the SD card's real size)...
Question
I would like to verify that the specified device actually is some USB mass storage (or at the very least a removable device) so that I can protect the system disks from being trashed accidentally. How can I do that?
I found nothing relevant in /proc
or on the web, I'm quite at loss now.