289

I need to know what hard disks are available, including ones that aren't mounted and possibly aren't formatted. I can't find them in dmesg or /var/log/messages (too much to scroll through). I'm hoping there's a way to use /dev or /proc to find out this information, but I don't know how. I am using Linux.

4
  • The original question didn't specify any particular unix variant, and hardware management is obviously highly variant-dependent. Commented Dec 6, 2010 at 18:51
  • @gilles yeah I was at work when I wrote it, so I clarified after I got home and thought about it. Commented Dec 7, 2010 at 1:11
  • 1
    Depending on what you're doing, udisks.
    – derobert
    Commented Oct 3, 2012 at 17:06
  • 2
    I found a useful page describing many common hardware commands with a search on Google. The disk drive ones include lshw (List Hardware), hwinfo (Hardware Information), lsscsi (List scsi devices), lsusb (List usb buses/devices), lsblk (List block devices), fdisk -l and mount. More information at binarytides.com/linux-commands-hardware-info.
    – Edward
    Commented Oct 1, 2017 at 14:35

16 Answers 16

239

This is highly platform-dependent. Also different methods may treat edge cases differently (“fake” disks of various kinds, RAID volumes, …).

On modern udev installations, there are symbolic links to storage media in subdirectories of /dev/disk, that let you look up a disk or a partition by serial number (/dev/disk/by-id/), by UUID (/dev/disk/by-uuid), by filesystem label (/dev/disk/by-label/) or by hardware connectivity (/dev/disk/by-path/).

Under Linux 2.6, each disk and disk-like device has an entry in /sys/block. Under Linux since the dawn of time, disks and partitions are listed in /proc/partitions. Alternatively, you can use lshw: lshw -class disk.

Linux also provides the lsblk utility which displays a nice tree view of the storage volumes (since util-linux 2.19, not present on embedded devices with BusyBox).

If you have an fdisk or disklabel utility, it might be able to tell you what devices it's able to work on.

You will find utility names for many unix variants on the Rosetta Stone for Unix, in particular the “list hardware configuration” and “read a disk label” lines.

2
  • 12
    Ooo; that Rosetta Stone site is excellent Commented Dec 6, 2010 at 15:22
  • 7
    sudo lshw -class disk made my day, simple and intuitive output. Commented Aug 22, 2020 at 11:07
206

lsblk will list all block devices. It lends itself well to scripting:

$ lsblk -io KNAME,TYPE,SIZE,MODEL
KNAME TYPE   SIZE MODEL
sda   disk 149.1G TOSHIBA MK1637GS
sda1  part  23.3G 
sda2  part    28G 
sda3  part  93.6G 
sda4  part   4.3G 
sr0   rom   1024M CD/DVDW TS-L632M

lsblk is present in util-linux package and is thus far more universal than proposed alternatives.

3
  • 13
    If you only need the physical disks, use lsblk -d, -d means no dependency message listed.
    – coanor
    Commented Apr 1, 2015 at 8:09
  • 2
    Indeed =) $ lsblk -ido KNAME,TYPE,SIZE,MODEL (part of util-linux which is part of base on Arch) instantly gives the information requested, and without the need to be root. Note that it provides the Device model, not Model Family. smarctl -i /dev/<device> advised by Skippy did it, eg: "Model Family: Seagate Barracuda 7200.12" (missing from lsblk -ido: "disk 465,8G ST3500418AS").
    – tuk0z
    Commented Sep 3, 2015 at 13:47
  • What I learned recently: -f is nice. So nice it might deserve being aliased in.
    – Vorac
    Commented Jul 12 at 10:26
83

How about

lshw -class disk
6
  • 3
    not bad... I'll double check it when I get off, I'm sure it works... unfortunately it's (lshw) not installed on the server, and I suspect the answer will be we're not installing it. Commented Dec 6, 2010 at 8:23
  • For some reason, lshw does not list hard disks. Commented Nov 6, 2013 at 0:44
  • 2
    When not run as root, it lists no disks, but also gives no error. Commented Jul 1, 2014 at 11:26
  • 2
    bash: lshw: command not found
    – Anthony
    Commented Jan 25, 2017 at 18:51
  • skips NVMe SSDs
    – Steven Lu
    Commented Nov 14, 2019 at 4:21
33

hwinfo helps:

