LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 03-10-2010, 05:21 PM   #1
dbrazeau
Member
 
Registered: Aug 2009
Distribution: Fedora, OpenSuse, DENX Embedded Linux
Posts: 178

Rep: Reputation: 28
Calculate usable bytes on a disk partition?


How do you calculate the number of usable bytes on a disk partition? When I do an fdisk -l I get this:

Disk /dev/md0: 192.0 GB, 192069500928 bytes
2 heads, 4 sectors/track, 46891968 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

Device Boot Start End Blocks Id System
/dev/md0p1 1 23445984 93783935+ 83 Linux
/dev/md0p2 23445985 46891968 93783936 83 Linux

The number of usable bytes for /dev/md0 is clearly displayed as 192069500928 bytes. Also calculating the number of bytes form the number of cylinders seems to be valid as well (192069500928 = 46891968 * 4096). My test program is happy when trying to access all 192069500928 bytes. When I try to do the same calculation on /dev/md0p2 I get (46891968-23445985)*4096 = 96034746368 bytes. Even though this value seems reasonable, it doesn't seem like all 96034746368 bytes are usable since my test program gets errors when trying to access all 96034746368 bytes.

Does anyone know how to calculate the number "usable" bytes on a disk partition?

Last edited by dbrazeau; 03-10-2010 at 08:05 PM.
 
Old 03-10-2010, 05:53 PM   #2
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,201

Rep: Reputation: 397Reputation: 397Reputation: 397Reputation: 397
not sure if this is what you are looking for but
df -h
will show statistics about what file systems are mounted, how much is used and how much is free etc...
eg
Code:
hopper@hopper-desktop:~$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             147G   91G   49G  66% /
udev                  2.0G  328K  2.0G   1% /dev
none                  2.0G  7.0M  2.0G   1% /dev/shm
none                  2.0G  244K  2.0G   1% /var/run
none                  2.0G  4.0K  2.0G   1% /var/lock
none                  2.0G     0  2.0G   0% /lib/init/rw
/dev/sda1              99M   79M   16M  84% /boot
/dev/sdc1              74G   18G   53G  25% /media/music
/dev/sdb2             143G  103G   33G  76% /media/stuff
/dev/sdd1             459G  403G   33G  93% /media/videos
user259713@172.16.0.21:/home/user259713/www
                      144G  9.0G  128G   7% /mnt/testsite
user259713@172.16.0.21:/home/user259713/backend
                      144G  9.0G  128G   7% /mnt/modules
user874-3985@172.16.0.22:/home/user874-3985/www
                      100G   37G   58G  39% /mnt/website
 
Old 03-10-2010, 06:33 PM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
The hair to be split is:
Do you want the useable bytes on the partition or the useable bytes in the filesystem that is on the partition?

Keep in mind that data gets stored in blocks, and a 1 byte file will take more space than you might have assumed.
 
Old 03-10-2010, 07:11 PM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,039

Rep: Reputation: 1913Reputation: 1913Reputation: 1913Reputation: 1913Reputation: 1913Reputation: 1913Reputation: 1913Reputation: 1913Reputation: 1913Reputation: 1913Reputation: 1913
Further to this, depending on the filesystem, you may (or not) have reserved blocks, and you will certainly have metadata that is stored in the filesystem.
dumpe2fs will give you some idea of the type of things you need to account for in ext2/3/4.
 
Old 03-10-2010, 07:36 PM   #5
dbrazeau
Member
 
Registered: Aug 2009
Distribution: Fedora, OpenSuse, DENX Embedded Linux
Posts: 178

Original Poster
Rep: Reputation: 28
No I am not referring to a filesystem. I want to know the usable bytes on a raw block device partition.

Last edited by dbrazeau; 03-10-2010 at 08:01 PM.
 
Old 03-10-2010, 11:09 PM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Originally Posted by dbrazeau View Post
No I am not referring to a filesystem. I want to know the usable bytes on a raw block device partition.
Write all zeroes to the partition using dd---it will tell you exactly how many bytes it wrote.
For partition sda3:

Code:
dd if=/dev/zero of=/dev/sda3
If it's a large partition, plan on doing dinner and a movie while it's working.
Or--read the partition into a file:
Code:
dd if=/dev/sda3 of=/<path>/sda3.img
The size of the file = the # of useable bytes on the partition.

In the latter case, you obviously will need a lot of space somewhere to write the image file.

Last edited by pixellany; 03-10-2010 at 11:23 PM. Reason: Correction
 
Old 03-10-2010, 11:37 PM   #7
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,039

Rep: Reputation: 1913Reputation: 1913Reputation: 1913Reputation: 1913Reputation: 1913Reputation: 1913Reputation: 1913Reputation: 1913Reputation: 1913Reputation: 1913Reputation: 1913
Should work - I might be inclined to test the math on a "real" device though ...
 
Old 03-10-2010, 11:42 PM   #8
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
I prefer using "fdisk -lu". This will show the results in 512 byte blocks. This eliminates rounding errors.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
how to calculate the bytes-per-inodes value? z@ki Red Hat 3 02-24-2010 03:17 PM
Space in Bytes on a partition MaxistXXL Linux - Hardware 3 04-14-2007 12:58 PM
creating usable partition tw001_tw Slackware 2 06-01-2004 01:43 PM
Cant get fdisk or cfdisk to partition my 20gig Bytes disk Heath Linux - Newbie 3 05-19-2004 06:08 AM
Widows partition and usb devices not usable by users! Menokh Linux - General 2 03-11-2004 08:16 PM


All times are GMT -5. The time now is 12:31 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration