LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-09-2013, 12:12 PM   #1
orenzp
LQ Newbie
 
Registered: Jul 2006
Location: Israel
Distribution: Ubuntu
Posts: 3

Rep: Reputation: 0
Command to list the amount of unused space on a physical disk.


Hi,
Im new to Ubuntu or Linux and i'm looking for away to check the hard disk free space. I know about df -h, but that only shows me free space inside mounted partitions. I want to see unused disks space on the physical hard drive like /dev/sda not /dev/sda1
Getting this information in fdisk is hard because its only shows the blocks that are used.

Example
If i a 500GB Disk and i create 1 partition that's 100GB in size, which command would i run so i can see the 400GB that are unused on the disk?

I'm a Windows SysAdmin that's trying to convert so please dont hate me.

Thanks
O.Z
 
Old 07-09-2013, 12:25 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
You can use fdisk and use the p command to view all partitions, that also shows the size of the drive. Just be careful you don't write to your partition table and screw up your drive.

Code:
sudo fdisk /dev/sda

Command (m for help): p

Disk /dev/sda: 640.1 GB, 640135028736 bytes
255 heads, 63 sectors/track, 77825 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x1549f232

<more info - deleted>

Command (m for help): q
 
Old 07-09-2013, 12:26 PM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Using df, you are correct in that (1) you will only see partitions which are mounted, and further (2) you will only see partitions which exist. For instance, if you have un-partitioned space on that drive, you will not know about it. Therefore using df and doing the math is not going to always get you the answer. However using fdisk is not recommended to be an everyday thing.
 
1 members found this post helpful.
Old 07-09-2013, 01:44 PM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
There is always the simple "cat /proc/partitions", which will list every partition, and every disk.

In my case:
Code:
$ cat /proc/partitions
major minor  #blocks  name

   8        0  244198584 sda
   8        1    1048576 sda1
   8        2  113185792 sda2
   8        3  113184768 sda3
   8        4          1 sda4
   8        5   16776192 sda5
   8       16 1953514584 sdb
   8       17  976757260 sdb1
   8       18  976757292 sdb2
   8       32  244198584 sdc
   8       33  244196001 sdc1
   8       48   58633344 sdd
   8       49   58629186 sdd1
  11        0    1048575 sr0
For remaining unallocated you do have to do a bit of arithmetic: 1953514584 blocks for sdb, 976757260 sdb1, 976757292 sdb2. So sdb1 + sdb2 = 1953514552, difference: 32 blocks unallocated. In this particular case it is to force alignment.

In the case of sda4, it is the "extended" partition header... and that is all it is.

Last edited by jpollard; 07-09-2013 at 01:45 PM.
 
Old 07-11-2013, 05:21 AM   #5
orenzp
LQ Newbie
 
Registered: Jul 2006
Location: Israel
Distribution: Ubuntu
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks guys,
I guess there isn't a simple solution for this. I will use the fdisk.
 
Old 07-11-2013, 05:33 AM   #6
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
or use a graphical partition tool, like gparted

or if it must be cli, then you have cfdisk

