logo

bootstrap-initrd

Linux initrd to bootstrap from a small binary seed git clone https://anongit.hacktivis.me/git/bootstrap-initrd.git/

README.md (7525B)


  1. # bootstrap-initrd
  2. ```
  3. Copyright 2017 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
  4. SPDX-License-Identifier: MPL-2.0
  5. ```
  6. A initrd generator for Linux to bootstrap a POSIX-ish system from a reasonably small binary seed.
  7. ## Status
  8. - [x] Small binary seed of only TCC and musl (~1.2MB of binaries, depending on the architecture), enforced by [deblob](https://hacktivis.me/projects/deblob)
  9. - [x] Capable of bootstrapping <https://git.sr.ht/~mcf/oasis>
  10. - [ ] Self-replicating: Able to reassemble the initrd with Alpine apks
  11. - [ ] Self-hosting: Able to recompile all the software used from source (including tcc and musl)
  12. - [x] Code compiled by `init.sh` is reviewable, mostly thanks to a lack of autotools
  13. ## Explorations
  14. - Reduce the binary seed even further, without compromising on keeping the bootstrapping simple and reasonably fast
  15. ## Non-Goals
  16. - GNU Environment, there is already <https://github.com/fosslinux/live-bootstrap> for this and it's a massive effort
  17. - Become a distro, at worst it should end up deferring to an existing ports system like <https://www.pkgsrc.org/>
  18. ## Architectures
  19. You can set `ALPINE_ARCH` to change the architecture, by default it's set to `x86_64`.
  20. - `aarch64`: Works except for extras (tested on HoneyComb LX2k with linux 6.12.21-gentoo)
  21. - `armhf`: Untested
  22. - `armv7`: Untested
  23. - `riscv64`: Works except for extras (tested on VisionFive2 with linux-lts from Alpine)
  24. - `x86`: Works
  25. - `x86_64` (aka amd64): Works
  26. ## Rationales
  27. Each of those roughly by their build order.
  28. ### TCC (binary)
  29. Need to start somewhere and TCC allows to interpret C, allowing to avoid seeding another interpreter.
  30. The reason to not pick Guile+MesCC instead is because I find Guile Scheme to be less well-known than amd64 itself.
  31. ### musl (binary)
  32. Need a libc to start somewhere, tryhards could maybe compile it from source with TCC to reduce the seed further but this hasn't been tried.
  33. It's `libc.a` is removed, to shave off 9.1MB from the binary seed, going from 11MB total to 1.2MB total, you're likely going to rebuild musl anyway since this is a sort of stage0.
  34. ### TCC as ar(1) implementation
  35. Meanwhile:
  36. - Binutils: 300+ MiB repository of sources, generated artifacts frequently over 1MB, and test fixtures also often over 1MB. Nope.
  37. ### OpenBSD ksh
  38. Portable version done by Dr. Brian Robert Callahan aka ibara@, of OpenBSD.
  39. Buildable with only a C compiler while being nicely complete (maybe even too much).
  40. Builtin commands (as of 7.6):
  41. - defined in c_sh.c: ., :, [, break, builtin, continue, eval, exec, exit, false, return, set, shift, times, trap, wait, read, test, true, ulimit, umask, unset, suspend
  42. - defined in c_ksh.c: alias, cd, command, echo, export, fc, getopts, jobs, kill, let, print, pwd, readonly, type, typeset, unalias, whence, bg, fg (and bind when emacs-mode is enabled)
  43. Meanwhile:
  44. - loksh: similar port but header names overrides the libc ones
  45. - mrsh: Too incomplete for actual use, but trivial to build with only a C Compiler
  46. - heirloom-sh: Also buildable with only a C Compiler but fails to allocate memory at launch
  47. - bash, yash: autoconf, so needs an existing shell
  48. - dash: autoconf and generator scripts, so needs an existing shell
  49. - mksh: ./Build.sh, so needs an existing shell
  50. - AT&T ksh: Way too big to even try, might as well try Perl
  51. ### OpenBSD yacc
  52. Portable version done by Dr. Brian Robert Callahan aka ibara@, of OpenBSD.
  53. Uses a BSD-style configure script, trivial to diff between versions and adjust hardcoded compiler flags (no utilities to run said script yet).
  54. Meanwhile:
  55. - bison: autoconf, way too early
  56. - byacc: autoconf
  57. - [yacc from compilertools.net](https://web.archive.org/web/20220511161030/http://dinosaur.compilertools.net/): Domain expired years ago and turns out Gentoo was the only distro still providing it
  58. ### utils-std
  59. My own software, which explicitly allows to bootstrap with an incomplete POSIX environment such as this one.
  60. Meanwhile:
  61. - GNU coreutils: Autoconf, therefore needs the utilities it's building plus some extras to already be available
  62. - Busybox and Toybox: Heavy dependency on GNU Make, bash, …, which can only come much later on in the bootstrapping process
  63. ## sbase
  64. Simple `ed` and `sed` implementations which uses `regex.h` instead of some broken regex engine.
  65. Lack of support of `-i` option on sed(1) is a bit annoying, might patch this.
  66. Meanwhile:
  67. - minised: Broken regex engine which is too limited to pass `./configure` checks like the one in GNU make
  68. - GNU sed: `./configure` script requires an existing sed (*why*), doesn't seems like there's a workaround.
  69. ### (One True) awk
  70. Reference implementation and AFAIK the one used in BSDs, can be built with only a Yacc implementation and a C Compiler.
  71. ### pdpmake
  72. Public Domain POSIX make, trivial to compile without an existing make, features future POSIX additions and common extensions.
  73. Meanwhile:
  74. - bmake (NetBSD make port): autotools configure script, simpler than the one in GNU make but still unreviewable
  75. - OpenBSD make, port at <https://github.com/ibara/make> is incomplete and likely outdated
  76. - (OpenOffice) dmake: Horribly massive
  77. ### bzip2
  78. Builds with C Compiler + POSIX make.
  79. Meanwhile:
  80. - pbzip2: Requires C++ compiler
  81. ### zlib
  82. Simple albeit slightly broken `./configure` script (see patches).
  83. ### pigz
  84. Simple, needs make + c compiler + zlib.
  85. Note: Vendored zopfli got removed, so no compression beyond -9
  86. Meanwhile:
  87. - GNU gzip: Autotools
  88. ### Heirloom-devtools lex
  89. Slightly messy Makefiles but only has few dependencies.
  90. Meanwhile:
  91. - flex: Autotools
  92. ### Heirloom-devtools m4
  93. Slightly messy Makefiles but only has few dependencies.
  94. Meanwhile:
  95. - GNU m4: Not even close
  96. - OpenBSD m4 aka om4: Requires a more modern lex than heirloom-devtools provides
  97. ### Heirloom (toolchest) diff, sort
  98. Slightly messy Makefiles but only has few dependencies.
  99. ### Heirloom (toolchest) tar
  100. Slightly messy Makefiles but only has few dependencies.
  101. Meanwhile:
  102. - libarchive aka bsdtar: Autotools
  103. - GNU tar: [No.](https://www.roguelazer.com/blog/surprising-behavior-in-gnu-tar/)
  104. ### extras as packed tarballs
  105. - GNU make: Required by the other extras
  106. - muxzcat: To decompress qbe tarball
  107. - lua: For oasis
  108. - muon: For pkgconf and git without autotools
  109. - pkgconf: For iproute2
  110. - iproute2: Basic networking configuration
  111. - bearssl: small TLS library
  112. - tiny-curl: Still pretty big but hopefully close enough to the usual one
  113. - cacert (from curl.haxx.se): Maybe could be reduced to a handful of CAs (like maybe even just Let's Encrypt)
  114. - git: For oasis
  115. - e2fsprogs: In case you need to format some extra storage
  116. You can automatically build all of the above with `/extras-build-all.sh` but be warned that some use pre-generated autotools blobs which harms reviewability.
  117. You can also exclude those tarballs from the initrd with setting the `EXCLUDE_EXTRAS` environment variable to any value.
  118. ## Launching in QEMU
  119. * You need a Linux kernel, so far no known version limitations
  120. * Combination of `panic=1` and `-no-reboot` allows to exit+relaunch
  121. ```
  122. $ ./make-initrd.sh && qemu-system-x86_64 -enable-kvm -m 512 -kernel /boot/vmlinuz-6.6.21-gentoo -initrd bootstrap-initrd/x86_64.cpio.gz -append 'init=/init console=ttyS0 panic=1' -nographic -no-reboot
  123. ```
  124. ## Dev setup via bubblewrap
  125. ```
  126. $ ./make-root.sh && bwrap --clearenv --unshare-all --bind bootstrap-initrd/x86_64/ / --proc /proc --dev /dev --uid 0 --gid 0 /init
  127. ```
  128. Useful as it allows to manipulate the environment externally, for example to edit files in an editor more comfortable than `ed(1)`.