免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 8270 | 回复: 1
打印 上一主题 下一主题

如何在buildroot中添加支持去制作ext3和ext4类型的根文件系统rootfs镜像文件 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-11-11 13:50 |只看该作者 |倒序浏览
[ext3已成功,ext4不成功]如何在buildroot中添加支持去制作ext3和ext4类型的根文件系统rootfs镜像文件

最近因需要,折腾了在buildroot下面,如何添加支持制作出ext2类型的rootfs,
其实就是在make menuconfig中,将ext2选上,然后make即可,就会去自动下载
genext2fs这个工具,通过这个工具,根据当前已经存在的rootfs对应的文件,
自动制作出ext2的rootfs的镜像文件arm.rootfs.ext2(我的是ARM的交叉编译环境)
然后,又想制作ext3的rootfs,
很自然地联想到,是否可以用这个genext2fs去生成ext3的rootfs,
找了下资料,好像没找到,以为不支持呢。
最后,终于大概搞清楚如何制作ext3的rootfs了,甚至应该ext4的rootfs,也可以的。
记录如下,以待验证:
【buildroot下制作ext3的rootfs镜像文件】
其实,也是很简单,关键是知道用什么工具。。。
就是在原先制作ext2的基础上,再用个工具转换一下即可:
1.默认的buildroot中,制作ext2的rootfs文件系统镜像,是类似于如下的命令:
  1. IMAGE_CMD_ext2 = "genext2fs -b ${IMAGE_ROOTFS_SIZE} \
  2. -d ${IMAGE_ROOTFS} \
  3. ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ext2 \
  4. ${EXTRA_IMAGECMD}"
复制代码

2.而想要得到ext3的rootfs,只需要再多加一个tune2fs即可:
  1. IMAGE_CMD_ext3 = "genext2fs -b ${IMAGE_ROOTFS_SIZE} \
  2. -d ${IMAGE_ROOTFS} \
  3. ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.ext3 \
  4. ${EXTRA_IMAGECMD}; \
  5. tune2fs -j ${DEPLOY_DIR_IMAGE}/tmp.gz/${IMAGE_NAME}.rootfs.ext3"
复制代码
由于tune2fs,buildroot已经有了,即使没有,自己去下载个源码自己编译一个。
然后,自己再buildroot中加一下对应命令即可搞定。
另外,附录摘录里面,也有对应的,关于压缩版本的rootfs,比如用gzip压缩的,是如何制作的,
感兴趣自己去看吧。
已实现了的ext3:
1.在buildroot/target/ext2/ext2root.mk中添加如下代码:
  1. ........
  2. ifneq ($(EXT2_ROOTFS_COMPRESSOR),)
  3. EXT2_TARGET := $(EXT2_BASE).$(EXT2_ROOTFS_COMPRESSOR_EXT)
  4. else
  5. EXT2_TARGET := $(EXT2_BASE)
  6. endif
  7. ifeq ($(strip $(BR2_TARGET_ROOTFS_EXT3)),y)
  8. EXT3_TARGET := $(subst ext2,ext3,$(EXT2_TARGET))
  9. endif
  10. ........
  11. ext2root: $(EXT2_TARGET)
  12.         @ls -l $(EXT2_TARGET)
  13. ifneq ($(EXT2_COPYTO),)
  14.         @cp -f $(EXT2_TARGET) $(EXT2_COPYTO)
  15. endif
  16. ifeq ($(strip $(BR2_TARGET_ROOTFS_EXT3)),y)
  17.         @cp -a $(EXT2_TARGET) $(EXT3_TARGET)
  18.         @tune2fs -j $(EXT3_TARGET)
  19.         @e2fsck -p $(EXT3_TARGET)
  20.         @ls -l $(EXT3_TARGET)
  21. endif
  22. ext2root-source: $(DL_DIR)/$(GENEXT2_SOURCE)
  23. ........
复制代码

作用是在ext2同文件夹下,生成ext3的rootfs。
2.同时,更新config:
在buildroot/target/ext2/Config.in中添加如下代码:
  1. config BR2_TARGET_ROOTFS_EXT3
  2.         bool "generate ext3 root filesystem"
  3.         depends on BR2_TARGET_ROOTFS_EXT2
  4.         default y
  5.         help
  6.           generate the ext3 filesystem or not.
复制代码

