While I was attempting to work out
card reader on Linux I discovered a couple of useful utilities which
can be used to scan the SCSI bus on a Linux computer and show a list of
SCSI and USB type devices, such as CD-ROMs, flash card readers etc. While
trying to mount the flash card reader I at first thought I needed to
manually add an entry to the /etc/fstab table and needed to get the device
name and number but this didn’t turn out to be the case. Refer to mount a flash
card reader of
this article to see how easy it is to mount a card reader on modern Linux
distributions.
Note that SuSE Professional 9.0 was used to write this article. It is
assumed that these utilties will work similarly well on other modern Linux
distributions. If you have experience making this work on other
distributions and it’s a little diferent I’d love to hear your solution and will update this
article accordingly.
sg_scan
The first utility is sg_scan
. To get the necessary
information you should use the -i
flag otherwise the results
are a little meaningless like so:
sg_scan -i
You will most likely have to be logged in as root when you do this
otherwise you will probably see a somewhat self-explanatory error like
so:
sg_scan: Error opening /dev/sg0 :
Permission denied
sg_scan: Error opening /dev/sg1 : Permission
denied
sg_scan: Error opening /dev/sg2 : Permission denied
sg_scan: Error opening /dev/sg3 : Permission denied
Stopping
because there are too many error
root access may be
required
After logging in as root (or using sudo, su -c "sg_scan
-i" etc), you’ll see something like so:
/dev/sg0: scsi0 channel=0 id=0 lun=0 [em]
type=5
HL-DT-ST RW/DVD GCC-4240N
0110 [wide=0 sync=0 cmdq=0 sftre=0 pq=0x0]
/dev/sg1: scsi1 channel=0
id=0 lun=0 [em] type=0
[wide=0 sync=0 cmdq=0 sftre=0 pq=0x1]
/dev/sg2: scsi1 channel=0 id=0
lun=1 [em] type=0
[wide=0
sync=0 cmdq=0 sftre=0 pq=0x1]
/dev/sg3: scsi1 channel=0 id=0 lun=2
[em] type=0
[wide=0 sync=0
cmdq=0 sftre=0 pq=0x1]
/dev/sg4: scsi1 channel=0 id=0 lun=3 [em]
type=0
[wide=0 sync=0 cmdq=0
sftre=0 pq=0x1]
This particular example shows us that there is a DVD player at
/dev/sg0. After plugging in my flash card reader and running the command
again, I got the following result:
/dev/sg0: scsi0 channel=0 id=0 lun=0 [em]
type=5
HL-DT-ST RW/DVD GCC-4240N
0110 [wide=0 sync=0 cmdq=0 sftre=0 pq=0x0]
/dev/sg1: scsi1 channel=0
id=0 lun=0 [em] type=0
Generic STORAGE
DEVICE 9138 [wide=0 sync=0 cmdq=0 sftre=0 pq=0x0]
/dev/sg2: scsi1 channel=0 id=0 lun=1 [em] type=0
Generic STORAGE DEVICE 9138 [wide=0 sync=0
cmdq=0 sftre=0 pq=0x0]
/dev/sg3: scsi1 channel=0 id=0 lun=2 [em]
type=0
Generic STORAGE DEVICE
9138 [wide=0 sync=0 cmdq=0 sftre=0 pq=0x0]
/dev/sg4: scsi1
channel=0 id=0 lun=3 [em] type=0
Generic
STORAGE DEVICE 9138 [wide=0 sync=0 cmdq=0 sftre=0
pq=0x0]
From this we can see there is some sort of storage device on /dev/sg1
through /dev/sg4. It is not possible to mount these devices directly so
you need to use the sg_map
utility.
sg_map
Entering sg_map
when logged in as root will display
something similar to:
/dev/sg0 /dev/scd0
/dev/sg1
/dev/sda
/dev/sg2 /dev/sdb
/dev/sg3
/dev/sdc
/dev/sg4 /dev/sdd
From this we can see that the device at /dev/sg1 can be mounted using
the mapped device /dev/sda. However, if you try to mount the flash card
(assuming that’s what you’ve connected) after plugging the flash card into
the reader like so:
mount -t msdos /dev/sda
/path/to/mount/point
you’ll get an error like so:
mount: wrong fs type, bad option, bad
superblock on /dev/sda,
or too many mounted
file systems
Instead try mounting it like so:
mount -t msdos
/dev/sda1/path/to/mount/point
and it will probably work. If you are using a multi card reader 1 may
not be the appropriate number so try using 2 then 3 and so on. If the
number is not correct you’ll get an error message like so:
mount: /dev/sda2 is not a valid block
device
Because I only have an a CF Card to test my multi card reader, and it’s
in the first slot, I’m assuming the second slot would be /dev/sda2.
If you mount your flash cards this way always remember to unmount the
flash card before pulling it out of the reader otherwise you may damage
the data on the card.