Click to See Complete Forum and Search --> : How many 4096 byte blocks on disk?
glitch003
08-13-2011, 01:40 AM
Hi, I want to find out how many 4096 byte blocks there are on my disk. I used df -B 4096 and it gave me a number but I'm not sure it's correct as I can use dd to read past what should be the final block.
So I do df -B 4096 and it reports this result:Filesystem 4K-blocks Used Available Use% Mounted on
/dev/sda1 15618840 13190294 1635137 89% /
But when I use dd to go past that block, it doesn't report an error or anything. The command I'm using is dd if=/dev/sda1 bs=4096 count=1 skip=15618841
How can I know that I'm really reading the very last block on the drive?
Thanks!!
saikee
08-13-2011, 05:39 AM
I think if sda1 has some overhead, like the filing indexing system etc, occupying the front end and the actual file storage is shorter than the length of sda1.
Here is my own example. My sda1 occupies from block 1 to 15400th block (1 block=1 cylinder=8225280 byte).
saikee@saikee-desktop:~$ sudo fdisk -l /dev/sda
[sudo] password for saikee:
Disk /dev/sda: 128.0 GB, 128035676160 bytes
255 heads, 63 sectors/track, 15566 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: 0xde00600d
Device Boot Start End Blocks Id System
/dev/sda1 * 1 15400 123700468+ 83 Linux
/dev/sda2 15401 15566 1333364+ 5 Extended
/dev/sda5 15401 15566 1333363+ 82 Linux swap / Solaris
However if I do a df I get
saikee@saikee-desktop:~$ df -B 8225280
Filesystem 8.3MB-blocks Used Available Use% Mounted on
/dev/sda1 15159 3449 10940 24% /
none 381 1 381 1% /dev
none 382 1 381 1% /dev/shm
none 382 1 382 1% /var/run
none 382 0 382 0% /var/lock
none 382 0 382 0% /lib/init/rw
/dev/sdb58 43453 13157 28088 32% /media/7f5e7b46-3579-415f-83f5-8b2e79a6c9c7
/dev/sdb58 43453 13157 28088 32% /mnt/sdb58
/dev/sdb3 59844 41042 15763 73% /mnt/sdb3
The file storage length of my sda1 is only 15159 blocks. This suggests the overhead section of the partition is 241 block long or 15% of the partition space.
When I using dd to display the contents of sda1 it complaints if the number of block exceeds the physical limit.
saikee@saikee-desktop:~$ sudo dd if=/dev/sda1 bs=8225280 count=1 skip=15400
dd: `/dev/sda1': cannot skip: Invalid argument
0+0 records in
0+0 records out
0 bytes (0 B) copied, 6.3942e-05 s, 0.0 kB/s
However I get one block displayed by dd if I skip 15399 blocks indicating the physical limit of the partition.
Thus the maximum block size you see in df does not corresponds to the end of the partition.
glitch003
08-13-2011, 06:43 AM
This is exactly what I wanted to know. Thank you very much!!