作用是可以配置是否生成ext3的rootfs。
最后make即可同时生成ext2和ext3的rootfs。
【buildroot下制作ext4的rootfs镜像文件】
总的说,就是在原先ext2/ext3的基础上,给上对应ext4支持的那些参数,调用tune2fs转换即可。
此处说一下大概步骤(待验证):
tune2fs -O extents,uninit_bg,dir_index 设备名或文件系统镜像名
关于参数具体含义,最好还是看英文的man:
很详细的TUNE2FS手册
http://bbs.qxntc.edu.cn/cgi-bin/cgiman?8+tune2fs
转完后,根据手册说明,如果-O参数后面包含sparse_super和filetype,
就还要用e2fsck再去检查一遍,以便保持文件系统完整性:
e2fsck 设备名或文件系统镜像名
其中,e2fsck这个工具,我在之前下载源码编译安装e2fsprogs后,就会有这个工具了。
e2fsprogs源码参见:
[源码下载]mkfs.ext2的源码==mk2efs的源码 == e2fsprogs的源码
http://hi.baidu.com/serial_story/blog/item/926aeb3fbfccbbc87c1e7120.html
更具体的方法解释,参考附录中那位:
使用tune2fs将ext3转换为ext4
http://www.linuxhobby.com/2009/06/tune2fs-ext3-convert-ext4/
【经如下检验,制作ext4不成功】
在Config.in中添加如下代码:
  1. config BR2_TARGET_ROOTFS_EXT4
  2.         bool "generate ext4 root filesystem"
  3.         depends on BR2_TARGET_ROOTFS_EXT2 && BR2_TARGET_ROOTFS_EXT3
  4.         default y
  5.         help
  6.           generate the ext4 filesystem or not. must generate ext3 before this if define this.
  7. 在ext2root.mk中,添加如下代码:
  8. 。。。
  9. ifeq ($(strip $(BR2_TARGET_ROOTFS_EXT4)),y)
  10. EXT4_TARGET := $(subst ext3,ext4,$(EXT3_TARGET))
  11. endif
  12. 。。。。。
  13. ifeq ($(strip $(BR2_TARGET_ROOTFS_EXT4)),y)
  14. ext4root: $(EXT4_TARGET)
  15.         @cp -a $(EXT3_TARGET) $(EXT4_TARGET)
  16.         @tune2fs -O extents,uninit_bg,dir_index $(EXT4_TARGET)
  17.         @ls -l $(EXT4_TARGET)
  18.         @e2fsck -fpDC0 $(EXT4_TARGET)
  19.         @ls -l $(EXT4_TARGET)
  20. endif
  21. 。。。
