<aside> ⚠️ Magisk的Patch操作和实际的工作流程涉及到Android启动的不同方法,对不同设备不同系统有着不同的启动方式,这是一个很复杂的问题,将会直接决定Magisk的工作流程,有时间需要进行细致分析。在这里仅给出一种实现方式的解析,其他类比起来看就行。
</aside>
<aside> 💡 测试设备为RedMI Note7(lavender),非A/B分区设备,刷入Android 12类原生系统。
</aside>
- 内嵌阅读
大致意思是,Magisk将Android设备的Boot方式分为三种
- Method A - Legacy ramdisk: This is how all Android devices used to boot (good old days). The kernel uses
initramfs
as rootdir, and exec/init
to boot.
- Devices that does not fall in any of Method B and C’s criteria
- Method B - Legacy SAR: This method was first seen on Pixel 1. The kernel directly mounts the
system
partition as rootdir and exec/init
to boot.
- Devices with
(LV = 28)
- Google: Pixel 1 and 2. Pixel 3 and 3a when
(RV = 28)
.- OnePlus: 6 - 7
- Maybe some
(LV < 29)
Android Go devices?- Method C - 2SI ramdisk SAR: This method was first seen on Pixel 3 Android 10 developer preview. The kernel uses
initramfs
as rootdir and exec/init
inrootfs
. Thisinit
is responsible to mount thesystem
partition and use it as the new rootdir, then finally exec/system/bin/init
to boot.
- Devices with
(LV >= 29)
- Devices with
(LV < 28, RV >= 29)
, excluding those that were already using Method B- Google: Pixel 3 and 3a with
(RV >= 29)
Method Initial rootdir Final rootdir A rootfs rootfs B system system C rootfs system 除此之外,Magisk将设备大致分为4类。
Type Boot Method Partition 2SI Ramdisk in boot I A A-only No boot ramdisk II B A/B Any recovery ramdisk III B A-only Any N/A IV C Any Yes Hybrid ramdisk
<aside>
💡 由于测试机为RedMI Note7(lavender)(非A/B分区设备,即****A-only设备),即使刷入了Android12的类原生系统,但是其出场Android版本API=28,即LV=28,设备属于第三类设备,分区中没有包含有**ramdisk
,但是后面会讲到测试设备刚好是红米,幸运的是它居然可以接受手动添加到boot中的ramdisk
,但是Magisk 实际上不可能知道设备引导加载程序是否接受虚拟硬盘,因此假设始终通知用户使用恢复模式,因此在Magsik界面Ramdisk后面显示否。
理论上来说测设设备启动是采用MethodB: Legacy SAR方式进行启动,内核直接挂载到system分区作为根目录并且直接运行/init进行启动。通过后面日志分析也可以发现,[2.686814] magiskinit: LegacySARInit
这里第一阶段进入了LegacySARInit
** 分支。因此本文重点分析这种启动方式,其次Method C是现如今Android设备常规启动方式,因此也进行分析。
</aside>