How do I find out what hard disks are in the system?
Solution 1
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.
Solution 2
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.
Solution 3
How about
lshw -class disk
Solution 4
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
Solution 5
@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
Related videos on Youtube
xenoterracide
Former Linux System Administrator, now full time Java Software Engineer.
Updated on September 17, 2022Comments
-
xenoterracide almost 2 years
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.-
Admin over 13 yearsThe original question didn't specify any particular unix variant, and hardware management is obviously highly variant-dependent.
-
Admin over 13 years@gilles yeah I was at work when I wrote it, so I clarified after I got home and thought about it.
-
Admin over 11 yearsDepending on what you're doing, udisks.
-
Admin over 6 yearsI 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
andmount
. More information at binarytides.com/linux-commands-hardware-info.
-
-
xenoterracide over 13 yearsnot 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. -
Michael Mrozek over 13 yearsOoo; that Rosetta Stone site is excellent
-
laebshade over 12 yearsUse
fdisk -l /dev/sd?
orfdisk -l /dev/hd?
to avoid bring in dm devices. -
NicBright almost 11 yearsIt should be noted that the
smartctl
way even works on Cygwin, +1! Just loop over possible device names and see ifsmartctl
returns that the drive supports SMART. -
André van Schoubroeck over 10 yearsFor some reason, lshw does not list hard disks.
-
Anthon about 10 yearsThis is off by 500% on one of my systems (Ubuntu 12.04) and by 200% on another system.
-
Volker Siegel almost 10 yearsWhen not run as root, it lists no disks, but also gives no error.
-
Lahi2010 about 9 yearsIf you only need the physical disks, use
lsblk -d
,-d
means no dependency message listed. -
tuk0z almost 9 yearsIndeed =) $
lsblk -ido KNAME,TYPE,SIZE,MODEL
(part ofutil-linux
which is part ofbase
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"). -
Anthony over 7 yearsbash: lshw: command not found
-
Steven Lu over 4 yearsskips NVMe SSDs
-
Jürgen A. Erhard over 4 years"number of block devices" was not the question.
-
João Pimentel Ferreira almost 4 years
sudo lshw -class disk
made my day, simple and intuitive output. -
Martin almost 4 yearsThe cleaner way would be to use
lsblk --nodeps
. (Add--noheadings
to get exactly your output.)