The Architecture of Minimal Linux Live
Welcome to the wonderful world of Minimal Linux Live! :)
Minimal Linux Live (MLL) is a tiny educational Linux distribution, which is designed to be built from scratch by using a collection of automated shell scripts. Minimal Linux Live offers a core environment with just the Linux kernel, GNU C library, and Busybox userland utilities. Additional software can be included in the ISO image at build time by using a well-documented configuration file.
The generated ISO image file contains Linux kernel, GNU C library compiled with default options, Busybox compiled with default options, quite simple initramfs structure and some "overlay bundles" (the default build process provides few overlay bundles). You don't get Windows support out of the box, nor you get any fancy desktop environment. All you get is a simple shell console with default Busybox applets, network support via DHCP and... well, that's all. This is why it's called "minimal".
Note that by default Minimal Linux Live provides support for legacy BIOS systems. You can change the build configuration settings in the .config file and rebuild MLL with support for modern UEFI systems.
All build scripts are well organized and quite small in size. You can easily learn from the scripts, reverse engineer the build process and later modify them to include more stuff (I encourage you to do so). After you learn the basics, you will have all the necessary tools and skills to create your own fully functional Linux based operating system which you have built entirely from scratch.
Boot Process
BIOS
- The machine passes the execution control to the BIOS firmware.
- BIOS passes the execution control to the Syslinux boot loader, which is present in the MLL ISO image.
- The Syslinux boot loader has special configuration file
syslinux.cfg
which describes where the Linux kernel (kernel.xz) and the initramfs (rootfs.xz) files are located in the ISO image. - Syslinux loads both the kernel and the initramfs files in the RAM and then passes the execution control to the kernel.
- The kernel detects the available hardware and loads the corresponding necessary drivers.
- The kernel unpacks the initramfs archive (already loaded in the RAM by Syslinux) and then passes the execution control to the initramfs.
- At this point the actual execution control is passed to the shell script file
/init
, which is present in the initramfs file.
Refer to the init section below for more details on how /init
handles the OS preparation.
UEFI
- The machine passes the execution control to the UEFI firmware.
- UEFI detects properly configured EFI boot image that is present in the MLL ISO image.
- UEFI loads the EFI boot image from the MLL ISO image in the RAM.
- UEFI passes the execution control to the special EFI file
EFI/BOOT/BOOTx64.EFI
(for 64-bit machines) from the previously described EFI boot image. This special file is the entry point of the systemd-boot UEFI boot manager. - The
systemd-boot
UEFI boot manager has special configuration files (loader.conf and all files in the entries/ folder) which describe where the Linux kernel (kernel.xz) and the initramfs (rootfs.xz) files are located in the EFI boot image. systemd-boot
loads the kernel in the RAM.- The kernel detects the available hardware and loads the corresponding necessary drivers.
- The kernel loads the initramfs file in the RAM. Refer to the kernel EFI stub documentation for more details.
- The kernel unpacks the initramfs archive (already loaded in the RAM by the kernel) and then passes the execution control to the initramfs.
- At this point the actual execution control is passed to the shell script file
/init
, which is present in the initramfs file.
Refer to the init section below for more details on how /init
handles the OS preparation.
INIT
The /init
shell script is responsible to prepare the actual OS environment and to present the user with functional shell prompt.
The base initramfs structure is located here:
https://github.com/ivandavidov/minimal/tree/master/src/minimal_rootfs
The actual /init
script is located here:
https://github.com/ivandavidov/minimal/blob/master/src/minimal_rootfs/init
This is what happens when /init
is executed:
- All core filesystems (i.e. /dev, /sys, /proc) are mounted.
- The overlay system is prepared. At this point the initramfs structure and the overlay bundles are merged.
- The execution control is passed to
/sbin/init
which is located in the initramfs. /sbin/init
uses the special configuration file /etc/inittab which describes the system initialization actions.- All autorun scripts are executed one by one.
- Welcome message is displayed and the user is presented with functional shell prompt.
Filesystem Layout of MLL's ISO image
The default build process generates a bootable ISO image file named minimal_linux_live.iso
.
BIOS
When the property FIRMWARE_TYPE
in the configuration file .config
is set to bios
, the generated ISO image has the following structure.
# FIRMWARE_TYPE=bios
minimal_linux_live.iso
├── boot/
│ ├── kernel.xz
│ ├── rootfs.xz
│ └── syslinux/
├── EFI/
└── minimal/
boot/
This folder contains all files that are necessary for the proper BIOS boot process. More precisely, you can find the Linux kernel, the initial RAM filesystem (initramfs) and the boot loader.
boot/kernel.xz
This is the Linux kernel. The kernel detects the available hardware, loads necessary drivers and then it passes the execution control to the initramfs.
boot/rootfs.xz
This is the initial RAM filesystem. The initramfs file is an archive, automatically unpacked by the kernel in the RAM. The actual execution control is passed to the shell script file /init
, which must be present in the initramfs file.
boot/syslinux/
This folder contains the ISOLINUX boot loader (binaries and configuration files), part of the Syslinux project.
EFI/
This folder contains a simple .nsh
script which allows MLL to boot on EFI based machines, provided that these machines support UEFI shell.
minimal/
This folder contains all MLL overlay bundles (i.e. additional software prepared during the build process).
UEFI
When the property FIRMWARE_TYPE
in the configuration file .config
is set to uefi
, the generated ISO image has the following structure.
# FIRMWARE_TYPE=uefi
minimal_linux_live.iso
├── boot/
│ └── uefi.img
└── minimal/
boot/
This folder contains all files that are necessary for the proper UEFI boot process. More precisely, you can find the EFI boot image.
boot/uefi.img
This is the EFI boot image. It contains the systemd-boot UEFI boot manager, corresponding boot configurations, the Linux kernel and the initramfs.
minimal/
This folder contains all MLL overlay bundles (i.e. additional software prepared during the build process).
Initial workspace
These are the files and folders that you need in order to build Minimal Linux Live.
src/
├── .config
├── common.sh
├── 00_clean.sh
├── 01_get_kernel.sh
├── 02_build_kernel.sh
├── 03_get_glibc.sh
├── 04_build_glibc.sh
├── 05_prepare_sysroot.sh
├── 06_get_busybox.sh
├── 07_build_busybox.sh
├── 08_prepare_bundles.sh
├── 09_generate_rootfs.sh
├── 10_pack_rootfs.sh
├── 11_generate_overlay.sh
├── 12_get_syslinux.sh
├── 12_get_systemd-boot.sh
├── 13_prepare_iso.sh
├── 14_generate_iso.sh
├── 15_generate_image.sh
├── 16_cleanup.sh
├── minimal_boot/
├── minimal_config/
├── minimal_overlay/
└── minimal_rootfs/
Build Process
The MLL build process can be divided in several major phases.
- Preparations
- Kernel
- GNU C Library
- Initramfs
- Overlay bundles
- Packaging
- Boot loader
- ISO image
Common Properties And Functions
The shell script file common.sh is sourced in all MLL scripts. It provides common properties and functions.
Properties
SRC_DIR
SRC_DIR=src/
This is the main source directory, i.e. the property references the main project directory src/
.
CONFIG
CONFIG=src/.config
This is the main configuration file. The configuration properties are described here.
SOURCE_DIR
SOURCE_DIR=src/source/
This is the directory where all source archives are downloaded.
WORK_DIR
WORK_DIR=src/work/
This is the directory where all MLL artifacts are processed. All build actions happen in this directory.
KERNEL_INSTALLED
KERNEL_INSTALLED=src/work/kernel/kernel_installed/
This is the directory where the kernel and its corresponding header files are placed after the kernel build phase has been completed.
GLIBC_OBJECTS
GLIBC_OBJECTS=src/work/glibc/glibc_objects/
TODO...
GLIBC_INSTALLED
GLIBC_INSTALLED=src/work/glibc/glibc_installed/
TODO...
BUSYBOX_INSTALLED
BUSYBOX_INSTALLED=src/work/busybox/busybox_installed/
TODO...
SYSROOT
SYSROOT=src/work/sysroot/
TODO...
ROOTFS
ROOTFS=src/work/rootfs/
TODO...
OVERLAY_ROOTFS
OVERLAY_ROOTFS=src/work/overlay_rootfs/
TODO...
ISOIMAGE
OVERLAY_ROOTFS=src/work/isoimage/
TODO...
ISOIMAGE_OVERLAY
OVERLAY_ROOTFS=src/work/isoimage_overlay/
TODO...
Functions
read_property(prop_name)
This function reads properties from the main .config
file.
# Example
JOB_FACTOR=`read_property JOB_FACTOR`
download_source(url, file_to_save)
This function downloads the url
resource and saves it as $file_to_save
.
# Example
#
# This is the filesystem structure before the execution
# of the function.
#
# src/
# └── source/
# └── (no files/folders)
download_source \
'https://busybox.net/downloads/busybox-1.32.0.tar.bz2' \
$SOURCE_DIR/busybox-1.32.0.tar.bz2
# This is the filesystem structure after the execution
# of the function.
#
# src/
# └── source/
# └── busybox-1.32.0.tar.bz2
extract_source(archive_file, dest_dir)
This function extracts the archive archive_file
in the directory src/work/$dest_dir/
.
# Example
#
# This is the filesystem structure before the execution
# of the function.
#
# src/
# ├── source/
# │ └── busybox-1.32.0.tar.bz2
# └── work/
# └── (no files/folders)
extract_source \
$SOURCE_DIR/busybox-1.32.0.tar.bz2 \
busybox
# This is the filesystem structure after the execution
# of the function.
#
# src/
# ├── source/
# │ └── busybox-1.32.0.tar.bz2
# └── work/
# └── busybox
# └── busybox-1.32.0/