18

How do I find out what hard drives are attached to a Linux box? I'm hoping for a single command that can give me a nice list of all ATA/SCSI/etc drives.

I've catted /proc/partitions in the past to do this, but I wonder if that still works if there's a drive with no partitions on it.

10 Answers 10

30

sudo lshw -class disk

gives you everything but the mount point

  *-cdrom                 
       description: CD-R/CD-RW writer
       product: 52MAXX 3252AJ
       vendor: Memorex
       physical id: 0
       bus info: scsi@0:0.0.0
       logical name: /dev/cdrom
       logical name: /dev/cdrw
       logical name: /dev/scd0
       logical name: /dev/sr0
       version: QWS3
       capabilities: removable audio cd-r cd-rw
       configuration: ansiversion=5 status=nodisc
  *-disk:0
       description: SCSI Disk
       product: ZIP 100
       vendor: IOMEGA
       physical id: 0.1.0
       bus info: scsi@0:0.1.0
       logical name: /dev/sda
       version: 12.A
       capabilities: removable
       configuration: ansiversion=5
     *-medium
          physical id: 0
          logical name: /dev/sda
  *-disk:1
       description: ATA Disk
       product: WDC WD800AB-00CB
       vendor: Western Digital
       physical id: 1
       bus info: scsi@1:0.0.0
       logical name: /dev/sdb
       version: 04.0
       serial: WD-WCAA52477019
       size: 74GiB (80GB)
       capabilities: partitioned partitioned:dos
       configuration: ansiversion=5 signature=90909090

sudo lshw -class disk -html

2
  • 3
    I would use "lshw -C disk -C volume" to also include the partitions May 6, 2009 at 5:22
  • and -short to have information easily grep-able
    – drAlberT
    Feb 7, 2013 at 16:13
8

fdisk -l

3
  • One problem I have with with fdisk is that it also shows or errors on dm-crypt devices, or lvm devices, sometimes I like to see the actual disks.
    – Zoredache
    May 5, 2009 at 22:19
  • +1 as the default installes for Ubuntu and Debian I have access to don't have lshw
    – Greg B
    May 29, 2009 at 10:34
  • fdisk -l | grep ^Disk Oct 27, 2014 at 16:24
8

When I run:

# lsblk

it returns tree disk-partition with mountpoints (for those partitions that have):

NAME                             MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                                8:0    0 278.9G  0 disk
+-sda1                             8:1    0   500M  0 part /boot
+-sda2                             8:2    0 278.4G  0 part
  +-vg_devlinux02-lv_root (dm-0) 252:0    0    50G  0 lvm  /
  +-vg_devlinux02-lv_swap (dm-1) 252:1    0    32G  0 lvm  [SWAP]
sdb                                8:16   0  14.6T  0 disk
+-sdb1                             8:17   0  14.6T  0 part
  +-vg_devlinux02-lv_home (dm-2) 252:2    0  12.8T  0 lvm  /home
sr0                               11:0    1  1024M  0 rom
sdc                                8:32   0   2.7T  0 disk
+-sdc1                             8:33   0   128M  0 part
+-sdc2                             8:34   0   2.7T  0 part
sdd                                8:48   0   2.7T  0 disk
+-sdd1                             8:49   0   2.7T  0 part
sde                                8:64   0   2.7T  0 disk
+-sde1                             8:65   0   2.7T  0 part
sdf                                8:80   0   2.7T  0 disk
+-sdf1                             8:81   0   128M  0 part
+-sdf2                             8:82   0   2.7T  0 part
2
  • that's very useful, as it also shows which drives/partitions are assembled into which RAID drives
    – simpleuser
    Feb 1, 2016 at 3:09
  • lsblk works nicely with watch to see when drives are attached, removed, or mounted. This is my currently favorite format: watch lsblk -o tran,name,model,fstype,label,mountpoints,fssize,fsavail,fsused,fsuse%. Here's a tutorial about lsblk that also explains how to define which information to show about drives and their partitions. Aug 31, 2022 at 12:13
7

An alternative to lshw:

hwinfo --disk 

Also has '--short' option, if you're only interested in the /dev and model name and not all the details.

hal9k:~ # hwinfo --disk --short
disk:
  /dev/sda             Hitachi HDT72502
  /dev/sdb             Generic USB SD Reader
  /dev/sdc             Generic USB CF Reader
  /dev/sdd             Generic USB SM Reader
  /dev/sde             Generic USB MS Reader

Long version gives you more details then lshw:

