Skip to content

davidar/bootsh

Repository files navigation

bootsh

A comprehensive POSIX userspace, including a C compiler, in a single tiny (<1MB) executable.

  • Bootstrappable: bootsh contains a variety of builtin commands (including grep, diff, sed, xzcat, sha1sum, ninja and many more) providing a solid POSIX base to bootstrap a full GNU/Linux distribution from source.

  • Self-hosting: bootsh can compile itself from source, thanks to its builtin cc command which implements a full C99 compiler.

  • Tiny: bootsh can be compiled into a single ~700KB binary executable in under 10 seconds. With UPX it can be reduced to half that size.

Build

Just run ./configure && ninja. The configure script will prompt you for any missing build dependencies. If you don't have ninja, you can run make to bootstrap with the builtin copy of samurai.

Usage

A Docker image is provided to demonstrate how bootsh can be used in a self-contained environment.

docker run --rm -it davidar/bootsh

This image contains four files:

  • /bin/sh: the bootsh executable

  • /sbin/init: a small shell script for constructing the root filesystem and bootstrapping musl libc from source

  • /bin/configure-musl.sh: sets up an alternative ninja-based build system for musl

  • /bin/awk: a C script (note the #!/bin/cc -run interpreter line) which is JIT compiled as needed

Upon running the Docker image, it will bootstrap itself by constructing a minimal root filesystem on top of this.

Alternatively, you can build a minimal Linux distribution by running

scripts/build-docker.sh --kernel

This will produce a compressed kernel in build/bzImage and a compressed root filesystem in build/initramfs.cpio.xz (whose contents are the same as the Docker image). Together they occupy less than 2MB. To boot the kernel in QEMU, run

scripts/run-qemu.sh

POSIX Compliance

bootsh implements all of the mandatory POSIX commands (and a number of optional commands) except for the following:

  • system administration: at, batch, crontab, df, logger, lp, man, newgrp, ps
  • text/locale processing: csplit, gencat, iconv, locale, localedef, pr, split
  • interactive tools: ed, mailx, mesg, unexpand, write
  • terminal control: stty, tabs, tput
  • miscellaneous: bc, join, m4, pathchk, pax, tsort

Credits

bootsh is based on several MIT/BSD licensed projects: