1 |
On 20/07/02 08:05AM, Benda Xu wrote: |
2 |
> >> Could you please remind me why we need a bootstrap-init? Can we just |
3 |
> >> exec the Android init when the lxc-guest starts? |
4 |
> > |
5 |
> > Yeah sure. Apparently, Android needs to parse its device tree for early |
6 |
> > mounting partitions, before exec'ing `init`. Plus even before dealing |
7 |
> > with the dt, we need to mount `/system` and switch root to it. |
8 |
> > I could create the environment for "using /system as root" w/o the help |
9 |
> > of `bootstrap-init` but I couldn't deal with the device tree easily. |
10 |
> > |
11 |
> > `bootstrap-init` creates the entire environment for android to boot from |
12 |
> > scratch and then finally exec's `init`. So I proposed to use it instead |
13 |
> > of manually setting up the LXC container for system-as-root devices. |
14 |
> > That way the setup is clean as we only need a /dev directory and a static |
15 |
> > `bootstrap-init` binary inside of the LXC rootfs. |
16 |
> |
17 |
> In principle you can choose your way of achieving things. But |
18 |
> considering you got stuck in making a functional 'bootstrap-init', I |
19 |
> have 2 questions. |
20 |
|
21 |
I would like to clarify first that bootstrap-init works fine, but due to |
22 |
the nature of build-system it requires, I was having difficulties in |
23 |
compiling it natively in arm64 Gentoo. |
24 |
|
25 |
> 1. If you need to prepare a proper environment for Android to boot |
26 |
> inside the LXC guest, please check out LXC container hooks in |
27 |
> lxc.container.conf(5) manpage. Another init seems an overkill for |
28 |
> me. |
29 |
|
30 |
I was going with this approach initially, but the container configs just |
31 |
don't seem apt for a process like this. I mean to mount the early |
32 |
partitions only, I have no clue how I would approach parsing the device |
33 |
tree using the LXC conf. |
34 |
|
35 |
Although I had made some slight edits to the original container hook |
36 |
scripts, for keeping the rootfs clean after reboots and more. You could |
37 |
check the modified scripts in [1]. |
38 |
|
39 |
> 2. Why bootstrap-init needs to be written in C++? Would a shell script |
40 |
> enough? |
41 |
|
42 |
I followed Magisk's approach of booting SAR Android. I thought of |
43 |
rewriting the entire init but realised that that would be rather |
44 |
inefficient. Therefore, I stripped all the "Magisk-y" code and put |
45 |
forward the bare minimum required for functioning. |
46 |
In theory, we could rewrite it all in shell, but then again, I would not |
47 |
recommend it as it could be somewhat lengthy. |
48 |
Moreover, this setup is scalable and it could be extended later for any |
49 |
new boot-scheme Android pulls up. |
50 |
|
51 |
If required by any situation, I can willingly rewrite it in shell as |
52 |
well. |
53 |
|
54 |
Regards, |
55 |
Gunwant |
56 |
|
57 |
[1] https://wantguns.gitlab.io/blog/sharkbait/starting_android_in_gentoo/#install-lxc |