hal9k:~ # hwinfo --disk 
16: IDE 200.0: 10600 Disk                                       
  [Created at block.243]                                        
  UDI: /org/freedesktop/Hal/devices/storage_serial_SATA_Hitachi_HDT7250_VFL104R62EUUTX
  Unique ID: 3OOL.JSHCimqnHw6                                                         
  Parent ID: CvwD.epf1vnVqQVC                                                         
  SysFS ID: /class/block/sda                                                          
  SysFS BusID: 2:0:0:0                                                                
  SysFS Device Link: /devices/pci0000:00/0000:00:05.0/host2/target2:0:0/2:0:0:0       
  Hardware Class: disk                                                                
  Model: "Hitachi HDT72502"                                                           
  Vendor: "Hitachi"                                                                   
  Device: "HDT72502"                                                                  
  Revision: "V5DO"                                                                    
  Serial ID: "VFL104R62EUUTX"                                                         
  Driver: "sata_sis", "sd"                                                            
  Driver Modules: "sata_sis"                                                          
  Device File: /dev/sda                                                               
  Device Files: /dev/sda, /dev/disk/by-id/scsi-SATA_Hitachi_HDT7250_VFL104R62EUUTX, /dev/disk/by-id/ata-Hitachi_HDT725025VLA380_VFL104R62EUUTX, /dev/disk/by-path/pci-0000:00:05.0-scsi-0:0:0:0, /dev/disk/by-id/edd-int13_dev80                                                                                                                                        
  Device Number: block 8:0-8:15                                                                                                                                                     
  BIOS id: 0x80                                                                                                                                                                     
  Geometry (Logical): CHS 30401/255/63                                                                                                                                              
  Size: 488397168 sectors a 512 bytes                                                                                                                                               
  Geometry (BIOS EDD): CHS 484521/16/63                                                                                                                                             
  Size (BIOS EDD): 488397168 sectors                                                                                                                                                
  Geometry (BIOS Legacy): CHS 1023/255/63                                                                                                                                           
  Config Status: cfg=no, avail=yes, need=no, active=unknown                                                                                                                         
  Attached to: #9 (IDE interface)                                                                                                                         

[...]

EDIT:

As for the packages availability. I'm using OpenSUSE 11.1. hwinfo is in the standard repository, while lshw is only available from unofficial one.

2
  • But you need the hwinfo package installed for this to work :'(
    – Andor
    May 6, 2009 at 9:33
  • @Andor: true, but to have lshw you also need to install the package.
    – vartec
    May 6, 2009 at 9:59
4

/proc/diskstats will have stats on all your extant drives, whether or not they have partitions on them.

2

cat /proc/partitions Is working even if there is no partition defined for disk.

My favorite is lsblk which shows very good detail about disks and partitions, and where they mounted. Also file -s /dev/sda can give you simple information too.

2

I like:

lshw -class disk

which lists all disks and storage controllers in the system.

0
# fdisk -l | grep Disk

is used to display list of harddisk on server

0

Not sure if it changed at some point, but using sudo lshw -class disk did not work for me. On my system, Ubuntu 17.10, I needed to use the storage class:

sudo lshw -class storage

0

Alternatively, you can use duf that conveniently groups devices by their type and shows disk usage per default.

Example output:

  ╭────────────────────────────────────────────────────────────────────╮
  │ 2 local devices                                                    │
  ├────────────┬────────┬────────┬────────┬────────┬──────┬────────────┤
  │ MOUNTED ON │   SIZE │   USED │  AVAIL │  USE%  │ TYPE │ FILESYSTEM │
  ├────────────┼────────┼────────┼────────┼────────┼──────┼────────────┤
  │ /          │ 808.0G │ 443.1G │ 323.8G │  54.8% │ ext4 │ /dev/sda3  │
  │ /sda1      │ 108.0G │  59.5G │  43.9G │  55.1% │ ext4 │ /dev/sda1  │
  ╰────────────┴────────┴────────┴────────┴────────┴──────┴────────────╯
  ╭─────────────────────────────────────────────────────────────────────╮
  │ 5 special devices                                                   │
  ├──────────────┬──────┬────────┬───────┬────────┬────────┬────────────┤
  │ MOUNTED ON   │ SIZE │   USED │ AVAIL │  USE%  │ TYPE   │ FILESYSTEM │
  ├──────────────┼──────┼────────┼───────┼────────┼────────┼────────────┤
  │ /dev         │ 7.7G │     0B │  7.7G │        │ devtmp │ dev        │
  │              │      │        │       │        │ fs     │            │
  │ /dev/shm     │ 7.8G │   5.1M │  7.8G │   0.1% │ tmpfs  │ tmpfs      │
  │ /run         │ 7.8G │   1.3M │  7.8G │   0.0% │ tmpfs  │ run        │
  │ /run/user/10 │ 1.6G │  28.0K │  1.6G │   0.0% │ tmpfs  │ tmpfs      │
  │ 00           │      │        │       │        │        │            │
  │ /tmp         │ 7.8G │ 192.0K │  7.8G │   0.0% │ tmpfs  │ tmpfs      │
  ╰──────────────┴──────┴────────┴───────┴────────┴────────┴────────────╯

You must log in to answer this question.

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