logo

bootstrap-initrd

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

README.md (7116B)


  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`: Untested
  21. - `armhf`: Untested
  22. - `armv7`: Untested
  23. - `riscv64`: Broken, tcc snapshot needs to be updated
  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. ### loksh
  38. Linux/portable-port of OpenBSD Korn Shell, buildable with only a C compiler while being nicely complete (maybe even too much).
  39. Meanwhile:
  40. - mrsh: Too incomplete for actual use, but trivial to build with only a C Compiler
  41. - heirloom-sh: Also buildable with only a C Compiler but fails to allocate memory at launch
  42. - bash, yash: autoconf, so needs an existing shell
  43. - dash: autoconf and generator scripts, so needs an existing shell
  44. - mksh: ./Build.sh, so needs an existing shell
  45. - AT&T ksh: Way too big to even try, might as well try Perl
  46. ### OpenBSD yacc
  47. Portable version done by Dr. Brian Robert Callahan aka ibara, of OpenBSD.
  48. Uses a BSD-style configure script, trivial to diff between versions and adjust hardcoded compiler flags (no utilities to run said script yet).
  49. Meanwhile:
  50. - bison: autoconf, way too early
  51. - byacc: autoconf
  52. - [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
  53. ### utils-std
  54. My own software, which explicitly allows to bootstrap with an incomplete POSIX environment such as this one.
  55. Meanwhile:
  56. - GNU coreutils: Autoconf, therefore needs the utilities it's building plus some extras to already be available
  57. - Busybox and Toybox: Heavy dependency on GNU Make, bash, …, which can only come much later on in the bootstrapping process
  58. ## sed from suck(less) sbase
  59. Simple `sed` implementation which uses `regex.h` instead of some broken regex engine.
  60. Lack of support of `-i` flag is a bit annoying, might patch this.
  61. Meanwhile:
  62. - minised: Broken regex engine which is too limited to pass `./configure` checks like the one in GNU make
  63. - GNU sed: `./configure` script requires an existing sed (*why*), doesn't seems like there's a workaround.
  64. ### (One True) awk
  65. Reference implementation and AFAIK the one used in BSDs, can be built with only a Yacc implementation and a C Compiler.
  66. ### pdpmake
  67. Public Domain POSIX make, trivial to compile without an existing make, features future POSIX additions and common extensions.
  68. Meanwhile:
  69. - bmake (NetBSD make port): autotools configure script, simpler than the one in GNU make but still unreviewable
  70. - OpenBSD make, port at <https://github.com/ibara/make> is incomplete and likely outdated
  71. - (OpenOffice) dmake: Horribly massive
  72. ### bzip2
  73. Builds with C Compiler + POSIX make.
  74. Meanwhile:
  75. - pbzip2: Requires C++ compiler
  76. ### zlib
  77. Simple albeit slightly broken `./configure` script (see patches).
  78. ### pigz
  79. Simple, needs make + c compiler + zlib.
  80. Note: Vendored zopfli got removed, so no compression beyond -9
  81. Meanwhile:
  82. - GNU gzip: Autotools
  83. ### Heirloom-devtools lex
  84. Slighly messy Makefiles but only has few dependencies.
  85. Meanwhile:
  86. - flex: Autotools
  87. ### Heirloom-devtools m4
  88. Slighly messy Makefiles but only has few dependencies.
  89. Meanwhile:
  90. - GNU m4: Not even close
  91. - OpenBSD m4 aka om4: Requires a more modern lex than heirloom-devtools provides
  92. ### Heirloom (toolchest) diff, sort
  93. Slighly messy Makefiles but only has few dependencies.
  94. ### Heirloom (toolchest) tar
  95. Slighly messy Makefiles but only has few dependencies.
  96. Meanwhile:
  97. - libarchive aka bsdtar: Autotools
  98. - GNU tar: [No.](https://www.roguelazer.com/blog/surprising-behavior-in-gnu-tar/)
  99. ### extras as packed tarballs
  100. - GNU make: Required by the other extras
  101. - xz: Not for anything yet, but requires working around libtool to build so including it
  102. - lua: For oasis
  103. - pkgconf: For iproute2
  104. - iproute2: Basic networking configuration
  105. - skalibs: dependency of mdevd
  106. - mdevd: hotplug devices daemon
  107. - bearssl: small TLS library
  108. - tiny-curl: Still pretty big but hopefully close enough to the usual one
  109. - cacert (from curl.haxx.se): Maybe could be reduced to a handful of CAs (like maybe even just Let's Encrypt)
  110. - gettext-tiny: Much smaller replacement to GNU gettext, for git
  111. - git: For oasis
  112. - e2fsprogs: In case you need to format some extra storage
  113. You can automatically build all of the above with `/build-extras.sh` but be warned that those aren't as curated and due to lack of deblob, they might contain binaries and some use autotools which harms reviewability.
  114. You can also exclude those tarballs from the initrd with setting the `EXCLUDE_EXTRAS` environment variable to any value.
  115. ## Launching in QEMU
  116. * You need a Linux kernel, so far no known version limitations
  117. * Combination of `panic=1` and `-no-reboot` allows to exit+relaunch
  118. ```
  119. $ ./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
  120. ```
  121. ## Dev setup via bubblewrap
  122. ```
  123. $ ./make-root.sh && bwrap --clearenv --unshare-all --bind bootstrap-initrd/x86_64/ / --proc /proc --dev /dev --uid 0 /init
  124. ```
  125. Useful as it allows to manipulate the environment externally, for example to edit files in an editor more comfortable than `ed(1)`.