LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Calculate usable bytes on a disk partition? (https://www.linuxquestions.org/questions/linux-newbie-8/calculate-usable-bytes-on-a-disk-partition-794526/)

dbrazeau 03-10-2010 04:21 PM

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?

frieza 03-10-2010 04:53 PM

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


pixellany 03-10-2010 05:33 PM

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.

syg00 03-10-2010 06:11 PM

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.

dbrazeau 03-10-2010 06:36 PM

No I am not referring to a filesystem. I want to know the usable bytes on a raw block device partition.

pixellany 03-10-2010 10:09 PM

Quote:

Originally Posted by dbrazeau (Post 3893553)
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.

syg00 03-10-2010 10:37 PM

Should work - I might be inclined to test the math on a "real" device though ...

jschiwal 03-10-2010 10:42 PM

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


All times are GMT -5. The time now is 09:22 AM.