Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

4 Answers 4

up vote 6 down vote accepted

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.

share|improve this answer
    
Hey, code formatting. Thanks. –  ChimneyImp Jul 31 '12 at 20:33

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.

share|improve this answer
    
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" –  sapeurfaire Jul 31 '12 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 '12 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? –  sapeurfaire Jul 31 '12 at 18:06
    
I am trying to find a disk that I think is already there. –  Arpssss Jul 31 '12 at 18:16

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

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:~# 
share|improve this answer
    
-S is not a valid option on debian wheezy/sid or Ubuntu 12.10. Without it, however, lsblk displays a nice forest-like output. –  dezso Mar 31 at 9:51

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.