EXT4文件系统特性说明

在嵌入式设备中,针对EMMC使用的文件系统,很多都使用了EXT4格式,下面介绍几个实用的功能。

首先获取EXT4的特性:

复制代码
root@test:~# dumpe2fs /dev/mmcblk0p15 
dumpe2fs 1.46.5 (30-Dec-2021)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          64783e92-dd8f-4eed-bd6d-58dbce16e654
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:              708528
Block count:              2833920
Reserved block count:     0
Free blocks:              2762800
Free inodes:              708514
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:         8144
Inode blocks per group:   509
Flex block group size:    16
Filesystem created:       Thu Jan  1 08:00:39 1970
Last mount time:          Mon Dec  8 22:16:37 2025
Last write time:          Mon Dec  8 22:16:37 2025
Mount count:              2
Maximum mount count:      -1
Last checked:             Thu Jan  1 08:00:39 1970
Check interval:           0 (<none>)
Lifetime writes:          177 MB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)

这是读的EXT4超级块的信息,从这里我们可以得到好多信息,挑几个说明一下:

1、Filesystem features:

文件系统支持的特性,比如has_journal large_file等

2、Errors behavior:

文件系统出错时采用的方式,有以下几个选择:

continue:忽略错误,继续运行

remount-ro:将文件系统重新挂载为只读

panic:触发内核 panic(系统崩溃)

一般推荐使用remount-ro的方式

这个特性可以通过tune2fs工具来修改,如下:

1)查看当前特性

bash 复制代码
root@test:~# tune2fs -l /dev/mmcblk0p15 | grep "Errors behavior"
Errors behavior:          Continue

2)修改remount-ro

bash 复制代码
root@test:~# tune2fs -e remount-ro /dev/mmcblk0p15
tune2fs 1.46.5 (30-Dec-2021)
Setting error behavior to 2
root@test:~# tune2fs -l /dev/mmcblk0p15 | grep "Errors behavior"
Errors behavior:          Remount read-only 

重启后生效

3)手动破坏分区进行试验

bash 复制代码
root@test:~# dd if=/dev/zero of=/dev/mmcblk0p15 count=3
3+0 records in
3+0 records out
1536 bytes (1.5 kB, 1.5 KiB) copied, 0.000317058 s, 4.8 MB/s 
root@test:~# echo 11111 > /second/2.txt
[   95.782427] EXT4-fs error (device mmcblk0p15): ext4_map_blocks:601: inode #2: block 9203: comm bash: lblock 0 mapped to illegal pblock 9203 (length 1)
[   95.801136] Aborting journal on device mmcblk0p15-8.
[   95.806432] EXT4-fs (mmcblk0p15): Remounting filesystem read-only
-bash: /data/2.txt: Structure needs cleaning
root@test:~# 

可以看到分区检测到错误后,就被重新挂载为read-only了,避免进一步被破坏。

3、Lifetime writes:

记录自文件系统创建以来(对应镜像烧录以来)总写入数据量的持久化计数器(单位 KB),主要用于评估闪存设备的磨损程度。

相关推荐
甲鱼9291 天前
MySQL 实战手记:日志管理与主从复制搭建全指南
运维
碳基沙盒3 天前
OpenClaw 多 Agent 配置实战指南
运维
蝎子莱莱爱打怪6 天前
Centos7中一键安装K8s集群以及Rancher安装记录
运维·后端·kubernetes
DianSan_ERP7 天前
电商API接口全链路监控:构建坚不可摧的线上运维防线
大数据·运维·网络·人工智能·git·servlet
呉師傅7 天前
火狐浏览器报错配置文件缺失如何解决#操作技巧#
运维·网络·windows·电脑
不是二师兄的八戒7 天前
Linux服务器挂载OSS存储的完整实践指南
linux·运维·服务器
zhangfeng11337 天前
趋动云 如何ssh登录 服务区 项目server
运维·人工智能·ssh
ZeroNews内网穿透7 天前
谷歌封杀OpenClaw背后:本地部署或是出路
运维·服务器·数据库·安全
失重外太空啦7 天前
nginx
运维·nginx
Gofarlic_oms17 天前
避免Kisssoft高级分析模块过度采购的科学评估方法
大数据·linux·运维·人工智能·matlab