Find all storage devices attached to a Linux machine

warren picture warren · Oct 14, 2008 · Viewed 467.5k times · Source

I have a need to find all of the writable storage devices attached to a given machine, whether or not they are mounted.

The dopey way to do this would be to try every entry in /dev that corresponds to a writable devices (hd* and sd*)......

Is there a better solution, or should I stick with this one?

Answer

Steve Baker picture Steve Baker · Oct 14, 2008

/proc/partitions will list all the block devices and partitions that the system recognizes. You can then try using file -s <device> to determine what kind of filesystem is present on the partition, if any.