Linux EXT4檔案系統TF卡空間容量顯示和計算

王二車發表於2019-02-18

以32GB的EXT4檔案系統為例進行計算。

驅動資訊

usb 1-1.3: new full-speed USB device number 4 using ci_hdrc
scsi 0:0:0:0: Direct-Access     Generic  STORAGE DEVICE   0819 PQ: 0 ANSI: 6
sd 0:0:0:0: [sda] 62566400 512-byte logical blocks: (32.0 GB/29.8 GiB)
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
 sda: sda1
sd 0:0:0:0: [sda] Attached SCSI removable disk

fdisk檢視資訊

Disk /dev/sda: 32.0 GB, 32033996800 bytes
64 heads, 32 sectors/track, 30550 cylinders, total 62566400 sectors
Units = sectors of 1 * 512 = 512 bytes

   Device Boot      Start         End      Blocks  Id System
/dev/sda1            2048    62566399    31282176  83 Linux

SD卡容量32GB,實際可儲存容量為32033996800 bytes=31283200KB (62566400 * 512 = 29.833984375GB)

檔案系統容量為31282176 KB,start 2048前面儲存的是分割槽資訊,佔用2048*512=1024KB

掛載

/dev/sda1 on /mnt/sda1 type ext4 (rw,relatime,data=ordered)

容量df

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1             30659500     45232  29033776   0% /mnt/sda1

容量單位是1k,所以就是數字後面加k;

容量大小為30659500 KB (純檔案資料塊容量)

使用大小為45232 KB(實際檔案資料塊173K + 還有什麼佔用資料塊?)

空閒大小為29033776 KB(剩餘資料塊,不包含預留的空間

隱藏大小為30659500  -  29079008 =1580492 KB (就是檔案系統預留空間)

dumpe2fs資訊

資料塊總容量:7820544 * 4K = 31282176

使用大小:667756K(檔案系統資訊資料 + 實際檔案資料塊大小)

空閒容量:7653605 * 4K = 30614420 

預留容量:391027 * 4K = 1564108

root@www:~# /mnt/emmc/dumpe2fs /dev/sda1 -h
dumpe2fs 1.44.5 (15-Dec-2018)
Filesystem volume name:   <none>
Last mounted on:          /mnt/sda1
Filesystem UUID:          d200bbcf-7fa9-40a7-b69a-8891ed917744
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize
Filesystem flags:         unsigned_directory_hash 
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              1957888
Block count:              7820544
Reserved block count:     391027
Free blocks:              7653605
Free inodes:              1957877
First block:              0
Block size:               4096
Fragment size:            4096
Group descriptor size:    64
Reserved GDT blocks:      1024
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8192
Inode blocks per group:   512
Flex block group size:    16
Filesystem created:       Mon Jan 21 10:26:05 2019
Last mount time:          Thu Jan  3 18:25:12 2019
Last write time:          Thu Jan  3 18:25:12 2019
Mount count:              1
Maximum mount count:      -1
Last checked:             Mon Jan 21 10:26:05 2019
Check interval:           0 (<none>)
Lifetime writes:          612 MB
Reserved blocks uid:      0 (user unknown)
Reserved blocks gid:      0 (group unknown)
First inode:              11
Inode size:	          256
Required extra isize:     32
Desired extra isize:      32
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      1a43adc3-ca82-4a24-bb2a-8195f1c7aabb
Journal backup:           inode blocks
Journal features:         journal_64bit
Journal size:             128M
Journal length:           32768
Journal sequence:         0x00000002
Journal start:            1

 容量示意圖

總結

df實時顯示記憶體中的ext4檔案系統資料塊容量資訊,空閒容量不包括預留容量,預留容量在容量用完後給超級使用者使用的;dumpe2fs是讀取磁碟上面的超級塊資訊,不能實時更新,應該是在解除安裝或掛載時更新容量資料。

 

相關文章