android 根文件系统,使用mkbootfs制作ramdisk根文件系统

本文介绍了Android系统如何使用mkbootfs和minigzip创建ramdisk根文件系统。通过解析mkbootfs和minigzip的原理,包括它们在制作过程中的文件处理规则,以及在Linux内核启动时的角色。同时,文章提到了使用config.txt配置文件以及Android内建的配置机制。最后,展示了如何在QEMU环境下验证ramdisk的使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境

Qemu:QEMU emulator version 3.1.0

Linux:Linux-4.14.13

工具链:arm-none-linux-gnueabi-gcc  (gcc version 4.8.3 20140320)

Android:7.1.2

busyBox:BusyBox v1.24.2

概述

Android系统使用的根文件系统是用mkbootfs和minigzip制作的,其中mkbootfs用于将根文件系统打包成cpio格式,也可以用cpio工具来打包,将来Linux内核在启动时会调用init/initramfs.c中的函数unpack_to_rootfs对cpio格式进行解包[调用路径:start_kernel --> rest_init --> kernel_init --> kernel_init_freeable --> do_basic_setup --> do_initcalls --> do_initcall_level --> do_one_initcall --> populate_rootfs --> unpack_to_rootfs],在内存中构造出根文件系统结构,mkbootfs工具是Android自己实现的,支持的功能也比cpio弱很多。minigzip也是Android实现的一个压缩工具,是对gzip的简化。

minigzip的源码位于:external/zlib/

mkbootfs的源码位于:system/core/cpio/mkbootfs.c

不过需要注意mkbootfs的功能要比cpio弱,从mkbootfs.c的代码注释中可以看出来:

/*NOTES

**

** - see buffer-format.txt from the linux kernel docs for

** an explanation of this file format

** - dotfiles are ignored

** - directories named ‘root‘ are ignored

** - device notes,pipes,etc are not supported (error)*/

上面的信息说明了如下几点:

1. 对cpio格式的说明,Linux内核文档Documentation/early-userspace/buffer-format.txt中有详细说明说明:

The full format of the initramfs buffer is defined by the following

grammar,where:* is used to indicate "0 or more occurrences of"(|) indicates alternatives+indicates concatenation

GZIP() indicates thegzip(1) of the operand

ALGN(n) means padding withnull bytes to an n-byteboundary

initramfs := (&

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值