Android开发 System Ramdisk相关

Andoird7 上 Ramdisk挂载为根文件系统

在android7 上文件系统的root是挂载 ramdisk; ramdisk镜像是被打包在boot.img上。

可以通过unpack_bootimg 工具对boot.img镜像拆解:

unpack_bootimg需要执行android编译的环境设置后,make unpack_bootimg;

执行过程及结果:

yujixuan@yujixuan:~/prj/code/out/target/product/msm8953_64/bootout$ unpack_bootimg --boot_img boot.img --out ./
boot_magic: ANDROID!
kernel_size: 15636495
kernel load address: 2147516416
ramdisk size: 1350215
ramdisk load address: 2164260864
second bootloader size: 0
second bootloader load address: 2163212288
kernel tags load address: 2147483904
page size: 2048
boot image header version: 0
os version and patch level: 235147554
product name: 
command line args: console=ttyHSL0,115200,n8 androidboot.console=ttyHSL0 androidboot.hardware=qcom msm_rtb.filter=0x237 ehci-hcd.park=3 androidboot.bootdevice=7824900.sdhci lpm_levels.sleep_disabled=1 earlyprintk buildvariant=userdebug
additional command line args: 
yujixuan@yujixuan:~/prj/code/out/target/product/msm8953_64/bootout$ ls
boot.img  kernel  ramdisk  second
yujixuan@yujixuan:~/prj/code/out/target/product/msm8953_64/bootout$ file *
boot.img: Android bootimg, kernel, ramdisk, page size: 2048, cmdline (console=ttyHSL0,115200,n8 androidboot.console=ttyHSL0 androidboot.hardware=qcom msm_rtb.filter=)
kernel:   Linux kernel ARM boot executable zImage (little-endian)
ramdisk:  gzip compressed data, from Unix
second:   empty

通过File命令可知,ramdisk是个gzip文件;

修改为.gz 后缀文件后,通过gunzip解压它可得到ramdisk归档后的文件,接着再用 cpio命令进行解档,过程如下:

yujixuan@yujixuan:~/prj/code/out/target/product/msm8953_64/bootout$ mv ramdisk ramdisk.gz 
yujixuan@yujixuan:~/prj/code/out/target/product/msm8953_64/bootout$ ls
boot.img  kernel  ramdisk.gz  second
yujixuan@yujixuan:~/prj/code/out/target/product/msm8953_64/bootout$ gunzip ramdisk.gz 
yujixuan@yujixuan:~/prj/code/out/target/product/msm8953_64/bootout$ ls
boot.img  kernel  ramdisk  second
yujixuan@yujixuan:~/prj/code/out/target/product/msm8953_64/bootout$ cpio -i -F ramdisk 
5493 块
yujixuan@yujixuan:~/prj/code/out/target/product/msm8953_64/bootout$ ls
acct        config        etc                init.class_main.sh       init.qcom.early_boot.sh     init.qcom.usb.rc      init.usb.rc       proc               sdcard           service_contexts  ueventd.rc
boot.img    d             file_contexts.bin  init.environ.rc          init.qcom.factory.rc        init.qcom.usb.sh      init.zygote32.rc  property_contexts  seapp_contexts   storage           vendor
bugreports  data          fstab.qcom         init.mdm.sh              init.qcom.rc                init.rc               kernel            ramdisk            second           sys               verity_key
cache       default.prop  init               init.qcom.bms.sh         init.qcom.sh                init.target.rc        mnt               res                selinux_version  system
charger     dev           init.carrier.rc    init.qcom.class_core.sh  init.qcom.syspart_fixup.sh  init.usb.configfs.rc  oem               sbin               sepolicy         ueventd.qcom.rc

即可得到 系统启动后的根文件系统中的文件; 系统启动过程中会将system,vendor等img挂载到相应的路径上; 也可以看出这里的一些初始化文件,如init.rc uevent.rc 就是在boot.img中生效的;

在编译目录out下,对应的是root目录:

Android9及以上 system as root

在android9 及以上,根文件系统不是通过boot。img中的ramdisk直接来挂载根文件系统;而编译的ramdisk.img被打包到system.img中; 系统启动过程中,会将根目录切换到system目录下;

同样执行上面的步骤解析boot.img; 可以看到虽然ramdisk还有;但是是空文件;

yujixuan@yujixuan:~/prj/code/out/target/product/msm8953_64/bootout2$ unpack_bootimg --boot_img boot.img --out ./
boot_magic: ANDROID!
kernel_size: 16609898
kernel load address: 2147516416
ramdisk size: 0
ramdisk load address: 2164260864
second bootloader size: 0
second bootloader load address: 2163212288
kernel tags load address: 2147483904
page size: 2048
boot image header version: 1
os version and patch level: 301990199
product name: 
command line args: console=ttyHSL0,115200,n8 androidboot.console=ttyHSL0 androidboot.hardware=qcom msm_rtb.filter=0x237 ehci-hcd.park=3 lpm_levels.sleep_disabled=1 androidboot.bootdevice=7824900.sdhci earlycon=msm_serial_dm,0x78af000 firmware_class.path=/vendor/firmware_mnt/image androidboot.usbconfigfs=true loop.max_part=7 buildvariant=userdebug
additional command line args: 
recovery dtbo size: 0
recovery dtbo offset: 0
boot header size: 1648
yujixuan@yujixuan:~/prj/code/out/target/product/msm8953_64/bootout2$ ls
boot.img  kernel  ramdisk  second
yujixuan@yujixuan:~/prj/code/out/target/product/msm8953_64/bootout2$ file *
boot.img: Android bootimg, kernel, page size: 2048, cmdline (console=ttyHSL0,115200,n8 androidboot.console=ttyHSL0 androidboot.hardware=qcom msm_rtb.filter=)
kernel:   gzip compressed data, max compression, from Unix
ramdisk:  empty
second:   empty

想要修改一些初始化文件,则需要更新system.img;

动态分区super.img

android10上,则需要烧录包含system.img的super.img简单来看 是将system.img 和vendor.img打包在一起;它们的大小并非固定的;是由编译时决定的,更合理的使用内存空间;

posted @ 2021-06-22 11:47  yujixuan  阅读(270)  评论(0编辑  收藏  举报