> hwinfo --disk
21: IDE 00.0: 10600 Disk                                        
[Created at block.245]
Unique ID: 3OOL.8MZXfAWnuH8
Parent ID: w7Y8.1T_0outZkp6
SysFS ID: /class/block/sda
SysFS BusID: 0:0:0:0
SysFS Device Link: /devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0
Hardware Class: disk
Model: "Hitachi HTS54322"
Vendor: "Hitachi"
Device: "HTS54322"
Revision: "ESBO"
Driver: "ahci", "sd"
Driver Modules: "ahci"
Device File: /dev/sda
Device Files: /dev/sda, /dev/disk/by-id/ata-Hitachi_HTS543225A7A384_E2021342GEPG4J, /dev/disk/by-id/scsi-SATA_Hitachi_HTS5432_E2021342GEPG4J, /dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0, /dev/disk/by-id/wwn-0x5000cca614c6395e
Device Number: block 8:0-8:15
BIOS id: 0x80
Geometry (BIOS EDD): CHS 484521/16/63
Size (BIOS EDD): 488397168 sectors
Geometry (BIOS Legacy): CHS 1023/255/63
Drive status: no medium
Config Status: cfg=new, avail=yes, need=no, active=unknown
Attached to: #17 (SATA controller)
> hwinfo --block --short
disk:                                                           
  /dev/sda             Hitachi HTS54322
partition:
  /dev/sda1            Partition
  /dev/sda2            Partition
  /dev/sda3            Partition
  /dev/sda4            Partition
  /dev/sda5            Partition
21

@Giles says this is highly platform-dependent. Here's one such example.

I'm running a CentOS 5.5 system. This system has 4 disks and a 3ware RAID controller.

In my case, lshw -class disk, cat /proc/scsi/scsi and parted --list shows the RAID controller (3ware 9650SE-4LP). This doesn't show the actual disks:

only shows the 3ware RAID controller which provides the /dev/sda volume:

# lshw -class disk
  *-disk                  
       description: SCSI Disk
       product: 9650SE-4LP DISK
       vendor: AMCC
       physical id: 0.0.0
       bus info: scsi@0:0.0.0
       logical name: /dev/sda

# cat /proc/scsi/scsi 
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
  Vendor: AMCC     Model: 9650SE-4LP DISK  Rev: 4.06
  Type:   Direct-Access                    ANSI SCSI revision: 05

# parted --list

Model: AMCC 9650SE-4LP DISK (scsi)
Disk /dev/sda: 2000GB

In order to see the disks which lie underneath, I had to install the tw_cli utility from 3ware, and ask the controller itself.

# tw_cli info c0
...

VPort Status         Unit Size      Type  Phy Encl-Slot    Model
------------------------------------------------------------------------------
p0    OK             u0   931.51 GB SATA  0   -            WDC WD1002FBYS-02A6 
p1    OK             u0   931.51 GB SATA  1   -            WDC WD1002FBYS-02A6 
16

Since both "Can I see what HDD I have installed?" and "How do I determine the make & model of my storage devices?" are marked as duplicates of this question, I'm surprised no-one mentioned hdparm and smartctl. Having a look at a few machines, seems that either of them (when it's not both) is often found already installed in standard (even old) linux distributions.

# smartctl -i /dev/sda
smartctl 6.1 2013-03-16 r3800 [i686-linux-3.9.9-301.fc19.i686.PAE] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     Toshiba 2.5" HDD MK..56GSY
Device Model:     TOSHIBA MK1656GSY
Serial Number:    60PKT43CT
LU WWN Device Id: 5 000039 2919874b6
Firmware Version: LH013D
User Capacity:    160 041 885 696 bytes [160 GB]
Sector Size:      512 bytes logical/physical
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ATA8-ACS (minor revision not indicated)
SATA Version is:  SATA 2.6, 3.0 Gb/s
Local Time is:    Mon Jul 22 11:13:37 2013 CEST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

# hdparm -i /dev/sda

/dev/sda:

 Model=TOSHIBA MK1656GSY, FwRev=LH013D, SerialNo=60PKT43CT
 Config={ Fixed }
 RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=0
 BuffType=unknown, BuffSize=16384kB, MaxMultSect=16, MultSect=16
 CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=312581808
 IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
 PIO modes:  pio0 pio1 pio2 pio3 pio4
 DMA modes:  sdma0 sdma1 sdma2 mdma0 mdma1 mdma2
 UDMA modes: udma0 udma1 udma2 udma3 udma4 *udma5
 AdvancedPM=yes: unknown setting WriteCache=enabled
 Drive conforms to: Unspecified:  ATA/ATAPI-3,4,5,6,7

 * signifies the current active mode

As usual, check manpage for more options.

1
  • It should be noted that the smartctl way even works on Cygwin, +1! Just loop over possible device names and see if smartctl returns that the drive supports SMART. Commented Sep 12, 2013 at 12:35
14

I'm running fedora 14 and lshw is not available here (at least not by default). However in my case, I used fdisk -l command (as a root user) to get the following output:

Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0006a697

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    16777215     7875584   8e  Linux LVM

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table

Disk /dev/dm-0: 6509 MB, 6509559808 bytes
255 heads, 63 sectors/track, 791 cylinders, total 12713984 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/dm-0 doesn't contain a valid partition table

