ext4 file system

本文详细介绍了Ext4文件系统的特性,包括其相对于Ext3的改进之处,如支持更大的文件和文件系统大小、无限数量的子目录等。还讨论了Ext4的分配方案、延迟分配和其他性能优化措施,以及如何创建和配置Ext4文件系统。

Chapter 6. The Ext4 File System

The ext4 file system is a scalable extension of the ext3 file system, which was the default file system of Red Hat Enterprise Linux 5. Ext4 is the default file system of Red Hat Enterprise Linux 6, and can support files and file systems up to 16 terabytes in size. It also supports an unlimited number of sub-directories (the ext3 file system only supports up to 32,000), though once the link count exceeds 65,000 it resets to 1 and is no longer increased.

Note

As with ext3, an ext4 volume must be umounted in order to perform an  fsck. For more information, see  Chapter 5, The Ext3 File System.
Main Features
Ext4 uses extents (as opposed to the traditional block mapping scheme used by ext2 and ext3), which improves performance when using large files and reduces metadata overhead for large files. In addition, ext4 also labels unallocated block groups and inode table sections accordingly, which allows them to be skipped during a file system check. This makes for quicker file system checks, which becomes more beneficial as the file system grows in size.
Allocation Features
The ext4 file system features the following allocation schemes:
  • Persistent pre-allocation
  • Delayed allocation
  • Multi-block allocation
  • Stripe-aware allocation
Because of delayed allocation and other performance optimizations, ext4's behavior of writing files to disk is different from ext3. In ext4, when a program writes to the file system, it is not guaranteed to be on-disk unless the program issues an  fsync() call afterwards.
By default, ext3 automatically forces newly created files to disk almost immediately even without  fsync(). This behavior hid bugs in programs that did not use  fsync() to ensure that written data was on-disk. The ext4 file system, on the other hand, often waits several seconds to write out changes to disk, allowing it to combine and reorder writes for better disk performance than ext3.

Warning

Unlike ext3, the ext4 file system does not force data to disk on transaction commit. As such, it takes longer for buffered writes to be flushed to disk. As with any file system, use data integrity calls such as  fsync() to ensure that data is written to permanent storage.
Other Ext4 Features
The ext4 file system also supports the following:
  • Extended attributes ( xattr) — This allows the system to associate several additional name and value pairs per file.
  • Quota journaling — This avoids the need for lengthy quota consistency checks after a crash.

    Note

    The only supported journaling mode in ext4 is  data=ordered (default).
  • Subsecond timestamps — This gives timestamps to the subsecond.

6.1. Creating an Ext4 File System

To create an ext4 file system, use the  mkfs.ext4 command. In general, the default options are optimal for most usage scenarios:
# mkfs.ext4 /dev/device
Below is a sample output of this command, which displays the resulting file system geometry and features:

Example 6.1. mkfs.ext4 command output

~]# mkfs.ext4 /dev/sdb1 
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
245280 inodes, 979456 blocks
48972 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1006632960
30 block groups
32768 blocks per group, 32768 fragments per group
8176 inodes per group
Superblock backups stored on blocks: 
 32768, 98304, 163840, 229376, 294912, 819200, 884736

Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
For striped block devices (for example, RAID5 arrays), the stripe geometry can be specified at the time of file system creation. Using proper stripe geometry greatly enhances the performance of an ext4 file system.
When creating file systems on LVM or MD volumes,  mkfs.ext4 chooses an optimal geometry. This may also be true on some hardware RAIDs which export geometry information to the operating system.
To specify stripe geometry, use the  -E option of  mkfs.ext4 (that is, extended file system options) with the following sub-options:
stride=value
Specifies the RAID chunk size.
stripe-width=value
Specifies the number of data disks in a RAID device, or the number of stripe units in the stripe.
For both sub-options,  value must be specified in file system block units. For example, to create a file system with a 64k stride (that is, 16 x 4096) on a 4k-block file system, use the following command:
# mkfs.ext4 -E stride=16,stripe-width=64 /dev/device
For more information about creating file systems, refer to  man mkfs.ext4.

Important

It is possible to use  tune2fs to enable some ext4 features on ext3 file systems, and to use the ext4 driver to mount an ext3 file system. These actions, however, are  not supported in Red Hat Enterprise Linux 6, as they have not been fully tested. Because of this, Red Hat cannot guarantee consistent performance and predictable behavior for ext3 file systems converted or mounted in this way.
在处理与虚拟文件系统(VFS)相关的 `unable to find ext4 file system` 挂载问题时,通常涉及内核对文件系统的支持方式以及挂载参数的正确性。以下是可能导致此问题的原因及解决方法: ### 1. 内核未内置或未加载 ext4 文件系统模块 如果内核没有将 ext4 文件系统编译为内置支持或模块形式,则无法识别该文件系统类型。确保在内核配置中启用了以下选项: - **Second extended fs support** (`CONFIG_EXT2_FS`) - **Ext3 journalling file system support** (`CONFIG_EXT3_FS`) - **Ext4 journalling file system support** (`CONFIG_EXT4_FS`) [^1] 可以通过检查 `/proc/filesystems` 文件来确认当前内核是否支持 ext4: ```bash grep ext4 /proc/filesystems ``` 如果没有输出,则表示 ext4 模块未加载或未启用。 ### 2. 缺少必要的用户空间工具 挂载 ext4 文件系统需要用户空间工具如 `mount` 和 `e2fsprogs` 提供支持。确保这些工具已安装并保持最新版本。 ### 3. 文件系统损坏或元数据不一致 如果文件系统本身存在损坏,可能会导致 VFS 无法识别其类型。可以尝试使用 `fsck.ext4` 工具进行修复: ```bash sudo fsck.ext4 /dev/sdXn ``` 其中 `/dev/sdXn` 是目标设备节点。 ### 4. 挂载命令参数错误 挂载时需确保指定正确的文件系统类型。例如: ```bash sudo mount -t ext4 /dev/sdXn /mnt/point ``` 若未指定 `-t ext4` 或指定了错误的类型,VFS 可能无法识别文件系统结构 [^4]。 ### 5. 内核日志中的诊断信息 通过查看 dmesg 输出获取更详细的错误信息: ```bash dmesg | grep -i ext4 ``` 这有助于定位是模块加载失败、硬件访问问题还是文件系统结构异常。 ### 6. ramdisk 或启动镜像中缺少 ext4 支持 对于嵌入式系统或定制化 initramfs 环境,需确保 ramdisk 中包含 ext4 模块或相关驱动。否则,在早期启动阶段可能无法挂载根文件系统 [^4]。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值