Core Package Installation into Target RootFS
Core Package Installation into Target RootFS
Now we construct the actual operating system filesystem that will be compressed into rootfs.squashfs.
Step 1: Base Filesystem Skeleton
Create the standard FHS directory structure with modern Usr-Merge symlinks:
$ mkdir -p "$SYSROOT"/{etc,root,home,proc,sys,dev,tmp,run,var}
$ mkdir -p "$SYSROOT"/usr/{bin,lib,share}
$ mkdir -p "$SYSROOT"/var/{log,cache,lib}
# Establish the Usr-Merge
$ cd "$SYSROOT"
$ ln -sf usr/bin bin
$ ln -sf usr/bin sbin
$ ln -sf usr/lib lib
$ ln -sf usr/bin usr/sbinStep 2: Compile & Install BusyBox
BusyBox provides our core command suite (ls, cat, grep, sh, vi, tar):
$ cd "$BYOL_ROOT/build"
$ tar -xf "$BYOL_ROOT/sources/busybox-1.36.1.tar.bz2"
$ cd busybox-1.36.1
$ make defconfig
# Cross-compile against musl toolchain
$ make CROSS_COMPILE="${TARGET}-" $MAKEFLAGS
$ make CROSS_COMPILE="${TARGET}-" CONFIG_PREFIX="$SYSROOT" installStep 3: Base System Configuration Files
Create standard Unix identity and host configuration files:
# /etc/passwd
cat << 'EOF' > "$SYSROOT/etc/passwd"
root:x:0:0:root:/root:/bin/sh
daemon:x:1:1:daemon:/usr/sbin:/bin/false
nobody:x:65534:65534:nobody:/nonexistent:/bin/false
EOF
# /etc/group
cat << 'EOF' > "$SYSROOT/etc/group"
root:x:0:
daemon:x:1:
wheel:x:10:root
video:x:27:
audio:x:29:
nobody:x:65534:
EOF
# /etc/shadow (root with empty password for instant live login)
cat << 'EOF' > "$SYSROOT/etc/shadow"
root:::0:99999:7:::
daemon:*:19000:0:99999:7:::
nobody:*:19000:0:99999:7:::
EOF
chmod 600 "$SYSROOT/etc/shadow"
# /etc/hostname
echo "byol-box" > "$SYSROOT/etc/hostname"
# /etc/inittab
cat << 'EOF' > "$SYSROOT/etc/inittab"
::sysinit:/etc/init.d/rcS
tty1::respawn:/sbin/getty 38400 tty1
ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100
::ctrlaltdel:/sbin/reboot
::shutdown:/etc/init.d/rcK
EOF
# /etc/init.d/rcS
cat << 'EOF' > "$SYSROOT/etc/init.d/rcS"
#!/bin/sh
mount -t proc none /proc
mount -t sysfs none /sys
mount -t devtmpfs none /dev
echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s
hostname -F /etc/hostname
ifconfig lo 127.0.0.1 up
echo "=========================================="
echo " Welcome to BYOL Linux 1.0 (Rolling) "
echo "=========================================="
EOF
chmod +x "$SYSROOT/etc/init.d/rcS"Step 4: Compressing into SquashFS
Now compress the staged rootfs into the live payload:
$ mkdir -p "$BYOL_ROOT/iso-staging/byol"
$ mksquashfs "$SYSROOT" "$BYOL_ROOT/iso-staging/byol/rootfs.squashfs" \
-comp zstd \
-b 1048576 \
-noappendThe entire operating system payload is now staged.