feat: Implement complete Zero OS Alpine Initramfs Builder

- Complete bash framework with strict error handling
- Modular library system (docker, alpine, components, initramfs, kernel, testing)
- Rust component integration (zinit, rfs, mycelium) with musl targeting
- Rootless Docker/Podman support for GitHub Actions
- Centralized configuration in config/build.conf
- 2-stage module loading system
- Strip + UPX optimization for minimal size
- Complete zinit integration replacing OpenRC
- GitHub Actions CI/CD pipeline
- Comprehensive documentation and usage guides

Components:
- Latest stable kernel 6.12.44
- Alpine Linux 3.22 base
- ThreeFold components: zinit, mycelium, rfs, corex
- Target: ~8-12MB final initramfs.cpio.xz
This commit is contained in:
2025-08-31 12:31:49 +02:00
commit 860b9aa161
81 changed files with 30118 additions and 0 deletions

103
configs/init Executable file
View File

@@ -0,0 +1,103 @@
#!/bin/sh
# Alpine-based Zero-OS Init Script
# Maintains identical flow to original busybox version
echo ""
echo "============================================"
echo "== ZERO-OS ALPINE INITRAMFS =="
echo "============================================"
echo "[+] creating ram filesystem"
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -t tmpfs tmpfs /mnt/root -o size=1536M
mount -t devtmpfs devtmpfs /dev
echo "[+] building ram filesystem"
target="/mnt/root"
# Copy Alpine filesystem to tmpfs (same as original)
echo " copying /bin..."
cp -ar /bin $target
echo " copying /etc..."
cp -ar /etc $target
echo " copying /lib..."
cp -ar /lib* $target
echo " copying /usr..."
cp -ar /usr $target
echo " copying /root..."
cp -ar /root $target
echo " copying /sbin..."
cp -ar /sbin $target
echo " copying /tmp..."
cp -ar /tmp $target
echo " copying /var..."
cp -ar /var $target
echo " copying /run..."
cp -ar /run $target
# Create essential directories
mkdir -p $target/dev
mkdir -p $target/sys
mkdir -p $target/proc
mkdir -p $target/mnt
# Mount filesystems in tmpfs
mount -t proc proc $target/proc
mount -t sysfs sysfs $target/sys
mount -t devtmpfs devtmpfs $target/dev
# Mount devpts for terminals
mkdir -p $target/dev/pts
mount -t devpts devpts $target/dev/pts
echo "[+] setting environment"
export PATH
echo "[+] probing drivers"
# Use Alpine's udev instead of busybox udevadm
if [ -x /sbin/udevd ]; then
echo " starting udevd..."
udevd --daemon
echo " triggering device discovery..."
udevadm trigger --action=add --type=subsystems
udevadm trigger --action=add --type=devices
udevadm settle
echo " stopping udevd..."
kill $(pidof udevd) || true
else
echo " warning: udevd not found, skipping hardware detection"
fi
echo "[+] loading essential drivers"
# Load core drivers for storage and network
modprobe btrfs 2>/dev/null || true
modprobe fuse 2>/dev/null || true
modprobe overlay 2>/dev/null || true
# Load storage drivers
modprobe ahci 2>/dev/null || true
modprobe nvme 2>/dev/null || true
modprobe virtio_blk 2>/dev/null || true
modprobe virtio_scsi 2>/dev/null || true
# Load network drivers
modprobe virtio_net 2>/dev/null || true
modprobe e1000 2>/dev/null || true
modprobe e1000e 2>/dev/null || true
# Unmount init filesystems
umount /proc 2>/dev/null || true
umount /sys 2>/dev/null || true
echo "[+] checking for debug files"
if [ -e /init-debug ]; then
echo " executing debug script..."
sh /init-debug
fi
echo "[+] switching root"
echo " exec switch_root /mnt/root /sbin/zinit init"
exec switch_root /mnt/root /sbin/zinit init

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,59 @@
# Essential kernel modules for Zero-OS Alpine initramfs
# This file contains a curated list of essential modules for network and storage functionality
# Comments are supported (lines starting with #)
# Network drivers - Intel
e1000
e1000e
igb
ixgbe
i40e
ice
# Network drivers - Realtek
r8169
8139too
8139cp
# Network drivers - Broadcom
bnx2
bnx2x
tg3
b44
# Network drivers - Atheros
atl1
atl1e
atl1c
alx
# VirtIO drivers
virtio_net
virtio_scsi
virtio_blk
virtio_pci
# Tunnel and container support
tun
overlay
# Storage subsystem (essential only)
scsi_mod
sd_mod
# Control Groups (cgroups v1 and v2) - essential for container management
cgroup_pids
cgroup_freezer
cgroup_perf_event
cgroup_device
cgroup_cpuset
cgroup_bpf
cgroup_debug
memcg
blkio_cgroup
cpu_cgroup
cpuacct
hugetlb_cgroup
net_cls_cgroup
net_prio_cgroup
devices_cgroup

View File

@@ -0,0 +1,46 @@
# MINIMAL Alpine packages for Zero-OS embedded initramfs
# Target: ~50MB total (not 700MB!)
# Core system (essential only)
alpine-baselayout
busybox
musl
# Module loading & hardware detection
eudev
eudev-hwids
eudev-libs
eudev-netifnames
kmod
# Console/terminal management
util-linux
# Essential networking (for Zero-OS connectivity)
iproute2
ethtool
# Filesystem support (minimal)
btrfs-progs
dosfstools
# Essential libraries only
zlib
# Network utilities (minimal)
dhcpcd
tcpdump
bmon
# Random number generation (for crypto/security)
haveged
# SSH access and terminal multiplexer
openssh-server
zellij
# Essential debugging and monitoring tools included
# NO development tools, NO curl/wget, NO python, NO redis
# NO massive linux-firmware package
# Other tools will be loaded from RFS after network connectivity

