背景
移动魔百盒刷 HiNAS 系统后,由于魔百盒本身只有 8G 存储,插了个 U盘,格式化成
ext4
挂载到系统。查看磁盘信息,发现挂载的 U盘Used + Avail ≠ Size
。原因: Linux 系统中,ext 文件系统(包括 ext2、ext3、ext4)都会默认预留
5%
的磁盘空间,用于 root 用户维护系统或记录系统关键日志使用。因此 used 空间加 avail 空间不等于磁盘大小。我们可以通过tune2fs
来改变5%
的默认设置,比如只预留1%
的空间。可不可以设成0%
呢?当然可以,但是不推荐。
root@hinas:/mnt# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 6.6G 2.6G 3.8G 41% /
devtmpfs 427M 0 427M 0% /dev
tmpfs 428M 0 428M 0% /dev/shm
tmpfs 86M 2.6M 84M 3% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 428M 0 428M 0% /sys/fs/cgroup
tmpfs 428M 8.0K 428M 1% /tmp
/dev/sda1 57G 53M 54G 1% /mnt/sda1
tmpfs 86M 0 86M 0% /run/user/0
修改 ext 预留空间
可以通过 tune2fs -m
命令来改变保留的空间。
# 查看磁盘详细信息
root@hinas:/mnt# tune2fs -l /dev/sda1
tune2fs 1.45.5 (07-Jan-2020)
Filesystem volume name: <none>
Last mounted on: <not available>
Filesystem UUID: e537ae14-0f54-4324-8ca9-c4f0c381b9bc
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 metadata_csum
Filesystem flags: unsigned_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 3801088
Block count: 15179520
Reserved block count: 758976 # 这个就是预留的块数量信息
Free blocks: 14862053
Free inodes: 3801077
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 15 09:05:16 2024
Last mount time: Mon Jan 15 10:00:26 2024
Last write time: Mon Jan 15 11:46:25 2024
Mount count: 2
Maximum mount count: -1
Last checked: Mon Jan 15 09:05:16 2024
Check interval: 0 (<none>)
Lifetime writes: 1189 MB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
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: 5900f364-bda3-452e-bbd1-8aea1e297dbd
Journal backup: inode blocks
Checksum type: crc32c
Checksum: 0xb6035018
# 把 /dev/sda1 的保留空间设为 1%
root@hinas:/mnt# tune2fs -m 1 /dev/sda1
tune2fs 1.45.5 (07-Jan-2020)
Setting reserved blocks percentage to 1% (151795 blocks)
# 查看修改后磁盘信息
root@hinas201:/mnt# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 6.6G 2.6G 3.8G 41% /
devtmpfs 427M 0 427M 0% /dev
tmpfs 428M 0 428M 0% /dev/shm
tmpfs 86M 2.6M 84M 3% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 428M 0 428M 0% /sys/fs/cgroup
tmpfs 428M 8.0K 428M 1% /tmp
/dev/sda1 57G 53M 57G 1% /mnt/sda1
tmpfs 86M 0 86M 0% /run/user/0
评论区