android文件系统\busybox文件系统的启动介绍
快速链接:
.
👉👉👉 个人博客笔记导读目录(全部) 👈👈👈
1、android文件系统(rootfs)
在uboot中检查启动参数,如果是normal mode,则load boot.img以及boot.img中的ramdisk,如果是recovery mode,则会load recovery.img以及recovery.img中的ramdisk。
注意:如果开启了system_as_root功能(在android9.0及其后的版本中要求开启了),原先boot.img中的ramdisk搬移到了system.img中。开启system_as_root功能,需要在cmdline中添加"skip_initramfs"参数
kernel/linux/init/initramfs.c中的populate_rootfs()检查到了skip_initramfs后,不去解压uboot解析后的ramdisk,而是创建了一个default_rootfs()空目录,然后将整个system.img mount到根目录.
(normal mode时)
acct charger data init init.currenttest.rc init.recovery.aquilac_evb.rc init.zygote64_32.rc oem sbin system verity_key
bin config default.prop init.aquilac_evb.rc init.environ.rc init.usb.configfs.rc lost+found proc sdcard ueventd.aquilac_evb.rc
bugreports cores dev init.ata.rc init.factory.rc init.usb.rc mnt product storage ueventd.rc
cache d etc init.calibration.rc init.rc init.zygote32.rc odm res sys vendor
(recovery mode时)
acct charger data init odm proc root sideload system_root vendor
bin config default.prop init.rc oem product sbin storage tmp vendor_file_contexts
bugreports cores dev init.recovery.aquilac_evb.rc plat_file_contexts prop.default sdcard sys ueventd.aquilac_evb.rc vendor_property_contexts
cache d etc mnt plat_property_contexts res sepolicy system ueventd.rc verity_key
2、busybox文件系统(rootfs)
xxxx
3、android init的启动 / busybox init的启动
#cat /proc/cmdline
firmware_class.path=/vendor/firmware uart_dma keep_dbgclk_on clk_ignore_unused log_buf_len=1M printk.devkmsg=on pmic_status=0x2 lcd_id=ID1901, fb_base=FB17e200000, fb_size=SZ7f8000, lcd_config=CF101. androidboot.serialno=0123456789 board_id=2 crash_page=0x10c040000 init=/init skip_initramfs rootwait root=/dev/dm-0 dm="system none ro,0 1 android-verity /dev/mmcblk0p20" veritykeyid=id:7e4333f9bba00adfe0ede979e28ed1920492b40f buildvariant=userdebug printk_nc earlycon nokaslr androidboot.dtbo_idx=0 androidboot.hardware=aquilac_evb androidboot.selinux=enforcing
在kernel_init()中:
(1)先检查ramdisk_execute_command变量(对应的cmdline中的rdinit参数,该参数是一个可执行文件的名字),如果存在则执行.
(2)、再检查execute_command(对应的cmdline中的init参数,该参数是一个可执行文件的名字),如果存在则执行,然后返回.
(3)、如果步骤(2)不存在,则会尝试执行"/sbin/init"、“/etc/init”、“/bin/init”、“/bin/sh”
vim kernel/linux/init/main.c
static int __ref kernel_init(void *unused)
{
int ret;
kernel_init_freeable();
/* need to finish all async __init code before freeing the memory */
async_synchronize_full();
free_initmem();
mark_readonly();
system_state = SYSTEM_RUNNING;
numa_default_policy();
flush_delayed_fput();
printk("kernel_init enter\n");
if (ramdisk_execute_command) {
ret = run_init_process(ramdisk_execute_command);
if (!ret)
return 0;
pr_err("Failed to execute %s (error %d)\n",
ramdisk_execute_command, ret);
}
/*
* We try each of these until one succeeds.
*
* The Bourne shell can be used instead of init if we are
* trying to recover a really broken machine.
*/
if (execute_command) {
ret = run_init_process(execute_command);
if (!ret)
return 0;
panic("Requested init %s failed (error %d).",
execute_command, ret);
}
printk("kernel_init execute_command after\n");
if (!try_to_run_init_process("/sbin/init") ||
!try_to_run_init_process("/etc/init") ||
!try_to_run_init_process("/bin/init") ||
!try_to_run_init_process("/bin/sh"))
return 0;
panic("No working init found. Try passing init= option to kernel. "
"See Linux Documentation/init.txt for guidance.");
}
在android的设计中,根目录下的init就是system/core/init/init.cpp编译生成的可执行文件,并且cmdline添加了"init=/init"参数, 自然而然的就运行了android的init,接下来就是执行parse init.rc、load property、selinux等程序。android init的流程就不在本文介绍了。
在非android系统的设计中(如busybox文件系),依然在cmdline添加了"init=/init"参数,但此时根目录下的init是busybox中的init程序
busybox init程序会依次调用:
a. 为init设置信号处理过程
b. 初始化控制台
c. 剖析/etc/inittab文件
d. 执行系统初始化命令行,缺省情况下会使用/etc/init.d/rcS
e. 执行所有导致init暂停的inittab命令(动作类型:wait)
f. 执行所有仅执行一次的inittab(动作类型:once)
其中,/etc/inittab不是linux shell脚本,有一定的语法规则,如下是我系统中的inittab:
This is run first except when booting in single-user mode.
#Startup the system
::sysinit:/bin/mount -t proc proc /proc
::sysinit:/bin/mount -t sysfs sysfs /sys
::sysinit:/bin/mount -t devtmpfs devtmpfs /dev
::sysinit:/bin/mount -o remount,rw /
::sysinit:/bin/mkdir -p /dev/pts
::sysinit:/bin/mount -t devpts devpts /dev/pts
::sysinit:/bin/mount -a
::sysinit:/etc/init.d/rcS
#Stuff to do before rebooting
::ctrlaltdel:/sbin/reboot
::shutdown:/etc/init.d/rcK
::shutdown:/sbin/swapoff -a
::shutdown:/bin/umount -a -r
#Stuff to do when restarting the init process
::restart:/sbin/init
#set hostname
null::sysinit:/bin/busybox hostname -F /etc/hostname
ttyS0::respawn:-/bin/sh
相关文章
- Android 项目中文件夹作用(res文件夹详细介绍)
- 在Chrome调试WebView内页面(Android环境)
- 【一文就懂】Android Kotlin协程用法介绍
- android Unhandled exception type ParseException提示报错
- 转:Android中Context详解 ---- 你所不知道的Context
- Android系统移植(一)-让android系统在目标平台上运行起来
- Android学习--Assets资源文件读取及AssetManager介绍
- ubuntu16.04下安装jdk和android studio
- Android Material Design-Defining Custom Animations(自己定义动画)-(六)
- Android使得手机拍照功能的发展(源共享)
- 【Android】应用程序Activity启动过程分析
- 关于Android导入开源项目:Error:Unable to load class 'org.gradle.api.publication.maven.internal.DefaultMavenFa
- Android ViewDataBinding之include与ViewStub的介绍与使用
- Android Jetpack WorkManager 介绍
- Android测试工具 UIAutomator入门与介绍
- android 登录申请微博所需图片资料
- Android中的利器-AsyncTask
- 原生Android开发基础项目结构介绍
- Android 网络基础 -- Web发展及 TCP/IP 、HTTP 介绍
- 【Android 命令行工具】Android 命令行工具简介 ( 官方文档 | SDK 命令行工具 | SDK 构建工具 | SDK 平台工具 | 模拟器工具 | Jetifier 工具 )
- 介绍一款比Android原生模拟器还要快的模拟器Genymotion(转)
- Android开发中,那些让你相见恨晚的方法、类或接口
- 2.Android网络编程-web介绍以及Tomcat安装使用
- 3.Android-ADT之helloworld项目结构介绍
- 我的Android进阶之旅------>WindowManager.LayoutParams介绍
- 我的Android进阶之旅------>介绍一款集录制与剪辑为一体的屏幕GIF 动画制作工具 GifCam