10
configs/sources.conf Normal file
View File

@@ -0,0 +1,10 @@
# sources.conf - Components to download and build for initramfs
# Format: TYPE:NAME:URL:VERSION:BUILD_FUNCTION[:EXTRA_OPTIONS]
# Git repositories to clone and build
git:zinit:https://github.com/threefoldtech/zinit:master:build_zinit
git:mycelium:https://github.com/threefoldtech/mycelium:0.6.1:build_mycelium
git:rfs:https://github.com/threefoldtech/rfs:development:build_rfs
# Pre-built releases to download
release:corex:https://github.com/threefoldtech/corex/releases/download/2.1.4/corex-2.1.4-amd64-linux-static:2.1.4:install_corex:rename=corex

View File

@@ -0,0 +1,2 @@
exec: sh /etc/zinit/init/cgroup.sh
oneshot: true

View File

@@ -0,0 +1,2 @@
exec: /sbin/getty -L 9600 console
restart: always

View File

@@ -0,0 +1 @@
exec: depmod -a

2
configs/zinit/getty.yaml Normal file
View File

@@ -0,0 +1,2 @@
exec: /sbin/getty -L 115200 ttyS0 vt100
restart: always

View File

@@ -0,0 +1,2 @@
exec: /sbin/getty console linux
restart: always

View File

@@ -0,0 +1,2 @@
exec: haveged -w 1024 -d 32 -i 32 -v 1
oneshot: true

View File

@@ -0,0 +1,6 @@
#!/bin/bash
echo "start ash terminal"
while true; do
getty -l /bin/ash -n 19200 tty2
done

10
configs/zinit/init/cgroup.sh Executable file
View File

@@ -0,0 +1,10 @@
set -x
mount -t tmpfs cgroup_root /sys/fs/cgroup
subsys="pids cpuset cpu cpuacct blkio memory devices freezer net_cls perf_event net_prio hugetlb"
for sys in $subsys; do
mkdir -p /sys/fs/cgroup/$sys
mount -t cgroup $sys -o $sys /sys/fs/cgroup/$sys/
done

10
configs/zinit/init/modprobe.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/bash
modprobe fuse
modprobe btrfs
modprobe tun
modprobe br_netfilter
echo never > /sys/kernel/mm/transparent_hugepage/enabled
ulimit -n 524288

10
configs/zinit/init/ntpd.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/sh
ntp_flags=$(grep -o 'ntp=.*' /proc/cmdline | sed 's/^ntp=//')
params=""
if [ -n "$ntp_flags" ]; then
params=$(echo "-p $ntp_flags" | sed s/,/' -p '/g)
fi
exec ntpd -n $params

4
configs/zinit/init/routing.sh Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/bash
echo "Enable ip forwarding"
echo 1 > /proc/sys/net/ipv4/ip_forward

3
configs/zinit/init/shm.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/sh
mkdir /dev/shm
mount -t tmpfs shm /dev/shm

View File

@@ -0,0 +1,15 @@
#!/bin/ash
if [ -f /etc/ssh/ssh_host_rsa_key ]; then
# ensure existing file permissions
chown root:root /etc/ssh/ssh_host_*
chmod 600 /etc/ssh/ssh_host_*
exit 0
fi
echo "Setting up sshd"
mkdir -p /run/sshd
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa
ssh-keygen -f /etc/ssh/ssh_host_ecdsa_key -N '' -t ecdsa -b 521
ssh-keygen -f /etc/ssh/ssh_host_ed25519_key -N '' -t ed25519

4
configs/zinit/init/udev.sh Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/sh
udevadm trigger --action=add
udevadm settle

2
configs/zinit/lo.yaml Normal file
View File

@@ -0,0 +1,2 @@
exec: ip l set lo up
oneshot: true

View File

@@ -0,0 +1,2 @@
exec: sh /etc/zinit/init/modprobe.sh
oneshot: true

View File

@@ -0,0 +1,6 @@
exec: /usr/bin/mycelium --key-file /tmp/mycelium_priv_key.bin
--tun-name my0 --silent --peers tcp://188.40.132.242:9651 tcp://136.243.47.186:9651
tcp://185.69.166.7:9651 tcp://185.69.166.8:9651 tcp://65.21.231.58:9651 tcp://65.109.18.113:9651
tcp://209.159.146.190:9651 tcp://5.78.122.16:9651 tcp://5.223.43.251:9651 tcp://142.93.217.194:9651
after:
- network

View File

@@ -0,0 +1,5 @@
exec: dhcpcd eth0
after:
- depmod
- udevd
- udev-trigger

3
configs/zinit/ntp.yaml Normal file
View File

@@ -0,0 +1,3 @@
exec: sh /etc/zinit/init/ntpd.sh
after:
- network

View File

@@ -0,0 +1,2 @@
exec: sh /etc/zinit/init/routing.sh
oneshot: true

2
configs/zinit/shm.yaml Normal file
View File

@@ -0,0 +1,2 @@
exec: /etc/zinit/init/shm.sh
oneshot: true

View File

@@ -0,0 +1,2 @@
exec: sh /etc/zinit/init/sshd-setup.sh
oneshot: true

3
configs/zinit/sshd.yaml Normal file
View File

@@ -0,0 +1,3 @@
exec: /usr/sbin/sshd -D -e
after:
- sshd-setup

View File

@@ -0,0 +1,6 @@
exec: sh /etc/zinit/init/udev.sh
oneshot: true
after:
- depmod
- udevmon
- udevd

1
configs/zinit/udevd.yaml Normal file
View File

@@ -0,0 +1 @@
exec: udevd

View File

@@ -0,0 +1 @@
exec: udevadm monitor