Skip to content

Building extremely minimalistic Linux distribution from source

License

Notifications You must be signed in to change notification settings

msiedlarek/minimal-linux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minimal Linux

This is a proof-of-concept of an extremely minimalistic Linux distribution, built directly from upstream source. The distribution consists only of:

  • Linux kernel
  • musl libc
  • busybox init and userland utilities
  • LLVM compiler infrastructure, including clang, libc++ and binutils

In theory, this is just enough to have a working shell, a text editor and a compiler. You can write everything else you need yourself. :)

The distribution is cross-compiled by default and currently x86_64 and ARM64 targets are supported. Everything is statically linked for simplicity. All sources are copied into this repository from upstream, without any modifications or patches.

Building

There is no real build and packaging system. The entire build process is wrapped in a very simple, linear shell script. It is intended to be easy to understand and strip the entire process of any magic. You could theoretically just copy and paste each commands into your shell.

Dependencies

  • A C/C++ compiler toolchain (GCC or Clang)
  • ccache to make recompilation faster for huge Linux and LLVM codebases
  • QEMU and libguestfs tools to run the built distribution in a virtual machine

Toolchain

First, we build the cross-compilation toolchain based on LLVM:

./toolchain.sh

This installs the toolchain in ./toolchain, including clang, binutils and libc++ statically linked against musl. This toolchain is capable of producing binaries for all supported platforms (x86_64 and ARM64) and the host system.

Target

Next, we use the toolchain to build the actual target system. This is done with a simple script, taking the target architecture as its only argument.

./target.sh x86_64
./target.sh arm64

After the build, the complete target sysroot can be found in ./target/<architecture>. It can be used directly as a chroot environment, or serve as an actuall root filesystem booted into by a real machine.

Testing

Included script allows you to build a disk from the previously built systroot and run it using QEMU.

./run.sh x86_64
./run.sh arm64

Related projects and inspiration

About

Building extremely minimalistic Linux distribution from source

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published