16

What is the command line command to get the number of physical disks in Linux Server and how much space is used on each?

6 Answers 6

13

sudo fdisk -l will list your disks and a bunch of stats about them, including the partitions. The disks are generally in the form of /dev/sdx and partitions /dev/sdxn, where x is a letter and n is a number (so sda is the first physical disk and sda1 is the first partition on that disk).

sudo df -h gives you the size and usage stats per partition. Drop the -h and you get usage in blocks, with it it's human readable.

I put the sudos in there because I got no output from fdisk and only partial output from df when I ran the commands as a regular user, I suppose because the commands read from somewhere off limits to non-admins.

1
  • you should add parted is used instead fdisk for GPT partitions. just to enforce your good answer. Sep 9, 2015 at 15:26
8

If you really want to display only the hardware, and not RAID volumes and partitions that might be seen by the OS as physical drives. You might want to try lshw

lshw -class disk -short
H/W path        Device      Class       Description
===================================================
/0/1/0.0.0      /dev/cdrom  disk        DVD-RAM GSA-H55N
/0/1/0.1.0      /dev/sda    disk        160GB ST3160021A
/0/2/0.0.0      /dev/sdb    disk        160GB ST3160815AS

Or a bit much verbose

lshw -class disk
  *-cdrom                 
   description: DVD-RAM writer
   product: DVD-RAM GSA-H55N
   vendor: HL-DT-ST
   physical id: 0.0.0
   bus info: scsi@0:0.0.0
   logical name: /dev/cdrom
   logical name: /dev/sr0
   version: 1.04
   serial: [
   capabilities: removable audio cd-r cd-rw dvd dvd-r dvd-ram
   configuration: ansiversion=5 status=nodisc
  *-disk
   description: ATA Disk
   product: ST3160021A
   vendor: Seagate
   physical id: 0.1.0
   bus info: scsi@0:0.1.0
   logical name: /dev/sda
   version: 8.01
   serial: 5JS97CFY
   size: 149GiB (160GB)
   capabilities: partitioned partitioned:dos
   configuration: ansiversion=5 sectorsize=512 signature=000f3a2f
  *-disk
   description: ATA Disk
   product: ST3160815AS
   vendor: Seagate
   physical id: 0.0.0
   bus info: scsi@2:0.0.0
   logical name: /dev/sdb
   version: 3.AA
   serial: 9RX7AK36
   size: 149GiB (160GB)
   capabilities: partitioned partitioned:dos
   configuration: ansiversion=5 sectorsize=512 signature=000b6d91
6

I think the easiest way (at least concerning parsing effort) on a recent Linux installation would be

$ lsblk -S

which outputs something like this:

tremendous:~# lsblk -S
NAME HCTL       TYPE VENDOR   MODEL             REV TRAN
sda  0:0:0:0    disk ATA      WDC WD5000AUDX-6 01.0 sata
sdb  1:0:0:0    disk ATA      WDC WD5000AUDX-6 01.0 sata
tremendous:~# 
1
  • -S is not a valid option on debian wheezy/sid or Ubuntu 12.10. Without it, however, lsblk displays a nice forest-like output. Mar 31, 2014 at 9:51
3

Depending on your distribution (in this case Centos 7) lsblk -d will show you (for example) three physical disks.

NAME MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sr0   11:0    1  1024M  0 rom  
sr1   11:1    1  1024M  0 rom  
sdf    8:80   0 372.6G  0 disk 
sde    8:64   0 372.6G  0 disk 
sdg    8:96   0   1.8T  0 disk 

iostat will also show similar results (ignore the dm devices as they are part of LVM)

Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
sdf               1.85        41.74        53.80   68524791   88335482
sde               0.00         0.01         0.00      20219          0
dm-0              7.75        40.17        52.24   65945186   85767784
dm-1              0.31         0.94         1.56    1543416    2567312
sdg               0.86         1.89       171.04    3096240  280813864
2

You'd think there'd be a simple answer to this, but it actually depends on what you mean by "physical disk". iSCSI volumes and RAID devices (for example) appear as physical disks, but the tools one uses to examine these differ.

If you just mean a plain SATA or SCSI drive attached directly to a host controller on the motherboard of the server, you're looking for actively used devices located at /dev/sdN, so you can grep through your dmesg for them (dmesg | grep sd) or you could look in /dev/disk/by-id or yet again you can look in /proc/diskstats.

Once you've identified the /dev/ entry for devices that are present, you can use the appropriate tool to check for free space. This again depends on other info, such as how they were partitioned, whether they use the lvm, and so on.

4
  • One other point: my answer was assuming that you might want to partition a disk, modify it's lvm layout, or create/modify filesystems. If you just want to know how much free space is available on already allocated disk, run the command "df -h" Jul 31, 2012 at 17:50
  • Actually, this question is motivated by stackoverflow.com/questions/11744730/…. I want to know actually, how many separate disk systems are in our server machine. (Tomas Answer).
    – Arpssss
    Jul 31, 2012 at 17:53
  • How many are available, or how many are in use? In other words, are you looking for a place to put another disk, or are you trying to find a disk you think is already there? Jul 31, 2012 at 18:06
  • I am trying to find a disk that I think is already there.
    – Arpssss
    Jul 31, 2012 at 18:16
1

If you just want to know the Physical Disks in the system.

lsblk | grep -e ^NAME -e disk

which outputs something like:

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

sda 8:0 0 40G 0 disk

You must log in to answer this question.

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