Disk /dev/dm-1: 1543 MB, 1543503872 bytes
255 heads, 63 sectors/track, 187 cylinders, total 3014656 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/dm-1 doesn't contain a valid partition table
1
  • Use fdisk -l /dev/sd? or fdisk -l /dev/hd? to avoid bring in dm devices.
    – laebshade
    Commented Feb 11, 2012 at 23:23
7

I found in other SE answer, inxi tool as very convenient:

inxi -Dxx
Drives:    HDD Total Size: 810.2GB (42.9% used)
           ID-1: /dev/sdc model: ST3160827AS size: 160.0GB serial: 5MT2HMH6
           ID-2: /dev/sdb model: WDC_WD3200JD size: 320.1GB serial: WD-WCAMR1302926
           ID-3: /dev/sda model: ST380817AS size: 80.0GB serial: 4MR2EWBE
           ID-4: /dev/sdd model: ST3250824AS size: 250.1GB serial: 9ND08GKX
4
sfdisk -l  

will give you detailed info about hardware/physical disks even if they are not mounted.

the program is pre-installed on all Linux variants that I have used, but you have to be root to use it.

3

This worked for me:

fdisk -l 2>/dev/null | grep "Disk \/" | grep -v "\/dev\/md" | awk '{print $2}' | sed -e 's/://g'
1
  • This worked very well for a server at work. I currently have 39 disk devices in it. It's a dual cpu SuperMicro server with 256GB of RAM and 36 hot swap 3.5 inch slots + 2 2.5 hotswap SATA SSD slots for the OS + dual internal NVMe for cache. I wanted a summary of the drives so that I can write / modify a script for nagios to monitor and make sense of the drives!
    – drescherjm
    Commented May 25 at 16:37
3

Many of the commands listed will help you look for disks that have already been recognized by the system at boot. With modern drives, you may find yourself looking for something that you inserted while the machine was up and running (I did). I like the advice from http://fredericiana.com/2010/06/15/hot-plugging-a-sata-drive-under-linux/:

Try this to rescan the SCSI hosts (each SATA port appears as a SCSI bus):

echo "0 0 0" >/sys/class/scsi_host/host/scan

...Then you can use your Linux utilities like fdisk to show you information about the disks that were found.

1

sudo gparted will show all this in a GUI.

(You didn't specify you need to do it within a terminal so I wonder why this solution was missing.)

1

On embedded Linux systems where lsblk nor lsscsi nor lsblk is not installed :

$ grep . /sys/class/block/sd*/device/model
/sys/class/block/sda/device/model:Samsung SSD 860
/sys/class/block/sdb/device/model:WDC WD4003FFBX-6
/sys/class/block/sdc/device/model:WDC WD4003FFBX-6
/sys/class/block/sdd/device/model:WDC WD4003FFBX-6

or if lsscsi is installed :

$ lsscsi
[0:0:0:0]    disk    ATA      Samsung SSD 860  2B6Q  /dev/sda
[1:0:0:0]    disk    ATA      WDC WD4003FFBX-6 0A83  /dev/sdb
[2:0:0:0]    disk    ATA      WDC WD4003FFBX-6 0A83  /dev/sdc
[3:0:0:0]    disk    ATA      WDC WD4003FFBX-6 0A83  /dev/sdd

or if lsblk is installed :

$ lsblk -do NAME,TYPE,SIZE,MODEL
NAME TYPE  SIZE MODEL
sda  disk  477G Samsung_SSD_860_PRO_512GB
sdb  disk  3.7T WDC_WD4003FFBX-68MU3N0
sdc  disk  3.7T WDC_WD4003FFBX-68MU3N0
sdd  disk  3.7T WDC_WD4003FFBX-68MU3N0
0

Another solution

lsblk | grep disk

Output in my case:

sda      8:0    0   1,8T  0 disk 
sdb      8:16   0 931,5G  0 disk 

As you can see, I have two physical disks.

And contrary to fdisk or sfdisk, you don't need root permissions to run it.

1
  • 2
    The cleaner way would be to use lsblk --nodeps. (Add --noheadings to get exactly your output.)
    – Martin
    Commented Sep 13, 2020 at 22:48
0

consider

alias lsblk2='lsblk -o size,fstype,model,name,serial,uuid'

but when having a hardware raid controller, you will only see the block device that the raid controller presents itself as to linux, not all the disks. In this case you need to use smartctl with the -d option.

-2

To return the number of block devices, without fancy tools nor obscure syntax or parameters:

 ls /sys/block/* | grep block | grep sd | wc -l

In my local test cases, 47 on my biggest war-machine and 1 on my laptop.

2
  • 3
    This is off by 500% on one of my systems (Ubuntu 12.04) and by 200% on another system.
    – Anthon
    Commented Apr 7, 2014 at 12:03
  • "number of block devices" was not the question. Commented Jan 22, 2020 at 12:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .