Linux下 解包/打包 Android 映像文件 system.img, boot.img, ramdisk.img, userdata.img.

2014年10月20日 ⁄ 计算机视觉 ⁄ 共 1372字⁄ ⁄ 暂无评论

转自: http://blog.csdn.net/yulix/article/details/12968705

Android源码编译成功后会输出映像文件:system.img,boot.img, ramdisk.img,userdata.img等等。有时我们需要修改里面的内容,下面列出在Linux下如何解包/打包这些映像文件。

ramdisk.img

ramdisk.img是经cpio打包、并用gzip压缩的文件。

解包: 新建一个工作目录,把当前目录更改为该工作目录,执行下面命令(注意: img文件位置可能不同).

[plain] view plaincopy

  1. gunzip -c  $HOME/img/ramdisk.img | cpio -i

打包:在工作目录下,把该目录下的所有内容打包

[plain] view plaincopy

  1. find . | cpio -o -H newc | gzip > ../newramdisk.img

参考文档:  http://android-dls.com/wiki/index.php?title=HOWTO:_Unpack%2C_Edit%2C_and_Re-Pack_Boot_Images

boot.img

boot.img包含2K字节头部,后面跟着的是zImage格式内核和和ramdisk格式的根文件系统。

解包工具: Android自带的unpackbootimg,以及一些脚本工具比如split_bootimg.pl

打包工具: Android自带的mkbootimg。

参考资料 :

中文请看: http://blog.csdn.net/wh_19910525/article/details/8200372

  英文请看:  http://android-dls.com/wiki/index.php?title=HOWTO:_Unpack%2C_Edit%2C_and_Re-Pack_Boot_Images

system.img (EXT4)

system.img 是 sparse image格式文件,现有的mount命令无法直接处理。

我们得把sparse image格式转变为普通的img格式,Android源码中带的ext4_utils可以做这个,没有Android源码也不用担心,该工具的源代码已被剥离出来,可以自行下载编译,地址是:http://forum.xda-developers.com/showthread.php?t=1081239

我们得到工具有: simg2img,make_ext4fs等等:

解包:

[plain] view plaincopy

  1. simg2img system.img system.img.ext4
  2. mkdir mnt_dir
  3. sudo mount -t ext4 -o loop system.img.ext4 mnt_dir

打包:

[plain] view plaincopy

  1. sudo make_ext4fs -s -l 512M -a system system_new.img mnt_dir

注意:在我的机器上必须用root权限执行make_ext4fs,否则新生成的image文件无法使用。

userdata.img (EXT4)

和system.img(EXT4) 一样处理

 

 

( file_context_open: Error getting file context handle (No such file or directory)
No such file or directory )

参考下面链接:

http://forum.xda-developers.com/galaxy-s2/general/ref-unpacking-repacking-stock-rom-img-t1081239/page23

the problem is that this version requires a file_contexts file. This can be extracted from boot.img. The filename is file_contexts
1. extract boot.img (i used AndroidImageKitchen for this)
2. call make_ext4fs with -S parameter
i.e.

Code:

make_ext4fs -l -s 2690M -a system -S <PATH_TO_FILE_CONTEXTS_FILE> system.img.ext4 <WHEREEVER_YOU_MOUNTED_SYSTEM_TO>

btw: the name of the mountpoint doesnt matter. So calling your mountpoint sys was no problem

If you have extracted boot.img the file_contexts-file should be located in the ramdisk folder.

Don't panic if there is no such file. In this case you just have to use an earlier version of make_ext4fs.

The file_contexts file is used by versions of android which use SELinux. I only found this on android versions >= 4.3.

 

 

所以最终的命令是:

./make_ext4fs -s -l 550M -a system -S ./file_contexts system_new.img mnt_dir

 

make_ext4fs [ -l <len> ] [ -j <journal size> ] [ -b <block_size> ]

    [ -g <blocks per group> ] [ -i <inodes> ] [ -I <inode size> ]

    [ -L <label> ] [ -f ] [ -a <android mountpoint> ]

    [ -S file_contexts ]

    [ -z | -s ] [ -w ] [ -c ] [ -J ] [ -v ]

    <filename> [<directory>]

 

参数解析

#make_ext4fs -s -l 512M -a root -L linux  ./rootfs_qt.img  ./root

执行之后即会将root文件打包成  rootfs_qt.img 文件系统镜像。

-l 512M"是分区大小,i9100的system分区是512M;

-s就是生成ext4的S模式制作;

-s  就是生成ext4的S模式制作;

-l 512M 是分区大小;

-a root 是指这个img用于Linux系统若为-a system即表示为android系统,挂载点即是/system。使用这个参数,make_ext4fs会根据private/android_filesystem_config.h里定义好的权限来给文件夹里的所有文件重新设置权限,如果你刷机以后发现有文件权限不对,可以手工修改android_filesystem_config.h来添加权限,重新编译make_ext4fs,也可以不使用 “-a system”参数,这样就会使用文件的默认权限

./rootfs_qt.img 表示在当前目录下生成镜像文件。

./root 指定源路径

