欢迎来到麦麦的不老阁 – 拒绝奇虎360卫士,从我做起!

关于LinuxHobby

记录一些关于自己在linux、网络应用、个人心情故事的文字...

关于我

我喜欢搬个小板凳坐在马路边看MM,喜欢把双手插裤兜...更多机密资料... »

Member Login

Lost your password?

Not a member yet?
Sign Up!

首页 > Linux之旅 > 使用tune2fs将ext3转换为ext4

使用tune2fs将ext3转换为ext4

fedora11已经在6月9号,如期发布,其中很重要的一个新特征是将ext4作为默认的文件系统。对于ext4于ext3相比较,ext4的优越性是不言而喻的,当你从fedora10升级到fedora11之后,文件系统是不会跟着自动升级的,所以很多linuxer尝试通过tune2fs手动来转换,使用tune2fs从ext3转换到ext4一点都不复杂,无需格式化分区,也不会破坏原有数据,只需要两个命令即可完成,完全就是“无痛”转换。

ext4文件系统的特征
支持Extent
Ext4支持Extent,档案的存放使用多个连续的区块。记录存放档案内容的区块就记录每段 extent 的起始区块位置和长度,而非传统记录每个区块位置,节省不少 metadata 空间。加上读取档案内容和分配空间时可以一次处理多个区块,减少输入/输出操作次数,大大加快系统效能。Extent 的使用亦减低 external fragmentation 的机会。所以为什么很多朋友在升级到ext4之后,明显感觉到系统性能有显著提高。

突破存储限制
Ext4的文件系统存储限制大小由 ext3 的 2TB 增至 1EB;单个文件大小由 2TB 增至 16 TB,Ext2/Ext3 的目录大小不可以最于多 32KB,Ext4 取消了这个限制。加上 B-Tree 目录索引,大大减低在大目录搜索档案的时间。不要觉得TB/EB的空间概念很遥远,其实现在很多企业的数据大小都已经提升到TB级别了,如果是提供存储服务的企业,提升到EB级别是必定的。

纳秒级高精确时间
传统 Ext2/Ext3 的档案时间资料只以秒作最小单位,随着多核 (multi-core) 和丛集 (clustering) 的技术发展,Ext4 把档案时间资料的精确度提无至纳秒,时间范围亦增加 2 个位元令 Ext4 的时间纪录足够未来 500 多年使用。

实际上,ext4并非fedora11的专利,所有的发行版,只要是2.6.28或者更新的内核,都可以使用ext4文件系统。

解决grub在ext4文件系统下正常运作,我在fedora10下,用第2种方法测试后:
1、升级到grub2,直接使用yum install grub2,将grub1升级到grub2,成功。
2、在启动内核参数中添加rootfstype=ext4。(测试失败,导致系统无法引导,据说在ubuntu9.04测试可以通过,本人尚未测试。)

使用tune2fs将ext3转换为ext4步骤:
# umount /dev/分区
# tune2fs -O extents,uninit_bg,dir_index /dev/分区
# fsck -pf /dev/分区

如果要将/boot所在分区转换为ext4,现升级到grub2。如果是转换非系统分区,可以在系统当前系统下转换,这里所说的非系统分区是指在系统运行状态下可以umonut的分区,无法umount的分区,可以用live CD来进行,我用的是ubuntu9.04 USB。
1、编辑/etc/fstab,将打算转换的分区类型修改为ext4。
2、umount待转换分区,使用tune2fs和fsck这个工具的时候,分区必须是非挂载的(umonut)。
3、使用tune2fs转换分区。
4、使用fsck检查转换后的分区,如果不做这一步,在启动的时候还是会提示你做分区检查。

转换实例:

[root@linuxhobby ~]# umount /dev/sda7
[root@linuxhobby ~]# tune2fs -O extents,uninit_bg,dir_index /dev/sda7 #extents这个特征到底有什么用,本人还未理解
tune2fs 1.41.4 (27-Jan-2009)
Please run e2fsck on the filesystem.
[root@linuxhobby ~]# fsck -pf /dev/sda7
fsck 1.41.4 (27-Jan-2009)
/backup: Group descriptor 0 checksum is invalid. FIXED.
/backup: Group descriptor 1 checksum is invalid. FIXED.
/backup: Group descriptor 2 checksum is invalid. FIXED.
…..此处省略部分显示信息….
/backup: Group descriptor 238 checksum is invalid. FIXED.
/backup: Group descriptor 239 checksum is invalid. FIXED.
/backup: Group descriptor 240 checksum is invalid. FIXED.
/backup: 24926/3933120 files (2.9% non-contiguous), 6457853/7865817 blocks

转换过程很快,根据分区大小所花的时间不同,我用30G的分区大概只要一分多钟…

说明一下:
1、tune2fs后的O(大写字母O,options)。
2、uninit_bg,dir_index 是ext4拥有的特征,使用man tune2fs可以查询到解释说明。
3、关于extents这个特征,有争议,在ext4的特征说明中,有提到这个extents特征,但是在man tune2fs中查询不到。
4、extents这个特征无法清除,也就说可以用tune2fs -O ^uninit_bg,^dir_index /dev/sda7 是可以的,但是tune2fs -O ^extents /dev/sda7的时候,会提示没有extents这个特征,很奇怪的事情…
5、通过这种方式转换而来的分区,原先存放的数据,文件数据存放结构还是ext3,解决的办法,就是把原来的数据重新复制一遍,这样就可以真正使用上ext4的文件系统特征了。

另外顺便贴一下man tune2fs中,关于-O的参考说明:

关于-O参数的说明:
-O [^]feature[,...]
Set or clear the indicated filesystem features (options) in the filesystem. More than one filesystem feature can be cleared or set by separating features with commas. Filesystem features prefixed with a caret character (’^’) will be cleared in the filesystem’s superblock; filesystem features without a prefix character or prefixed with a plus character (’+’) will be added to the filesystem.
The following filesystem features can be set or cleared using tune2fs:
large_file
Filesystem can contain files that are greater than 2GB. (Modern kernels set this feature automatically when a file > 2GB is created.)

dir_index
Use hashed b-trees to speed up lookups in large directories.

filetype
Store file type information in directory entries.

has_journal
Use a journal to ensure filesystem consistency even across unclean shutdowns. Setting the filesystem feature is equivalent to using the -j option.

sparse_super
Limit the number of backup superblocks to save space on large filesystems.

resize_inode
Reserve space so the block group descriptor table may grow in the future. Tune2fs only supports clearing this filesystem feature.

uninit_bg
Allow the kernel to initialize bitmaps and inode tables and keep a high watermark for the unused inodes in a filesystem, to reduce e2fsck(8) time. This first e2fsck run after enabling this feature will take the full time, but subsequent e2fsck runs will take only a fraction of the original time, depending on how full the file system is.

After setting or clearing sparse_super, uninit_bg, filetype, or resize_inode filesystem features, e2fsck(8) must be run on the filesystem to return the filesystem to a consistent state. Tune2fs will print a message requesting that the system administrator run e2fsck(8) if necessary. After setting the dir_index feature, e2fsck -D can be run to convert existing directories to the hashed B-tree format. Enabling certain filesystem features may prevent the filesystem from being mounted by kernels which do not support those features. In particular the uninit_bg and flex_bg features are only supported by the ext4 filesystem.

  1. 2009年6月17日21:04 | #1

    yum install grub2可以直接覆盖掉grub1吗?

    [回复]

  1. 本文目前尚无任何 trackbacks 和 pingbacks.

关闭
E-mail It