Embedding the Bootloader, Kernel, and SquashFS Filesystem
Embedding the Bootloader, Kernel, and SquashFS Filesystem
A Live installation ISO must compress a multi-gigabyte operating system into an image that can run entirely in system RAM without touching the user’s hard drive. The core technology that enables this is SquashFS combined with OverlayFS.
+-----------------------------------------------------------+
| The Live System Filesystem Stack |
| |
| [ Unified / View (Writable Root Filesystem) ] |
| | |
| +-----------------------+-----------------------+ |
| | | |
| v v |
| [ Upper Layer: tmpfs ] (RAM) [ Lower Layer ] |
| (Writes, new files, modified /etc) (Read-Only) |
| | |
| v |
| [ SquashFS Loopback ]
| (/byol/rootfs.squashfs)
+-----------------------------------------------------------+
Step 1: Compressing the RootFS with SquashFS
SquashFS is a highly compressed, read-only filesystem built directly into the Linux kernel (CONFIG_SQUASHFS=y). It achieves extreme compression ratios (often exceeding 60-70% reduction in size) using Zstandard (zstd) or XZ compression:
# Compressing the clean rootfs directory tree:
$ mksquashfs /mnt/target/ iso-staging/byol/rootfs.squashfs \
-comp zstd \
-Xcompression-level 19 \
-b 1048576 \
-noappend \
-wildcards \
-e "proc/*" -e "sys/*" -e "dev/*" -e "tmp/*"A 6 GB operating system rootfs compresses down to approximately 1.8 GB!
Step 2: OverlayFS (Making Read-Only Writable)
Because SquashFS is strictly read-only, how can a live user create files in /home or install testing software?
The initramfs uses the kernel’s OverlayFS driver to stack an in-memory writable tmpfs layer on top of the read-only SquashFS mount:
# Inside the Live Initramfs /init script:
# 1. Mount the optical ISO or USB drive
mount -t iso9660 -o ro /dev/disk/by-label/BYOL_LIVE /mnt/cdrom
# 2. Mount the compressed SquashFS payload via loop device
mkdir -p /mnt/squashfs
mount -t squashfs -o loop /mnt/cdrom/byol/rootfs.squashfs /mnt/squashfs
# 3. Create writable memory overlay
mkdir -p /mnt/overlay/upper /mnt/overlay/work /newroot
mount -t tmpfs none /mnt/overlay
# 4. Combine them into a unified rootfs using OverlayFS
mount -t overlay overlay -o lowerdir=/mnt/squashfs,upperdir=/mnt/overlay/upper,workdir=/mnt/overlay/work /newroot
# 5. Switch into the writable live desktop!
exec switch_root /newroot /sbin/initNow, any file modified by the user writes only to RAM (tmpfs), leaving the underlying SquashFS payload pristine.