Linux下 解包/打包 Android 映像文件 system.img, boot.img, ramdisk.img, userdata.img.的更多相关文章

  1. linux下rar包的解压方法

    linux下rar包的解压方法 学习了:https://blog.csdn.net/yonggeit/article/details/72190246?utm_source=itdadao&u ...

  2. apk 解包 打包

    APK应用程序的解包.修改.编辑.汉化.打包及应用 前两讲主要讲玩机的最基本的知识,集中在如何刷机.本讲是进级的内容,来谈谈与apk应用程序有关的知识,内容包括akp文件的解包.打包.反编辑.解析.汉 ...

  3. Linux下RPM包的安装

    Linux下RPM包安装 二进制包(RPM包.系统默认包) RPM安装 rpm -ivh 包全名(查询依赖网址:http://www.rpmfind.net) -i(install):安装 -v(ve ...

  4. linux下抓包学习--tcpdump的使用

    一.为什么需要学这个 很多时候,开发环境上不会出现问题.但在测试或者现场时,总是会有很多莫名其妙的问题. 这时候,能在出问题的环境上,开启抓包,然后再去重现问题的话,这时候,就可以拿到第一手的资料了. ...

  5. 监控io性能、free、ps命令、查看网络状态、Linux下抓包 使用介绍

    第7周第2次课(5月8日) 课程内容: 10.6 监控io性能 10.7 free命令10.8 ps命令10.9 查看网络状态10.10 linux下抓包扩展tcp三次握手四次挥手 http://ww ...

  6. Linux centos7日常运维——监控io性能、free内存命令、ps进程命令、查看网络状态、linux下抓包

    一.监控io性能 Linux系统出现了性能问题,一般我们可以通过top.iostat.free.vmstat等命令来查看初步定位问题.其中iostat可以给我们提供丰富的IO状态数据. iostat ...

  7. Linux下C程序的内存映像

    2.Linux下C程序的内存映像 2.1. 代码段.只读数据段(1)对应着程序中的代码(函数),代码段在Linux中又叫文本段(.text)(2)只读数据段就是在程序运行期间只能读不能写的数据,con ...

  8. Linux压缩解压 tar.gz格式的文件.查看tomcat是否运行

    tar命令详解 -c: 建立压缩档案 -x:解压 -t:查看内容 -r:向压缩归档文件末尾追加文件 -u:更新原压缩包中的文件 这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用 ...

  9. 将linux下的rm命令改造成移动文件至回收站【转】

    转自:http://blog.csdn.net/a3470194/article/details/16863803 [-] 将linux下的rm命令改造成移动文件至回收站 将AIX下的rm命令改造成移 ...

随机推荐

  1. 2、Reactive Extensions for .NET(译)

    实验3-引入 .net 中的 events 到 Rx 目标:前面实验中的使用各种工厂构造方法创建一个 可观察序列是一个部分.把 .net 中现有的异步数据源进行关联 是更重要的事情.在这次实验中我们将 ...

  2. oracle ORA-12545:因目标主机或对象不存在

    解决方法: 1.首先从最基本的入手,这里打开计算机右击,选择管理 2. 找到里面的服务和应用程序,打开服务 3.找到: OracleOraDb11g_home1TNSListener OracleSe ...

  3. Codeforces461A Appleman and Toastman 贪心

    题目大意是Appleman每次将Toastman给他的Ni个数拆分成两部分后再还给Toastman,若Ni == 1则直接丢弃不拆分.而Toastman将每次获得的Mi个数累加起来作为分数,初始时To ...

  4. spark源码 hashpartitioner

    def nonNegativeMod(x: Int, mod: Int): Int = { val rawMod = x % mod rawMod + () mod ) def getPartitio ...

  5. [Linux]gcc/libc/glibc

    转自:http://blog.csdn.net/weiwangchao_/article/details/16989713 1.gcc(gnu collect compiler)是一组编译工具的总称. ...

  6. Entity Framework(五):使用配置伙伴创建数据库

    在上一篇文章中讲了如何使用fluent API来创建数据表,不知道你有没有注意到一个问题.上面的OnModelCreating方法中,我们只配置了一个类Product,也许代码不是很多,但也不算很少, ...

  7. CSS(五):背景、列表、超链接伪类、鼠标形状控制属性

    一.背景属性 1.背景属性用来设置页面元素的背景样式. 2.常见背景属性 属性 描述 background-color 用来设置页面的背景色,取值如red,#ff0000 background-ima ...

  8. HeadFirst Jsp 09 (JSTL)

    JSTL (jsp standard tag library) 标准标记库 JSTL 安装, 注意你的每一个项目都需要一个 JSTL副本, 并把它放在WEB-INF/lib 目录下, 在 Tomcat ...

  9. KMP + 求相等前后缀--- POJ Seek the Name, Seek the Fame

    Seek the Name, Seek the Fame Problem's Link: http://poj.org/problem?id=2752 Mean: 给你一个字符串,求这个字符串中有多少 ...

  10. 通过http输出流的方式从将html写入到Excel

    private void HtmlResponseToExecl() { //将数据(html)导入到Excel中 Response.Charset = "gb2312"; Res ...