How to find storage devices attached to computer

Two storage devices found attached to computer
Two storage devices found attached to computer

Storage devices like hard disks, SSD drives, CD/DVD disks, SD cards and USB thumdrives can be plugged into a Linux computer. For many operations, we need to know the name of the storage device. For example, /dev/sda. Partitions created on this device to store data will have characters suffixed to this device name. For example, /dev/sda7 might be a partition on the /dev/sda hard disk.

Using fdisk

I like to find out the device name of storage devices by listing them out using fdisk:

$ sudo fdisk -l

For each storage device, this lists the device name (named after Disk) followed by information about it and its partitions.

Using df

The df command lists the mounted partitions on the computer:

$ df -h

You will have to guess the name of the storage device from the partition name by removing a few characters of suffix. For example, partitions on a SD card named /dev/mmcblk0 might be named as /dev/mmcblk0p1 and /dev/mmcblk0p2.

Using GNOME Disk

The GNOME Disk utility is typically pre-installed on Ubuntu. It can be invoked from the Dash using its name Disks or from the shell as gnome-disks. It shows all the attached storage devices and their name is listed under Device.

Using lshw

Some people suggest listing the disk class of devices from the lshw command:

$ sudo lshw -class disk

I do not prefer this since it does not list SD cards and many such storage devices.

Tried with: Ubuntu 14.04

How to wipe a SD card in Ubuntu

Note: Unlike hard disks, SD cards cannot actually be securely wiped such that data is fully unrecoverable. The only way to do that would be using an erase functionality of its firmware, if it has one. Else physical destruction of the SD card! 🙂

SD cards are commonly used in cameras and smartphones to store photos and other personal content. Even after these files are deleted they can be easily recovered from the SD card. So, it may be essential to completely erase the SD card such that data recovery is very difficult (but not impossible).

  • Find out the partition the SD card is mounted as. For example, a SD card I use in my camera is formatted as a FAT32 partition. I plug it into my Ubuntu computer and it is mounted automatically. I can find out its partition by either of these commands:
$ sudo fdisk -l
$ sudo blkid
  • Unmount the SD card. (Note: Do not eject it.) If you do not unmount it you might get this error while wiping it: failed to open for writing: Read-only file system

  • Use the shred program to erase the SD card partition. For example, I find that the FAT32 partition on my SD card is at /dev/sdb1. I wipe the SD card partition using:

$ sudo shred -v /dev/sdb1

By default, shred will overwrite the entire partition 3 times, making it really difficult to recover any old content from it.

Tried with: CoreUtils 8.23 and Ubuntu 15.10