How to identify SD-cards and flash sticks as being such?

Oct 10, 2014 25 Replies

Looking at the usbmount package. I see that it includes the text: "USBmount is intended as a lightweight solution which is independent of a desktop environment. Users which would like an icon to appear when an USB device is plugged in should use the pmount and hal packages instead."

I really don't want to break normal operation. Never mind. Since udev (and HAL unless it's been merged into udev) is standard on recent distros, the log search method should be robust. I'll just include a prompt to re-insert the device (if it was left in during reboot or something).

#!/bin/bash # burn specified iso to usb flash (verifies that it IS on USB) fail() { echo Error: $*; exit 1; } [[ -z $(grep '\bdisk\b' < &1 | grep ID_BUS=usb) ]] \ && fail Please re-insert the USB device mod=$(udevadm info /dev/$dv | grep 'ID_MODEL=' | sed 's/.*ID_MODEL=//') read -p "Burn $1 into \"$mod\" at /dev/$dv [Yn]" yn [[ "$yn" == [nN]* ]] && exit 1 [[ "$1" == ?(*.zip|*.gz) ]] && fz=funzip || fz='tee' pv -tpreb "$1" | $fz | dd bs=1M oflag=dsync of="/dev/$dv"

Yes... but what if user plugs in USB device that is not recognized for some reason? Like deffective device. I received one USB card reader that only lights up its LEDs and does nothing more. No info in logs. It is not detected. Well... as you've mentioned... at the end user has to decide. :)

One could make use of the kernel time in dmesg output. e.g. ignore block devices attached within 2 minutes after system start...

Still applies though

Yes. If you look at my second version of the script that I put in a reply to Rob, you'll see that if the last inserted /dev/sd? device isn't a USB device, you'll get a prompt to re-insert it. Then the user is prompted with the device model name as a final check.

I think that's better that giving the user a deadline to complete an action, given the holdups that are normally encountered when you're developing things with computers, and in any case, uptime comparisons are awkward to parse and would require several extra lines of code.

Perhaps one thing to consider is that a lot of built in SD card readers on laptops aren't USB. My Dell Latitude at work for example shows a "Standard Compliant SD Host Controller" connected to PCI Express.

OK. The one internal SD reader that I tried (on an Acer Revo mini-PC) did show up as USB.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required