1

how can I get the paths to all sd cards in a computer using GNU bash 4.3.11 running Ubuntu 14.04 and just those?

Background:

I have an .iso-file and want to create a bash script that asks the user to which sd card he wants that .iso-file to be written. The script should not offer him internal hard drives or cd/dvd-drives, just sd card paths.

Actually I manually use

ls -la /dev/sd*

which for example gives me on a test machine

brw-rw---- 1 root disk 8,  0 May  3 10:54 /dev/sda
brw-rw---- 1 root disk 8,  1 May  3 10:54 /dev/sda1
brw-rw---- 1 root disk 8,  2 May  3 10:54 /dev/sda2
brw-rw---- 1 root disk 8,  5 May  3 10:54 /dev/sda5
brw-rw---- 1 root disk 8, 16 May  3 15:12 /dev/sdb
brw-rw---- 1 root disk 8, 17 May  3 14:56 /dev/sdb1
brw-rw---- 1 root disk 8, 18 May  3 14:56 /dev/sdb2

I "know" that sda is my hard drive in that case because I know the hardware of the computer and therefor so sdb must be the sd card, but how can an algorithm do this?

2
  • 1
    I don't have an sd card to test this on but you might be able to do something with a combination of lsblk, blkid, /etc/fstab, mount (look for things that are mounted but are not in fstab), lsusb (to exclude USB drives) etc. Commented Mar 3, 2016 at 15:17
  • okay I'll try it. Commented Mar 3, 2016 at 20:40

1 Answer 1

1

You can obtain valuable information with the command lsblk -d -t which provides output like this:

NAME  ALIGNMENT MIN-IO OPT-IO PHY-SEC LOG-SEC ROTA SCHED    RQ-SIZE
sda           0    512      0     512     512    0 deadline     128
sdb           0   4096      0    4096     512    1 deadline     128
sdc           0    512      0     512     512    1 deadline     128
sdd           0    512      0     512     512    1 deadline     128
sr0           0    512      0     512     512    1 deadline     128

with which you can eliminate any line with a ROTA of 1 (which indicates rotating media and will rule out HDD's and CDROMs) unfortunately I don't have a method of ruling out SSD's without making dangerous assumptions (even capacity won't work safely as The Secure Digital eXtended Capacity (SDXC) format, announced in January 2009 and defined in version 3.01 of the SD specification, supports cards up to 2 TB and I've seen SDcards with capacities higher than some SSD's

2
  • I get a ROTA = 1 at my hard drive, my sd card and my dvd drive, despite the manual says that you are right. And sdb is my sd card, I checked it again. Commented Mar 3, 2016 at 18:14
  • @Undertaker That's odd, sorry I can't test SDcards at the moment. Commented Mar 3, 2016 at 18:31

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.