COSCUP 2023

mkroot walkthrough
2023-07-29, 09:30–10:00 (Asia/Taipei), TR 412-1
Language: English

The toybox package contains a ~300 line bash script that cross-compiles a Linux system from source code and boots it to a shell prompt on a dozen QEMU targets, with a second script that automatically smoketests each image (it boots and runs, and the clock, network, and block device all work) to regression test new versions of Linux, qemu, and itself.


The toybox project (providing Android's command line since 2015) includes a system builder script (https://github.com/landley/toybox/blob/master/mkroot/mkroot.sh) which compiles a toybox root filesystem, adds a small init script, packages it into Linux via initmpfs, and boots the result under qemu on 14 different architectures. (And on hexagon if you have a comet board. And j-core if you have a turtle board.)

The build script itself is a single standalone bash script but it can include additional scripts (on the command line) to build and install more packages into the initramfs. See mkroot/root/dropbear in the toybox source for an example.

The architecture-specific part for each target is only a few lines, including Linux kernel configuration. For example: QEMU=s390x KARCH=s390 VMLINUX=arch/s390/boot/bzImage KCONF=MARCH_Z900,PACK_STACK,VIRTIO_NET,VIRTIO_BLK,SCLP_TTY,SCLP_CONSOLE,SCLP_VT220_TTY,SCLP_VT220_CONSOLE,S390_GUEST

This is the successor to the earlier project (https://landley.net/aboriginal/about.html) which built a 7 package Linux system, rebuilt itself from source code under the result, and then built Linux From Scratch (and an older version of Gentoo) under that. Work is ongoing, but I'd eventually like to get the mkroot version of this minimal self-hosting development environment down to 4 packages (probably toybox, musl-libc, linux, and tinycc).


Difficulty

Skilled

Target Audience

It's not science if you can't reproduce it from scratch under laboratory conditions.

Rob maintains toybox and mkroot, writes linux docs, works to make Android a self-hosting development environment, fetches coffee for the j-core developers... Long ago he maintained busybox, co-founded Penguicon and Linucon, wrote for the Motley Fool, taught at Austin Community College, etc.