Filesystems

ext4:如何計算文件系統空間?

  • February 1, 2018

我最近格式化了一個 1.5 TB 的驅動器,打算用 ext4 替換 ntfs。

然後我注意到我保存的文件不適合新分區。

df:

ext4 (ext3 & ext2 show the same behavior)
Filesystem      1K-blocks   Used  Available Use% Mounted on
/dev/sdb1      1442146364   71160 1442075204    1% /media/Seagate

ntfs (similar to all other options that gparted offers):
/dev/sdb1      1465137148  110700 1465026448    1% /media/Seagate

1K 塊的差異意味著明顯減少了 22 GiB 的可用空間。

我已經執行了

tune2fs -O \^has_journal
tune2fs -r 0
tune2fs -m 0

毫不奇怪,沒有效果,因為這不會影響不存在的塊。

儘管如此,fdisk 仍報告 ext4 分區覆蓋了整個磁碟。

fdisk -l /dev/sdb:

WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.

Disk /dev/sdb: 1500.3 GB, 1500301910016 bytes
255 heads, 63 sectors/track, 182401 cylinders, total 2930277168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
  Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1  2930277167  1465138583+  ee  GPT

因此,例如 resize2fs 報告說“無事可做!”

dumpe2fs -h /dev/sdb1:
dumpe2fs 1.41.14 (22-Dec-2010)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          d6fc8971-89bd-4c03-a7cd-abdb945d2173
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      ext_attr resize_inode dir_index filetype extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash 
Default mount options:    (none)
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              91578368
Block count:              366284288
Reserved block count:     0
Free blocks:              360518801
Free inodes:              91578357
First block:              0
Block size:               4096
Fragment size:            4096
Reserved GDT blocks:      936
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8192
Inode blocks per group:   512
Flex block group size:    16
Filesystem created:       Sat May 21 17:12:04 2011
Last mount time:          Sat May 21 17:15:30 2011
Last write time:          Sat May 21 17:24:32 2011
Mount count:              1
Maximum mount count:      32
Last checked:             Sat May 21 17:12:04 2011
Check interval:           15552000 (6 months)
Next check after:         Thu Nov 17 16:12:04 2011
Lifetime writes:          1372 MB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:           256
Required extra isize:     28
Desired extra isize:      28
Default directory hash:   half_md4
Directory Hash Seed:      c334e6ef-b060-45d2-b65d-4ac94167cb09
Journal backup:           inode blocks

什麼在使用那個缺失的空間?

讓我們來看看。設備大小為 1,465,138,583½ kB = 1,500,301,909,504 B。文件系統由 366,284,288 個塊組成,每個塊 4096 B,即 1,500,300,443,648 B。我不知道剩餘的 1,465,856 B(1.4 MB)用於什麼(超級塊的附加副本) ? 我知道引導載入程序的開頭有幾 kB 的空間。)。

文件系統包含 91,578,368 個 inode,每個 256 字節,佔用 23,444,062,208 B(約 22 GB,提示,提示)。然後文件內容有 1,442,146,364 kB = 1,476,757,876,736 B。這佔 23,444,062,208 B + 1,476,757,876,736 B = 1,500,201,938,944 B。剩餘的大小是 98,504,704 B = 24,029 個塊,這是期刊大小的正確範圍。

如您所見,一切都已計算在內。(好吧,幾乎所有內容,但我們說的是兆字節,而不是千兆字節。)

引用自:https://unix.stackexchange.com/questions/13547