文件系统类型 | 最大文件名长度 | 路径字符限制 | 最大路径长度 | 最大文件尺寸 | 最大文件系统容量 |
ext4 | 255B | 非 NUL 字符 | 无限制 | 16TiB | 1EiB |
xfs | 255B | 非 NUL 字符 | 无限制 | 8EiB | 8EiB |
文件系统类型 | 文件属主 | POSIX 文件权限 | 文件创建时间 | 文件最后访问时间 | 文件最后修改时间 | 元数据最后变化时间 | 访问控制列表 | 强制访问控制(MAC) | 扩展属性 |
ext4 | 支持 | 支持 | 支持 | 支持 | 支持 | 支持 | 支持 | 支持 | 支持 |
xfs | 支持 | 支持 | 支持 | 支持 | 支持 | 支持 | 支持 | 支持 | 支持 |
文件系统类型 | 硬链接 | 软链接 | 块日志 | 元数据日志 | 区分大小写 | 加密 | 扩缩容 |
ext4 | 支持 | 支持 | 支持 | 支持 | 支持 | 支持 | 支持离线扩缩容和在线扩容 |
xfs | 支持 | 支持 | 支持 | 支持 | 支持 | 不支持 | 仅支持在线扩容 |
mkfs、mkfs.ext4 和 mke2fs 命令。mkfs 为前端入口,根据 -t 选项指定的文件系统类型,调用对应的 mkfs.fstype 命令。例如,创建 ext4 文件系统时,最终执行的是 mkfs.ext4 命令。mkfs.ext4 对应的二进制文件为 /usr/sbin/mke2fs 的硬链接,因此执行 mkfs.ext4 实际执行的是 mke2fs。mkfs -t ext4 block-device
mkfs.ext4 block-device
mke2fs -t ext4 block-device
/dev/sdb1 上创建 ext4 文件系统:mkfs.ext4 /dev/sdb1
mkfs.ext4 通过读取 /etc/mke2fs.conf 对初始文件系统进行默认配置,TencentOS Server 使用的默认配置如下:[defaults]base_features = sparse_super,large_file,filetype,resize_inode,dir_index,ext_attrdefault_mntopts = acl,user_xattrenable_periodic_fsck = 0blocksize = 4096inode_size = 256inode_ratio = 16384[fs_types]ext3 = {features = has_journal}ext4 = {features = has_journal,extent,huge_file,flex_bg,metadata_csum,64bit,dir_nlink,extra_isize}small = {blocksize = 1024inode_ratio = 4096}floppy = {blocksize = 1024inode_ratio = 8192}big = {inode_ratio = 32768}huge = {inode_ratio = 65536}news = {inode_ratio = 4096}largefile = {inode_ratio = 1048576blocksize = -1}largefile4 = {inode_ratio = 4194304blocksize = -1}hurd = {blocksize = 4096inode_size = 128warn_y2038_dates = 0}
节 | 说明 |
[defaults] | 指定通用的默认参数,优先级低于 [fs_types] 节或命令行参数中的相同配置。 |
[fs_types] | 指定特定文件系统或特定使用场景(如 small、big 等)下的默认参数,可通过 mke2fs 的 -T 选项指定。 |
其他 | 另外还支持 options 和 devices 节,具体请查看 man 手册。 |
标签 | 说明 |
base_features | 文件系统创建时默认启用的基本功能。TencentOS Server 启用了 sparse_super、large_file、filetype、resize_inode、dir_index、ext_attr;若存在多个同名配置项, [fs_types] 节中最后一个生效。 |
default_mntopts | 文件系统挂载时默认启用的挂载配置。TencentOS Server 启用了 acl 和 user_xattr。 |
enable_periodic_fsck | 是否在系统启动时强制执行文件系统周期性检查。TencentOS Server 默认为 0(禁用);设为 1 时,累计运行 180 天或累计挂载一定次数后会强制执行检查。 |
blocksize | 文件系统默认块大小,TencentOS Server 默认为 4096 字节。 |
inode_size | inode 的大小,TencentOS Server 默认为 256 字节。 |
inode_ratio | 分区大小与 inode 数量的比例(实际计算公式有差异),TencentOS Server 默认为 16384。 |
features | 文件系统额外功能的启用/禁用配置,特性前添加 ^ 表示禁用,不加 ^ 表示启用。 |
ext3 | 创建 ext3 文件系统时使用的参数(建议使用 ext4 文件系统)。 |
ext4 | 创建 ext4 文件系统时使用的参数。TencentOS Server 启用了 has_journal、extent、huge_file、flex_bg、metadata_csum、64bit、dir_nlink、extra_isize。 |
small / floppy / big / huge / news / largefile / largefile4 | 特定使用场景的预设配置,分别对应:小型文件系统、软盘、大型文件系统、更大型文件系统、新闻组数据、大文件、更大文件。 |
hurd | 针对 GNU Hurd 操作系统的配置。 |
man mke2fs.conf。-b 指定块大小。-t 指定文件系统类型,mkfs.ext4 命令无需指定,mke2fs 命令默认创建 ext2 文件系统。-i 指定 inode_ratio。-I 指定 inode 大小。-O 指定文件系统的特性,特性前添加 ^ 禁用特性。-T 指定文件系统使用场景,值为 /etc/mke2fs.conf 配置中 fs_types 列出的参数项。/dev/sdb2 上创建 ext4 文件系统,指定 block 大小为 2048 字节,inode 大小为 128 字节,并禁用 metadata_csum 功能。mkfs.ext4 -b 2048 -I 128 -O ^metadata_csum /dev/sdb2
mkfs、mkfs.xfs 命令。mkfs -t xfs block-device
mkfs.xfs block-device
-b block_size_options 指定文件系统块大小,如:-b size=4096。-m global_metadata_options 指定文件系统元数据区配置,如:-m crc=1。-d data_section_options 指定文件系统数据区配置,如:-d agcount=4。-i inode_options 指定 inode 区配置,如:-i size=512。/dev/sdb3 上创建 xfs 文件系统,指定 block 大小为 4096 字节,inode 大小为 512 字节,并启用 crc 功能。若设备上已存在文件系统,mkfs.xfs 默认会拒绝执行,-f 选项用于强制格式化:mkfs.xfs -b size=4096 -m crc=1 -i size=512 -f /dev/sdb3
man mkfs.xfs。mount 命令手动挂载文件系统。以下示例将设备 /dev/sdb1 挂载到 /mnt 目录:mount /dev/sdb1 /mnt/
f9ce3b49-da65-4eca-8692-7dafxxxxxxxx 到 /data 目录:mount UUID=f9ce3b49-da65-4eca-8692-7dafxxxxxxxx /data
mount 可自动识别块设备上的文件系统类型。如果 mount 无法识别,可通过 -t 选项指定文件系统类型,示例如下:mount -t xfs /dev/sdb3 /home/test
-o 选项指定挂载属性。以下示例将文件系统挂载为只读:mount -o ro /dev/sdb2 /data
man mount。systemd 会根据 /etc/fstab 中的配置自动挂载文件系统。/dev/mapper/os-root / ext4 defaults 1 1UUID=88d0f4bd-bed0-4307-867e-50d02353fea2 /boot ext4 defaults 1 2UUID=08C2-8D97 /boot/efi vfat umask=0077,shortname=winnt 0 2/dev/mapper/os-home /home ext4 defaults 1 2
字段 | 说明 |
设备 | 待挂载的设备,可以使用设备路径或 UUID,也可以是特殊文件系统(如 proc)或远程文件系统(如 nfs)。 |
挂载点 | 挂载点路径;对于 swap,该字段指定为 none。 |
文件系统类型 | 文件系统类型,如 ext4、xfs、vfat、swap。 |
挂载属性 | 挂载属性,如 defaults、ro、noauto。 |
dump | dump 工具根据该字段决定是否需要备份该文件系统。 |
fsck 检查顺序 | fsck 根据该字段决定系统启动时文件系统检查的顺序。 |
mount -a 命令,将自动挂载 /etc/fstab 配置的设备(如果挂载属性中配置了 noauto,则不会自动挂载)。mount
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel).../dev/mapper/os-root on / type ext4 (rw,relatime,seclabel)...
lsblk 查看当前系统的挂载信息,如下:lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTSsda 8:0 0 64G 0 disk├─sda1 8:1 0 50M 0 part /boot/efi├─sda2 8:2 0 512M 0 part /boot└─sda3 8:3 0 63.4G 0 part├─os-root 253:0 0 30G 0 lvm /└─os-home 253:1 0 33.4G 0 lvm /homesdb 8:16 0 64G 0 disk├─sdb1 8:17 0 8G 0 part├─sdb2 8:18 0 8G 0 part /data└─sdb3 8:19 0 64M 0 part /home/test
df -h 查看系统挂载信息,如下:df -h
Filesystem Size Used Avail Use% Mounted ondevtmpfs 4.0M 0 4.0M 0% /devtmpfs 3.7G 0 3.7G 0% /dev/shmtmpfs 1.5G 9.2M 1.5G 1% /run/dev/mapper/os-root 30G 5.4G 23G 20% /tmpfs 3.7G 16K 3.7G 1% /tmp/dev/sda2 488M 238M 215M 53% /boot/dev/sda1 50M 5.5M 45M 11% /boot/efi/dev/mapper/os-home 33G 12M 31G 1% /hometmpfs 748M 80K 748M 1% /run/user/1000tmpfs 748M 28K 748M 1% /run/user/0/dev/sdb2 7.8G 24K 7.4G 1% /data/dev/sdb3 60M 4.0M 56M 7% /home/test
df -i 可查看已挂载文件系统 inode 使用情况,如下:df -i
Filesystem Inodes IUsed IFree IUse% Mounted ondevtmpfs 1048576 481 1048095 1% /devtmpfs 957374 1 957373 1% /dev/shmtmpfs 819200 898 818302 1% /run/dev/mapper/os-root 1966080 131563 1834517 7% /tmpfs 1048576 27 1048549 1% /tmp/dev/sda2 32768 226 32542 1% /boot/dev/sda1 0 0 0 - /boot/efi/dev/mapper/os-home 2195456 495 2194961 1% /hometmpfs 191474 102 191372 1% /run/user/1000tmpfs 191474 31 191443 1% /run/user/0/dev/sdb2 524288 11 524277 1% /data/dev/sdb3 32768 3 32765 1% /home/test
man df。findmnt 命令显示系统挂载信息,如下:findmnt
TARGET SOURCE FSTYPE OPTIONS/ /dev/mapper/os-root| ext4 rw,relatime,seclabel|-/proc proc proc rw,nosuid,nodev,noexec,relatime| `-/proc/sys/fs/binfmt_misc systemd-1 autofs rw,relatime,fd=31,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,| `-/proc/sys/fs/binfmt_misc binfmt_misc binfmt_mis rw,nosuid,nodev,noexec,relatime|-/sys sysfs sysfs rw,nosuid,nodev,noexec,relatime,seclabel| |-/sys/kernel/security securityfs securityfs rw,nosuid,nodev,noexec,relatime| |-/sys/fs/cgroup cgroup2 cgroup2 rw,nosuid,nodev,noexec,relatime,seclabel,nsdelegate,memory_recur| |-/sys/fs/pstore pstore pstore rw,nosuid,nodev,noexec,relatime,seclabel...|-/boot /dev/sda2 ext4 rw,relatime,seclabel| `-/boot/efi /dev/sda1 vfat rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=ascii,s|-/home /dev/mapper/os-home| ext4 rw,relatime,seclabel| `-/home/test /dev/sdb3 xfs rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquot`-/data /dev/sdb2 ext4 rw,relatime,seclabel
findmnt -t ext4
TARGET SOURCE FSTYPE OPTIONS/ /dev/mapper/os-root ext4 rw,relatime,seclabel├─/boot /dev/sda2 ext4 rw,relatime,seclabel├─/home /dev/mapper/os-home ext4 rw,relatime,seclabel└─/data /dev/sdb2 ext4 rw,relatime,seclabel
findmnt /
TARGET SOURCE FSTYPE OPTIONS/ /dev/mapper/os-root ext4 rw,relatime,seclabel
umount 命令卸载文件系统,如下:umount /home/test
man umount。umount /home/test
umount: /home/test: target is busy.
fuser 查看该目录占用情况,如下:fuser -vm /home/test
USER PID ACCESS COMMAND/home/test: root kernel mount /home/testroot 5360 ...e. main
-k 选项 kill 占用进程,如下:fuser -kvm /home/test
USER PID ACCESS COMMAND/home/test: root kernel mount /home/testroot 5360 ...e. main[1]+ Killed /home/test/main
tune2fs 查看 ext4 文件系统信息,示例如下:tune2fs -l /dev/sdb2
tune2fs 1.46.5 (30-Dec-2021)Filesystem volume name: <none>Last mounted on: <not available>Filesystem UUID: f9ce3b49-da65-4eca-8692-7daf78db5daeFilesystem magic number: 0xEF53Filesystem 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_csumFilesystem flags: unsigned_directory_hashDefault mount options: user_xattr aclFilesystem state: cleanErrors behavior: ContinueFilesystem OS type: LinuxInode count: 524288Block count: 2097152Reserved block count: 104857Overhead clusters: 58505Free blocks: 2038641Free inodes: 524277First block: 0Block size: 4096Fragment size: 4096Group descriptor size: 64Reserved GDT blocks: 1023Blocks per group: 32768Fragments per group: 32768Inodes per group: 8192Inode blocks per group: 512Flex block group size: 16Filesystem created: Mon May 29 14:12:24 2023Last mount time: Mon May 29 19:23:26 2023Last write time: Mon May 29 19:23:26 2023Mount count: 1Maximum mount count: -1Last checked: Mon May 29 14:12:24 2023Check interval: 0 (<none>)Lifetime writes: 4129 kBReserved blocks uid: 0 (user root)Reserved blocks gid: 0 (group root)First inode: 11Inode size: 256Required extra isize: 32Desired extra isize: 32Journal inode: 8Default directory hash: half_md4Directory Hash Seed: 1f267a9b-0e32-493e-b2bc-36dfff3493e6Journal backup: inode blocksChecksum type: crc32cChecksum: 0xbaacede8
man tune2fs。dumpe2fs 可以查看 ext4 文件系统组信息,示例如下:# dumpe2fs /dev/sdb2dumpe2fs 1.46.5 (30-Dec-2021)Filesystem volume name: <none>Last mounted on: <not available>Filesystem UUID: f9ce3b49-da65-4eca-8692-7daf78db5daeFilesystem magic number: 0xEF53Filesystem 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_csumFilesystem flags: unsigned_directory_hashDefault mount options: user_xattr acl...Journal start: 1Journal checksum type: crc32cJournal checksum: 0xcc4acf7cGroup 0: (Blocks 0-32767) csum 0xc849 [ITABLE_ZEROED]Primary superblock at 0, Group descriptors at 1-1Reserved GDT blocks at 2-1024Block bitmap at 1025 (+1025), csum 0xa213e783Inode bitmap at 1041 (+1041), csum 0xad0eecccInode table at 1057-1568 (+1057)23513 free blocks, 8181 free inodes, 2 directories, 8181 unused inodesFree blocks: 9255-32767Free inodes: 12-8192Group 1: (Blocks 32768-65535) csum 0x880b [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]Backup superblock at 32768, Group descriptors at 32769-32769Reserved GDT blocks at 32770-33792Block bitmap at 1026 (bg #0 + 1026), csum 0x00000000Inode bitmap at 1042 (bg #0 + 1042), csum 0x00000000Inode table at 1569-2080 (bg #0 + 1569)31743 free blocks, 8192 free inodes, 0 directories, 8192 unused inodesFree blocks: 33793-65535Free inodes: 8193-16384Group 2: (Blocks 65536-98303) csum 0x894a [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]Block bitmap at 1027 (bg #0 + 1027), csum 0x00000000Inode bitmap at 1043 (bg #0 + 1043), csum 0x00000000Inode table at 2081-2592 (bg #0 + 2081)32768 free blocks, 8192 free inodes, 0 directories, 8192 unused inodesFree blocks: 65536-98303Free inodes: 16385-24576Group 3: (Blocks 98304-131071) csum 0xc70e [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]Backup superblock at 98304, Group descriptors at 98305-98305Reserved GDT blocks at 98306-99328Block bitmap at 1028 (bg #0 + 1028), csum 0x00000000Inode bitmap at 1044 (bg #0 + 1044), csum 0x00000000Inode table at 2593-3104 (bg #0 + 2593)31743 free blocks, 8192 free inodes, 0 directories, 8192 unused inodesFree blocks: 99329-131071Free inodes: 24577-32768...
tune2fs 查看的信息相似,后半部分为各个组的元数据信息。xfs_info 查看 xfs 文件系统信息,示例如下:xfs_info /dev/sdb3
meta-data=/dev/sdb3 isize=512 agcount=4, agsize=4096 blks= sectsz=4096 attr=2, projid32bit=1= crc=1 finobt=1, sparse=1, rmapbt=0= reflink=1 bigtime=0 inobtcount=0data = bsize=4096 blocks=16384, imaxpct=25= sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0, ftype=1log =internal log bsize=4096 blocks=1221, version=2= sectsz=4096 sunit=1 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0
man xfs_info。e2image block-device ext4-metadata.img
block-device:待备份文件系统的块设备。ext4-metadata.img:备份文件名称。normal,e2image 的恢复功能只支持这种格式。-r 选项保存成 raw 格式,使用 -Q 选项保存成 qcow2 格式,如果需要保存数据,可以添加 -a 选项,如下所示:e2image -r -a block-device ext4-backup.img
e2image 保存的 raw 格式文件是稀疏文件,可以压缩以节省空间,命令参考如下:e2image -r block-device - | bzip2 > ext4-backup.img.bz2
e2image 备份的 raw 格式文件可以直接使用 mount 命令挂载,如下:mount ext4-backup.img mountpoint
man e2image。e2image -I block-device ext4-metadata.img
ext4-metadata.img 为 e2image 命令保存的 normal 格式的元数据备份文件。e2image 仅对元数据进行恢复,无法恢复数据。dump -0uf backup-file block-device
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTSsda 8:0 0 64G 0 disk├─sda1 8:1 0 50M 0 part /boot/efi├─sda2 8:2 0 512M 0 part /boot└─sda3 8:3 0 63.4G 0 part├─os-root 253:0 0 30G 0 lvm /└─os-home 253:1 0 33.4G 0 lvm /home
/dev/sda2,即 boot 分区:dump -0uf /home/sda2.backup /dev/sda2
/dev/sda2 上的文件系统已损坏,以下示例演示如何通过 restore 的备份文件恢复系统 boot 分区。/dev/sda2 上创建 ext4 文件系统:mkfs.ext4 /dev/sda2
/dev/sda2 到 /boot 目录:mount /dev/sda2 /boot
boot 目录下执行如下命令:restore -rf /home/sda2.backup
boot 分区下的文件恢复完成。xfs_copy block-device xfs-backup.img
xfs_copy 将备份元数据和实际数据,备份文件可以直接使用 mount 命令挂载,也可以通过 xfs_info 命令查看。xfs_metadump -a block-device xfs-metadata.img
xfs_metadump 只保存文件系统元数据,可用于恢复 xfs 文件系统。xfs_mdrestore -gi xfs-metadata.img block-device
xfs_mdrestore 仅恢复元数据,不能恢复数据。xfsdump -l level -L session_label -M media_label -f backup-file path
level:备份级别,0 标识全部备份。session_label:会话标签,用以表明备份信息,可以为任意小于 255 字符的字符串。media_label:介质标签,用以标识备份介质,可以为任意小于 255 字符的字符串。backup-file:为生成的备份文件,path 表示待备份目录。/data 目录(/dev/sdb6 挂载点)的内容:xfsdump -l 0 -L "backup_data" -M "backup_sdb6" -f /home/sdb6.backup /data
/dev/sdb6 上的文件系统已损坏,以下示例演示如何通过 xfsrestore 的备份文件恢复。/dev/sdb6 上创建 xfs 文件系统:mkfs.xfs /dev/sdb6
/dev/sdb6 到 /data 目录:mount /dev/sdb6 /data
xfsrestore -f /home/sdb6.backup /data
/data 下的文件恢复完成。-e 选项调整文件系统在内核中报错时的行为,使用如下命令查看当前行为:tune2fs -l /dev/sdb2 | grep "Errors behavior"Errors behavior: Continue
tune2fs -e remount-ro /dev/sdb2
-o 选项调整文件系统当前挂载属性,属性前添加 ^ 禁用对应属性,使用如下命令查看当前默认挂载属性:tune2fs -l /dev/sdb2 | grep "Default mount options"Default mount options: user_xattr acl
acl 属性,启用 debug 属性:tune2fs -o ^acl,debug /dev/sdb2
-O 选项调整文件系统当前的一些特性,特性前添加 ^ 禁用对应特性,使用如下命令查看当前默认特性:tune2fs -l /dev/sdb2 | grep "Filesystem features"
metadata_csum 特性,启用 mmp 特性:tune2fs -O ^metadata_csum,mmp /dev/sdb2
resize2fs 支持在线扩容(文件系统处于挂载状态)和离线(文件系统处于卸载状态)扩缩容,命令如下:resize2fs block-device size
size 小于当前容量时,执行缩容,可能会导致数据丢失;当 size 大于当前容量时,执行扩容。resize2fs 命令自身无法调整分区大小,因此 size 必须小于或等于文件系统当前容量与所在分区剩余容量之和。文件系统挂载状态下,仅支持扩容操作。/dev/sdb 磁盘上的第 8 个分区,扩容前分区大小为 1G,文件系统大小为 1G:growpart /dev/sdb 8
resize2fs 调整文件系统大小为 8G:resize2fs /dev/sdb8 8G
lvextend/lvreduce 实现对逻辑卷上文件系统的扩容和缩容。xfs_admin 命令调整 XFS 文件系统参数。以下命令启用 XFS 文件系统的 bigtime 特性:xfs_admin -O bigtime=1 block-device
xfs_growfs -d <挂载点>
xfs_growfs -D size <挂载点>
fsck、fsck.ext4 或 e2fsck 对文件系统进行检查与修复。fsck 为前端入口,最终会调用 fsck.ext4。可通过 -t 选项指定文件系统类型;若不指定,fsck 会自动识别。fsck.ext4 对应的二进制文件为 /usr/sbin/e2fsck 的硬链接,两者命令相同。fsck.ext4 -p /dev/sdb5
/dev/sdb5: One or more block group descriptor checksums are invalid. FIXED./dev/sdb5: Group descriptor 0 checksum is 0x0000, should be 0x471e. FIXED./dev/sdb5: Group descriptor 1 checksum is 0x0000, should be 0x6325. FIXED./dev/sdb5: Group descriptor 2 checksum is 0x0000, should be 0x0f68. FIXED./dev/sdb5: Group descriptor 3 checksum is 0x0000, should be 0x2b53. FIXED.fsck.ext4: A block group is missing an inode table while reading bad blocks inode/dev/sdb5: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.(i.e., without -a or -p options)
fsck.ext4 /dev/sdb5
e2fsck 1.46.5 (30-Dec-2021)ext2fs_check_desc: Corrupt group descriptor: bad block for block bitmapfsck.ext4: Group descriptors look bad... trying backup blocks.../dev/sdb5 contains a file system with errors, check forced.Resize inode not valid. Recreate<y>?
fsck.ext4 -n /dev/sdb5
e2fsck 1.46.5 (30-Dec-2021)ext2fs_check_desc: Corrupt group descriptor: bad block for block bitmapfsck.ext4: Group descriptors look bad... trying backup blocks.../dev/sdb5 contains a file system with errors, check forced.Resize inode not valid. Recreate? noPass 1: Checking inodes, blocks, and sizesInode 7, i_blocks is 1520, should be 1504. Fix? noPass 2: Checking directory structurePass 3: Checking directory connectivityPass 4: Checking reference countsPass 5: Checking group summary informationFree blocks count wrong for group #0 (4294967295, counted=30644).Fix? noFree blocks count wrong for group #1 (0, counted=32703).Fix? no...Free inodes count wrong for group #0 (0, counted=8181).Fix? noDirectories count wrong for group #0 (0, counted=2).Fix? no...Padding at end of inode bitmap is not set. Fix? noInode bitmap differences: Group 0 inode bitmap does not match checksum.IGNORED.Group 1 inode bitmap does not match checksum.IGNORED.Group 2 inode bitmap does not match checksum.IGNORED..../dev/sdb5: ********** WARNING: Filesystem still has errors **********/dev/sdb5: 226/32768 files (0.0% non-contiguous), 67111/131072 blocks
fsck.ext4 -y /dev/sdb5
e2fsck 1.46.5 (30-Dec-2021)ext2fs_check_desc: Corrupt group descriptor: bad block for block bitmapfsck.ext4: Group descriptors look bad... trying backup blocks.../dev/sdb5 contains a file system with errors, check forced.Resize inode not valid. Recreate? yesPass 1: Checking inodes, blocks, and sizesPass 2: Checking directory structurePass 3: Checking directory connectivityPass 4: Checking reference countsPass 5: Checking group summary informationFree blocks count wrong for group #0 (4294967294, counted=30644).Fix? yesFree blocks count wrong for group #1 (0, counted=32703).Fix? yesFree blocks count wrong for group #2 (0, counted=32768).Fix? yesFree blocks count wrong for group #3 (0, counted=32703).Fix? yesFree blocks count wrong (63960, counted=128818).Fix? yesFree inodes count wrong for group #0 (0, counted=8181).Fix? yesDirectories count wrong for group #0 (0, counted=2).Fix? yesFree inodes count wrong for group #1 (0, counted=8192).Fix? yesFree inodes count wrong for group #2 (0, counted=8192).Fix? yesFree inodes count wrong for group #3 (0, counted=8192).Fix? yesFree inodes count wrong (32542, counted=32757).Fix? yesPadding at end of inode bitmap is not set. Fix? yes/dev/sdb5: ***** FILE SYSTEM WAS MODIFIED *****/dev/sdb5: 11/32768 files (0.0% non-contiguous), 2254/131072 blocks
fsck.ext4 命令修复,可根据 fsck.ext4 的返回值判断具体情况:-n 选项,xfs_repair 不进行实际的修复,仅对文件系统进行检查:# xfs_repair -n /dev/sdb5Phase 1 - find and verify superblock...Phase 2 - using internal log- zero log...- scan filesystem freespace and inode maps...Metadata CRC error detected at 0xaaaab6b205a0, xfs_agi block 0x10/0x1000agi has bad CRC for ag 0bad magic # 0x0 for agi 0bad version # 0 for agi 0bad length # 0 for agi 0, should be 32768bad uuid 00000000-0000-0000-0000-000000000000 for agi 0would reset bad agi for ag 0bad uncorrected agheader 0, skipping ag...sb_icount 384, counted 320sb_ifree 155, counted 123sb_fdblocks 52465, counted 52139root inode chunk not foundPhase 3 - for each AG...- scan (but don't clear) agi unlinked lists...- process known inodes and perform inode discovery...- agno = 0imap claims in-use inode 131 is free, would correct imapimap claims in-use inode 132 is free, would correct imap...imap claims in-use inode 159 is free, would correct imap- agno = 1- agno = 2- agno = 3- process newly discovered inodes...Phase 4 - check for duplicate blocks...- setting up duplicate extent list...- check for inodes claiming duplicate blocks...- agno = 0- agno = 1- agno = 2- agno = 3No modify flag set, skipping phase 5Phase 6 - check inode connectivity...- traversing filesystem ...- traversal finished ...- moving disconnected inodes to lost+found ...Phase 7 - verify link counts...No modify flag set, skipping filesystem flush and exiting.
# xfs_repair /dev/sdb5Phase 1 - find and verify superblock...Phase 2 - using internal log- zero log...- scan filesystem freespace and inode maps...Metadata CRC error detected at 0xaaaac43c05a0, xfs_agi block 0x10/0x1000agi has bad CRC for ag 0bad magic # 0x0 for agi 0bad version # 0 for agi 0bad length # 0 for agi 0, should be 32768bad uuid 00000000-0000-0000-0000-000000000000 for agi 0reset bad agi for ag 0bad levels 0 for inobt root, agno 0bad agbno 0 for inobt root, agno 0bad levels 0 for finobt root, agno 0bad agbno 0 for finobt root, agno 0agi unlinked bucket 0 is 0 in ag 0 (inode=0)agi unlinked bucket 1 is 0 in ag 0 (inode=0)...agi unlinked bucket 63 is 0 in ag 0 (inode=0)sb_icount 384, counted 320sb_ifree 155, counted 123root inode chunk not foundPhase 3 - for each AG...- scan and clear agi unlinked lists...- process known inodes and perform inode discovery...- agno = 0correcting imapcorrecting imap...correcting imap- agno = 1- agno = 2- agno = 3- process newly discovered inodes...Phase 4 - check for duplicate blocks...- setting up duplicate extent list...- check for inodes claiming duplicate blocks...- agno = 0- agno = 2- agno = 3- agno = 1Phase 5 - rebuild AG headers and trees...- reset superblock...Phase 6 - check inode connectivity...- resetting contents of realtime bitmap and summary inodes- traversing filesystem ...- traversal finished ...- moving disconnected inodes to lost+found ...Phase 7 - verify and correct link counts...done
文档反馈