A few days ago, I ran
I found the answer after consulted Google using columns of
The discrepancy comes from Reserved Blocks. From what I read, Extended File System (ext) since ext2, has such feature and the default reserved blocks are 5% of total blocks, marked by
5% (3.6G) is really a lot, even for my tiny harddrive. Imagine a 1TB harddrive, that's 50G, almost as big as my harddrive. There are two ways to set the reserved amount of blocks using
For percentage using
df -h for no reasons as I usually did, the output as follows:$ df -h Filesystem Size Used Avail Use% Mounted on rootfs 72G 49G 20G 72% / [...]To my amaze or not to, the part of my brain which manages mathematics finally told me that 72G != 49G + 20G. I have been using Linux full-time for more than five years and probably have run
df for a thousand times if not less. Finding the inconsistency is not really what confused me but why it took me so long to see the numbers. I found the answer after consulted Google using columns of
df, ie. "df size used avail". Yes, that's how I found the answer at my first try. I am still a master of Google.The discrepancy comes from Reserved Blocks. From what I read, Extended File System (ext) since ext2, has such feature and the default reserved blocks are 5% of total blocks, marked by
mke2fs.-m reserved-blocks-percentage Specify the percentage of the filesystem blocks reserved for the super-user. This avoids fragmentation, and allows root-owned daemons, such as syslogd(8), to continue to function correctly after non-privileged processes are prevented from writing to the filesystem. The default percentage is 5%.To see how many blocks are reserved, you can use
tune2fs:$ sudo tune2fs -l /dev/sda3 | grep -i block Block count: 19037025 Reserved block count: 951851 Free blocks: 6019654 [...] Block size: 4096 [...]In my case, it's 19,037,025 * 0.05 = 951,851.25. Round to 951,851 blocks as you see in the output above. To do the math correctly, use 1K-blocks for calculations:
$ df | head -2 Filesystem 1K-blocks Used Available Use% Mounted on rootfs 74953252 50727968 20417880 72% /The reserved size is 951,851 * 4 (Block size, 4096 = 4*1K-blocks) + 507,279,68 + 204,178,880 = 74,953,252. Mystery solved!
5% (3.6G) is really a lot, even for my tiny harddrive. Imagine a 1TB harddrive, that's 50G, almost as big as my harddrive. There are two ways to set the reserved amount of blocks using
tune2fs, one by percentage, another by number of blocks.For percentage using
-m, the following code set to 1%, you can assign a float number.$ sudo tune2fs -m 1 /dev/sda3 tune2fs 1.42 (29-Nov-2011) Setting reserved blocks percentage to 1% (190370 blocks)Or, the specific amount of block using
-r, the following code set to around 500MB in 4K block size.$ sudo tune2fs -r 129008 /dev/sda3 tune2fs 1.42 (29-Nov-2011) Setting reserved blocks count to 129008When creating an ext2/ext3/ext4 filesystem using
mke2fs/mkfs.ext2/mkfs.ext3/mkfs.ext4, you can only use -m to specify a reversed percentage.
0 comments:
Post a Comment