Listing removable media

While I was going through the process of writing up the process of putting an Ubuntu MATE image for the Raspberry Pi2 on to an SD card it occurred to me that there ought to be an easy way for beginners using linux to find out what removable storage devices are connected to their system, you don’t want to overwrite the wrong one by accident!

A bit of messing about with Google turned up vairous possible solutions; listing removable devices in /sys/block; using df to list the free space on all disks; or lsusb to list all USB devices. The problem is that for a beginner the results will be different on each machine and need some interpretation in order to work out which device refers to what. Fortunately I found a very neat little script here that lists all the removable USB storage devices on the ssytem so you can easily see which one is which, and there is also a very good explanation of how it all works. All you need to do it create a bash script and paste the relevent code from the page into it.

$ nano

   grep -Hv ^0$ /sys/block/*/removable |
   sed s/removable:.*$/device\\/uevent/ |
   xargs grep -H ^DRIVER=sd |
   sed s/device.uevent.*$/size/ |
   xargs grep -Hv ^0$ |
   cut -d / -f 4

for dev in ${USBKEYS[@]} ;do
   echo $dev \"$(
      sed -e s/\ *$//g </sys/block/$dev/device/model
      )\" ;

Then you just need to make it executable before running it. In my case I have several USB storage devices plugged in, CRW-CF/MD is my compact flash card from my camera, it is hopefully reasonably obvious that CRW-SD is the my SD card, and the third device is a Kingston USB stick.

$ chmod +x
$ ./
sdd "USB3.0 CRW-CF/MD"
sde "USB3.0 CRW-SD"
sdg "DataTraveler 2.0"

My thanks to F HAURI for including an excellent write up with his solution.

Raspberry Pi is a trademark of the Raspberry Pi Foundation

This entry was posted in Debian, Linux, Ubuntu and tagged , . Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.