Code:
sudo cfdisk /dev/sdX
Note, cfdisk doesn’t handle gpt ( which I didn't know until I did a quick double check it gave human readable numbers )
 
1 members found this post helpful.
Old 07-11-2013, 05:36 AM   #7
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
You can use cfdisk (console tool), or gparted (X window) to get "human readable" free space on drive.
 
Old 07-11-2013, 06:10 AM   #8
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
Quote:
Originally Posted by orenzp View Post
I guess there isn't a simple solution for this.
Don't be so hasty.
Code:
sudo parted /dev/sda "print free"

Last edited by syg00; 07-11-2013 at 06:11 AM. Reason: Ubuntu will need sudo
 
1 members found this post helpful.
Old 07-11-2013, 06:43 AM   #9
Madhu Desai
Member
 
Registered: Mar 2013
Distribution: Rocky, Fedora, Ubuntu
Posts: 541

Rep: Reputation: 153Reputation: 153
There are some GUI tools to check full hard disks used/free space. 6 Great Apps to View Disk Usage in Linux.

But like OP, i'm also looking for a commandline tool, which display HDDs total/used/free disk size regardless of type of filesystem/regular/lvm/alloted/not alloted partitions. Believe me, from past 2-3 months, whenever i am free, i'm hunting for it in internet. still cant find it. All i find is floods of tutorials on 'df' and 'du' in some or other type of script/sed/awk. nothing else. which are by the way are not accurate.

For example, i have three disks, 40GB, 250GB and 1TB.
40GB - Windows 8 (NTFS)
250GB - Backup (NTFS)
1TB -
/boot
/dc (backup ext4)
LVM ( /, /home, /var, /docus, /kumar and swap)

It makes even more difficult that, in those LVM, some space(LVs) are alloted to volume group, some(LVs) are encrypted, some space is still not alloted to volume group. those space that is not still alloted and are encrypted are not shown in df.

Code:
# df -h --total
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg-root    15G  6.4G  7.7G  46% /
tmpfs                 3.9G  1.7M  3.9G   1% /dev/shm
/dev/sdc1             194M   90M   94M  49% /boot
/dev/sdc2             493G  172G  296G  37% /dc
/dev/mapper/vg-home    99G   51G   44G  54% /home
/dev/mapper/vg-var     20G  6.2G   13G  33% /var
/dev/sdb2              37G   32G  6.0G  84% /mnt/Win8
/dev/sda1             234G  226G  8.1G  97% /mnt/Backup
total                 900G  492G  377G  57%

# vgs
  VG   #PV #LV #SN Attr   VSize   VFree  
  vg     1   6   0 wz--n- 431.31g 206.31g

# lvs
  LV    VG   Attr      LSize   Pool Origin Data%  Move Log Cpy%Sync Convert
  home  vg   -wi-ao--- 100.00g                                             
  docus vg   -wi-a----  10.00g                                             
  kumar vg   -wi-a----  70.00g                                             
  root  vg   -wi-ao---  15.00g                                             
  swap  vg   -wi-ao---  10.00g                                             
  var   vg   -wi-ao---  20.00g  
Every time i have to calculate total/used/free space i have to grab calculator, unless the box has GUI.

Its so frustrating, that i cannot find how much space i have used and free.

While searching, for that tool, i have found some other tools/script that can be of interest for some:
Code:
# lsscsi
[0:0:0:0]    disk    ATA      Maxtor 6Y250P0   YAR4  /dev/sda 
[0:0:1:0]    disk    ATA      ST340016A        3.19  /dev/sdb 
[2:0:0:0]    disk    ATA      ST31000524AS     JC45  /dev/sdc 
[3:0:0:0]    cd/dvd  ASUS     DRW-2014L1T      1.00  /dev/sr0

# dmesg | grep -i 'sd.*gib'
sd 0:0:0:0: [sda] 490232639 512-byte logical blocks: (250 GB/233 GiB)
sd 0:0:1:0: [sdb] 78163247 512-byte logical blocks: (40.0 GB/37.2 GiB)
sd 2:0:0:0: [sdc] 1953523055 512-byte logical blocks: (1.00 TB/931 GiB)

# fdisk -l | grep 'Disk.*sd'
Disk /dev/sdb: 40.0 GB, 40019582464 bytes
Disk /dev/sdc: 1000.2 GB, 1000203804160 bytes
Disk /dev/sda: 251.0 GB, 250999111168 bytes

# disktype /dev/sdc
--- /dev/sdc
Block device, size 931.5 GiB (1000203804160 bytes)
GRUB boot loader, compat version 3.2, boot drive 0x80
DOS/MBR partition map

Partition 1: 200 MiB (209715200 bytes, 409600 sectors from 2048, bootable)
  Type 0x83 (Linux)
  Ext3 file system
    UUID 5C6011EA-E7CC-4593-8032-DB2963351788 (DCE, v4)
    Last mounted at "/boot"
    Volume size 200 MiB (209715200 bytes, 204800 blocks of 1 KiB)

Partition 2: 500 GiB (536870912000 bytes, 1048576000 sectors from 411648)
  Type 0x83 (Linux)
  Ext3 file system
    UUID 8BE1C7A8-A3DF-4A30-B490-F24654E86911 (DCE, v4)
    Last mounted at "/dc"
    Volume size 500 GiB (536870912000 bytes, 131072000 blocks of 4 KiB)

Partition 3: 431.3 GiB (463122128384 bytes, 904535407 sectors from 1048987648)
  Type 0x8E (Linux LVM)
  Linux LVM2 volume, version 001
    LABELONE label at sector 1
    PV UUID pTrY6w-KuTX-y0uj-a5ei-HpBf-WTa0-9niCl4
    Volume size 431.3 GiB (463122128384 bytes)
    Meta-data version 1

# sfdisk -s
/dev/sdb:  39081623
/dev/sdc: 976761527
/dev/sda: 245116319
/dev/mapper/vg-swap:  10485760
/dev/mapper/vg-root:  15728640
/dev/mapper/vg-var:  20971520
/dev/mapper/vg-home: 104857600
/dev/mapper/vg-kumar:  73400320
/dev/mapper/vg-docus:  10485760
total: 1496889069 blocks
But still no luck on the tool that displays total/used/free space.

Last edited by Madhu Desai; 07-11-2013 at 06:57 AM.
 
Old 07-11-2013, 07:22 AM   #10
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
@mddesai
not sure you have the same issue here,
orenzp was after unallocated space ( syg00's option being the best in my opinion )
you seem concerned with the space you have on filesystems

this might work better for you
Code:
df -h --total /home /var /dc /mnt/*/
as for the unallocated to vg, use what ever you are using to manage them to, well manage them.
and the encrypted stuff.. what encryption are you using?
 
Old 07-12-2013, 07:25 AM   #11
orenzp
LQ Newbie
 
Registered: Jul 2006
Location: Israel
Distribution: Ubuntu
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks Guys,
Firerat and syg00 suggestions where the one that i was looking for.

sudo cfdisk /dev/sda
sudo parted /dev/sda "print free"

Both commands show exactly how much free disk space is available on the hard drive itself.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
No hard disk space where I have 150gb unused in /dev/sda5 Angoni6 Linux - Newbie 23 07-05-2012 03:07 AM
[SOLVED] shell command amount space in disk for mp3 celembor Linux - General 11 07-12-2010 04:41 AM
What I a good amount of disk space to have free? abefroman Linux - Server 2 01-08-2010 03:17 PM
Secure unused disk space wipes, dd and shred Akonbobot Linux - Security 10 03-14-2008 01:01 AM
List Amount of Space Taken Up by Each Directory? halfpower Linux - General 7 02-26-2007 08:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration