Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
The original question didn't specify any particular unix variant, and hardware management is obviously highly variant-dependent. – Gilles Dec 6 '10 at 18:51
@gilles yeah I was at work when I wrote it, so I clarified after I got home and thought about it. – xenoterracide Dec 7 '10 at 1:11
1  
Depending on what you're doing, udisks. – derobert Oct 3 '12 at 17:06

7 Answers

up vote 20 down vote accepted

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 undr /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.

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.

share|improve this answer
1  
Ooo; that Rosetta Stone site is excellent – Michael Mrozek Dec 6 '10 at 15:22

How about

lshw -class disk
share|improve this answer
1  
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. – xenoterracide Dec 6 '10 at 8:23

@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 
share|improve this answer

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
share|improve this answer

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
share|improve this answer
Use fdisk -l /dev/sd? or fdisk -l /dev/hd? to avoid bring in dm devices. – laebshade Feb 11 '12 at 23:23

lshw is provided by lshw-* package.

yum install lshw* 

Running above command as a root will install the package.

lshw -class disk will work now.

share|improve this answer
lshw has already been mentioned. – Mat Nov 20 '12 at 11:56

This worked for me:

fdisk -l 2>/dev/null | grep "Disk \/" | grep -v "\/dev\/md" | awk '{print $2}' | sed -e 's/://g'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.