Mic_chen

It is not the strongest of the species that survive, nor the most intelligent, but the one most responsive to change

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

原文来自:https://blog.csdn.net/z1026544682/article/details/100137317,有小部分理解修改。

 

Ext4有两种镜像方式:一种是裸镜像(raw image)和 稀疏镜像(sparse image)。

1.1.1  raw image

1. 描述

种是raw ext4 image(即raw image),使用file观察:其特点是完整的ext4分区镜像(如果未使用满则使用0进行填充),可以直接使用mount进行挂载,也可以直接烧写,因此比较大。

好处:升级时设备进行简单的顺序数据写入。通过file可以查看其类型:

file rootfs.ext4

rootfs.ext4: Linux rev 1.0 ext4 filesystem data, UUID=db0ca30c-e2c8-4b9a-b48a-a1620d43aa3a (extents) (large files) (huge files)

2. 制作方法

a方式一:使用 mkfs.ext4

创建挂载目录:mkdir mnt 

生成一个128M0roofs.ext4文件:dd if=/dev/zero of=rootfs.ext4 bs=1M count=128

将新文件格式化为ext4格式:mkfs.ext4 rootfs.ext4

将文件挂载到mnt目录,注意这里我们要使用mount –o loop的属性,表示我们要把rootfs.ext4当作硬盘分区挂载到mnt:echo 123456 | sudo -S mount -o loop rootfs.ext4 mnt

rootfs目录下的文件拷贝到mnt目录下:sudo cp rootfs/* mnt/ -rf

卸载mnt就完成了ext4文件系统制作:sudo umount mnt

 

b方式二:使用make_ext4fs(不带-s参数)

make_ext4fs -l 128M  roofs.ext4 rootfs

-l 128Mext4文件系统分区大小

rootfs.ext4:生成ext4文件系统的目标文件

rootfs:生成ext4文件系统的源目录

3. 烧写(以mmc为例)

uboot下使用 mmc write linux下使用 dd,直接烧写。

 

1.1.2  simg: sparse image

1. 描述

另外一种是sparse ext4 image,它是将raw ext4进行稀疏描述,因此尺寸比较小(制作目录有多少文件就计算多少,没有全零填充)。不能直接挂载。在linux下也不能直接烧写,需要还原为 raw image格式。通过file来查看:

file alg.ext4

alg.ext4: Android sparse image, version: 1.0, Total of 262144 4096-byte output blocks in 35 input chunks

 

2. 制作方法

同样使用make_ext4fs,只需加上-s选项,即可生成sparse image。

make_ext4fs -l 128M -s roofs.simg rootfs

-s:生成ext4S模式镜像(simg

 

3. 烧写(linux

使用simg2imgsimg sparse ext4 image)还原为 raw ext4 image,再像raw image 那样烧写。

simg2img roofs.simg rootfs.ext4

posted on 2020-11-24 15:52  Mic_chen  阅读(4490)  评论(0编辑  收藏  举报