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