复制代码
但是,最后对于ext4,make出错:
  1. tune2fs 1.41.1 (01-Sep-200
  2. Please run e2fsck on the filesystem.
  3. -rwxrwxrwx 1 buildroot users 57217024 2009-10-16 12:44 /root/buildroot/buildroot/binaries/uclibc/rootfs.arm-.ext4
  4. /root/buildroot/buildroot/binaries/uclibc/rootfs.arm-.ext4: Group descriptor 0 checksum is invalid. FIXED.
  5. /root/buildroot/buildroot/binaries/uclibc/rootfs.arm-.ext4: Group descriptor 1 checksum is invalid. FIXED.
  6. /root/buildroot/buildroot/binaries/uclibc/rootfs.arm-.ext4: Group descriptor 2 checksum is invalid. FIXED.
  7. /root/buildroot/buildroot/binaries/uclibc/rootfs.arm-.ext4: Group descriptor 3 checksum is invalid. FIXED.
  8. /root/buildroot/buildroot/binaries/uclibc/rootfs.arm-.ext4: Group descriptor 4 checksum is invalid. FIXED.
  9. /root/buildroot/buildroot/binaries/uclibc/rootfs.arm-.ext4: Group descriptor 5 checksum is invalid. FIXED.
  10. /root/buildroot/buildroot/binaries/uclibc/rootfs.arm-.ext4: Group descriptor 6 checksum is invalid. FIXED.
  11. /root/buildroot/buildroot/binaries/uclibc/rootfs.arm-.ext4: Adding dirhash hint to filesystem.
  12. /root/buildroot/buildroot/binaries/uclibc/rootfs.arm-.ext4:                                                                         /lost+found not found. CREATED.
  13. /root/buildroot/buildroot/binaries/uclibc/rootfs.arm-.ext4: 1926/2352 files (0.5% non-contiguous), 41430/55876 blocks
  14. make: *** [ext4root] Error 1
复制代码

由于make出错,所以自己另外单独尝试了去通过ext3制作ext4,结果和上面输入一样,根据输入看起来好像没什么问题:
  1. [root@linux-41lh buildroot]$>cp binaries/uclibc/rootfs.arm-.ext3 binaries/uclibc/rootfs.arm-.ext4
  2. [root@linux-41lh buildroot]$>tune2fs -O extents,uninit_bg,dir_index binaries/uclibc/rootfs.arm-.ext4
  3. tune2fs 1.41.1 (01-Sep-200
  4. Please run e2fsck on the filesystem.
  5. [root@linux-41lh buildroot]$>e2fsck -fpDC0 binaries/uclibc/rootfs.arm-.ext4
  6. binaries/uclibc/rootfs.arm-.ext4: Group descriptor 0 checksum is invalid. FIXED.
  7. binaries/uclibc/rootfs.arm-.ext4: Group descriptor 1 checksum is invalid. FIXED.
  8. binaries/uclibc/rootfs.arm-.ext4: Group descriptor 2 checksum is invalid. FIXED.
  9. binaries/uclibc/rootfs.arm-.ext4: Group descriptor 3 checksum is invalid. FIXED.
  10. binaries/uclibc/rootfs.arm-.ext4: Group descriptor 4 checksum is invalid. FIXED.
  11. binaries/uclibc/rootfs.arm-.ext4: Group descriptor 5 checksum is invalid. FIXED.
  12. binaries/uclibc/rootfs.arm-.ext4: Group descriptor 6 checksum is invalid. FIXED.
  13. binaries/uclibc/rootfs.arm-.ext4: Adding dirhash hint to filesystem.
  14. /lost+found not found. CREATED.:                                                                                
  15. binaries/uclibc/rootfs.arm-.ext4: 1926/2352 files (0.5% non-contiguous), 41430/55876 blocks
复制代码
但是,不知道为何,这些命令放到make里面,却返回错误,使得无法继续make。
有谁知道的,告诉我一下:green-[email=green-waste@163.com]waste@163.com[/email] 谢谢。
对于这样做出来的ext4,查看了一下,和ext3/ext2,都一样大小,觉得很奇怪:
  1. [root@linux-41lh buildroot]$>ls binaries/uclibc/rootfs.arm-.* -l
  2. -rwxrwxrwx 1 buildroot users 57217024 2009-10-16 12:59 binaries/uclibc/rootfs.arm-.ext2
  3. -rwxrwxrwx 1 buildroot users 57217024 2009-10-16 12:59 binaries/uclibc/rootfs.arm-.ext3
  4. -rwxrwxrwx 1 buildroot users 57217024 2009-10-16 13:06 binaries/uclibc/rootfs.arm-.ext4
复制代码

最后,通过烧写到板子上,验证结果是,kernel无法mount识别这样做出来的ext4.而对于原来的ext2和后来制作出来的ext3,是可以的。
也就是,这样做出来的ext4,好像还是有问题的,记录于此,以待后解。。。
【参考资料】
1.Image types
http://docs.openembedded.org/usermanual/html/image_types.html
2.[oe] [PATCH] Auto resizing ext2/ext3 images (from Poky)
http://projects.linuxtogo.org/pipermail/openembedded-devel/2008-December/007202.html
3.tune2fs的几个选项
http://linux.bloghome.cn/posts/45002.html
4.genext2fs
http://www.linuxcertif.com/man/8/genext2fs/
5.使用tune2fs将ext3转换为ext4
http://www.linuxhobby.com/2009/06/tune2fs-ext3-convert-ext4/
6.【推荐】man TUNE2FS
http://bbs.qxntc.edu.cn/cgi-bin/cgiman?8+tune2fs
7.Ext3详解
http://wiki.donews.com/index.php/Ext3
8.【推荐】Ext4 Howto
http://ext4.wiki.kernel.org/index.php/Ext4_Howto
9.[转]Ext4,Ext3的特点和区别
http://hi.baidu.com/serial_story/blog/item/f8d36360ff4006d58cb10db1.html

[ 本帖最后由 crifan 于 2009-11-11 13:54 编辑 ]

评分

参与人数 1可用积分 +30 收起 理由
T-Bagwell + 30 精品文章

查看全部评分

论坛徽章:
5
摩羯座
日期:2014-07-22 09:03:552015元宵节徽章
日期:2015-03-06 15:50:392015亚冠之大阪钢巴
日期:2015-06-12 16:01:352015年中国系统架构师大会
日期:2015-06-29 16:11:2815-16赛季CBA联赛之四川
日期:2018-12-17 14:10:21
2 [报告]
发表于 2009-12-08 11:19 |只看该作者
Dreamice兄,这个咋不给精华呢,写的多好啊
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP