From cbdc08c71f06104abd1bc558b97be2d06dffd396 Mon Sep 17 00:00:00 2001 From: Jan De Landtsheer Date: Fri, 5 Sep 2025 17:29:46 +0200 Subject: [PATCH] Fix module dependency resolution for clean builds - Use container modules from kernel_modules stage for dependency resolution - Remove dependency on initramfs modules that haven't been copied yet - Fixes regression where clean builds had empty stage1.list - Dependency resolution now works correctly in clean build scenarios --- config/init | 2 +- config/zinit.old/cgroup.yaml | 2 ++ config/zinit.old/depmod.yaml | 1 + config/zinit.old/getty.yaml | 2 ++ config/zinit.old/gettyconsole.yaml | 2 ++ config/zinit.old/haveged.yaml | 2 ++ config/zinit.old/init/ashloging.sh | 6 ++++++ config/zinit.old/init/cgroup.sh | 10 ++++++++++ config/zinit.old/init/modprobe.sh | 10 ++++++++++ config/zinit.old/init/ntpd.sh | 10 ++++++++++ config/zinit.old/init/routing.sh | 4 ++++ config/zinit.old/init/shm.sh | 3 +++ config/zinit.old/init/sshd-setup.sh | 15 +++++++++++++++ config/zinit.old/init/udev.sh | 4 ++++ config/zinit.old/lo.yaml | 2 ++ config/zinit.old/local-modprobe.yaml | 2 ++ config/zinit.old/mycelium.yaml | 6 ++++++ config/zinit.old/network.yaml | 5 +++++ config/zinit.old/ntp.yaml | 3 +++ config/zinit.old/routing.yaml | 2 ++ config/zinit.old/shm.yaml | 2 ++ config/zinit.old/sshd-setup.yaml | 2 ++ config/zinit.old/sshd.yaml | 3 +++ config/zinit.old/udev-trigger.yaml | 6 ++++++ config/zinit.old/udevd.yaml | 1 + config/zinit.old/udevmon.yaml | 1 + config/{zinit => zinit.old}/zinit.conf | 0 config/zinit/console.yaml | 2 ++ config/zinit/gettyconsole.yaml | 2 +- config/zinit/init/sshd-setup.sh | 1 + initramfs/etc/issue | 4 ++-- initramfs/etc/motd | 10 ++++------ initramfs/etc/passwd | 2 +- scripts/lib/initramfs.sh | 14 +++++--------- 34 files changed, 123 insertions(+), 20 deletions(-) create mode 100644 config/zinit.old/cgroup.yaml create mode 100644 config/zinit.old/depmod.yaml create mode 100644 config/zinit.old/getty.yaml create mode 100644 config/zinit.old/gettyconsole.yaml create mode 100644 config/zinit.old/haveged.yaml create mode 100755 config/zinit.old/init/ashloging.sh create mode 100755 config/zinit.old/init/cgroup.sh create mode 100755 config/zinit.old/init/modprobe.sh create mode 100755 config/zinit.old/init/ntpd.sh create mode 100755 config/zinit.old/init/routing.sh create mode 100755 config/zinit.old/init/shm.sh create mode 100755 config/zinit.old/init/sshd-setup.sh create mode 100755 config/zinit.old/init/udev.sh create mode 100644 config/zinit.old/lo.yaml create mode 100644 config/zinit.old/local-modprobe.yaml create mode 100644 config/zinit.old/mycelium.yaml create mode 100644 config/zinit.old/network.yaml create mode 100644 config/zinit.old/ntp.yaml create mode 100644 config/zinit.old/routing.yaml create mode 100644 config/zinit.old/shm.yaml create mode 100644 config/zinit.old/sshd-setup.yaml create mode 100644 config/zinit.old/sshd.yaml create mode 100644 config/zinit.old/udev-trigger.yaml create mode 100644 config/zinit.old/udevd.yaml create mode 100644 config/zinit.old/udevmon.yaml rename config/{zinit => zinit.old}/zinit.conf (100%) create mode 100644 config/zinit/console.yaml diff --git a/config/init b/config/init index f05dc6e..9dd73a8 100755 --- a/config/init +++ b/config/init @@ -112,6 +112,6 @@ fi echo "[+] switching root" echo " exec switch_root /mnt/root /sbin/zinit init" -exec switch_root /mnt/root /sbin/zinit -d init +exec switch_root /mnt/root /sbin/zinit init ## \ No newline at end of file diff --git a/config/zinit.old/cgroup.yaml b/config/zinit.old/cgroup.yaml new file mode 100644 index 0000000..51c1869 --- /dev/null +++ b/config/zinit.old/cgroup.yaml @@ -0,0 +1,2 @@ +exec: sh /etc/zinit/init/cgroup.sh +oneshot: true \ No newline at end of file diff --git a/config/zinit.old/depmod.yaml b/config/zinit.old/depmod.yaml new file mode 100644 index 0000000..84bcee7 --- /dev/null +++ b/config/zinit.old/depmod.yaml @@ -0,0 +1 @@ +exec: depmod -a \ No newline at end of file diff --git a/config/zinit.old/getty.yaml b/config/zinit.old/getty.yaml new file mode 100644 index 0000000..cc962a5 --- /dev/null +++ b/config/zinit.old/getty.yaml @@ -0,0 +1,2 @@ +exec: /sbin/getty -L 115200 ttyS0 vt100 +restart: always \ No newline at end of file diff --git a/config/zinit.old/gettyconsole.yaml b/config/zinit.old/gettyconsole.yaml new file mode 100644 index 0000000..e4074a8 --- /dev/null +++ b/config/zinit.old/gettyconsole.yaml @@ -0,0 +1,2 @@ +exec: /sbin/getty console linux +restart: always \ No newline at end of file diff --git a/config/zinit.old/haveged.yaml b/config/zinit.old/haveged.yaml new file mode 100644 index 0000000..3f36285 --- /dev/null +++ b/config/zinit.old/haveged.yaml @@ -0,0 +1,2 @@ +exec: haveged -w 1024 -d 32 -i 32 -v 1 +oneshot: true \ No newline at end of file diff --git a/config/zinit.old/init/ashloging.sh b/config/zinit.old/init/ashloging.sh new file mode 100755 index 0000000..095206c --- /dev/null +++ b/config/zinit.old/init/ashloging.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +echo "start ash terminal" +while true; do + getty -l /bin/ash -n 19200 tty2 +done diff --git a/config/zinit.old/init/cgroup.sh b/config/zinit.old/init/cgroup.sh new file mode 100755 index 0000000..f1b623f --- /dev/null +++ b/config/zinit.old/init/cgroup.sh @@ -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 diff --git a/config/zinit.old/init/modprobe.sh b/config/zinit.old/init/modprobe.sh new file mode 100755 index 0000000..1417d41 --- /dev/null +++ b/config/zinit.old/init/modprobe.sh @@ -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 \ No newline at end of file diff --git a/config/zinit.old/init/ntpd.sh b/config/zinit.old/init/ntpd.sh new file mode 100755 index 0000000..52e4d30 --- /dev/null +++ b/config/zinit.old/init/ntpd.sh @@ -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 \ No newline at end of file diff --git a/config/zinit.old/init/routing.sh b/config/zinit.old/init/routing.sh new file mode 100755 index 0000000..95eab6f --- /dev/null +++ b/config/zinit.old/init/routing.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +echo "Enable ip forwarding" +echo 1 > /proc/sys/net/ipv4/ip_forward \ No newline at end of file diff --git a/config/zinit.old/init/shm.sh b/config/zinit.old/init/shm.sh new file mode 100755 index 0000000..39ac1fd --- /dev/null +++ b/config/zinit.old/init/shm.sh @@ -0,0 +1,3 @@ +#!/bin/sh +mkdir /dev/shm +mount -t tmpfs shm /dev/shm \ No newline at end of file diff --git a/config/zinit.old/init/sshd-setup.sh b/config/zinit.old/init/sshd-setup.sh new file mode 100755 index 0000000..3909a79 --- /dev/null +++ b/config/zinit.old/init/sshd-setup.sh @@ -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 diff --git a/config/zinit.old/init/udev.sh b/config/zinit.old/init/udev.sh new file mode 100755 index 0000000..2667522 --- /dev/null +++ b/config/zinit.old/init/udev.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +udevadm trigger --action=add +udevadm settle \ No newline at end of file diff --git a/config/zinit.old/lo.yaml b/config/zinit.old/lo.yaml new file mode 100644 index 0000000..e9a0623 --- /dev/null +++ b/config/zinit.old/lo.yaml @@ -0,0 +1,2 @@ +exec: ip l set lo up +oneshot: true \ No newline at end of file diff --git a/config/zinit.old/local-modprobe.yaml b/config/zinit.old/local-modprobe.yaml new file mode 100644 index 0000000..a8f3b24 --- /dev/null +++ b/config/zinit.old/local-modprobe.yaml @@ -0,0 +1,2 @@ +exec: sh /etc/zinit/init/modprobe.sh +oneshot: true diff --git a/config/zinit.old/mycelium.yaml b/config/zinit.old/mycelium.yaml new file mode 100644 index 0000000..e61252a --- /dev/null +++ b/config/zinit.old/mycelium.yaml @@ -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 \ No newline at end of file diff --git a/config/zinit.old/network.yaml b/config/zinit.old/network.yaml new file mode 100644 index 0000000..f272134 --- /dev/null +++ b/config/zinit.old/network.yaml @@ -0,0 +1,5 @@ +exec: dhcpcd eth0 +after: + - depmod + - udevd + - udev-trigger \ No newline at end of file diff --git a/config/zinit.old/ntp.yaml b/config/zinit.old/ntp.yaml new file mode 100644 index 0000000..e7164e8 --- /dev/null +++ b/config/zinit.old/ntp.yaml @@ -0,0 +1,3 @@ +exec: sh /etc/zinit/init/ntpd.sh +after: + - network \ No newline at end of file diff --git a/config/zinit.old/routing.yaml b/config/zinit.old/routing.yaml new file mode 100644 index 0000000..16220e1 --- /dev/null +++ b/config/zinit.old/routing.yaml @@ -0,0 +1,2 @@ +exec: sh /etc/zinit/init/routing.sh +oneshot: true \ No newline at end of file diff --git a/config/zinit.old/shm.yaml b/config/zinit.old/shm.yaml new file mode 100644 index 0000000..7919fea --- /dev/null +++ b/config/zinit.old/shm.yaml @@ -0,0 +1,2 @@ +exec: /etc/zinit/init/shm.sh +oneshot: true \ No newline at end of file diff --git a/config/zinit.old/sshd-setup.yaml b/config/zinit.old/sshd-setup.yaml new file mode 100644 index 0000000..89ea84b --- /dev/null +++ b/config/zinit.old/sshd-setup.yaml @@ -0,0 +1,2 @@ +exec: sh /etc/zinit/init/sshd-setup.sh +oneshot: true diff --git a/config/zinit.old/sshd.yaml b/config/zinit.old/sshd.yaml new file mode 100644 index 0000000..309b92a --- /dev/null +++ b/config/zinit.old/sshd.yaml @@ -0,0 +1,3 @@ +exec: /usr/sbin/sshd -D -e +after: + - sshd-setup diff --git a/config/zinit.old/udev-trigger.yaml b/config/zinit.old/udev-trigger.yaml new file mode 100644 index 0000000..3c8c83a --- /dev/null +++ b/config/zinit.old/udev-trigger.yaml @@ -0,0 +1,6 @@ +exec: sh /etc/zinit/init/udev.sh +oneshot: true +after: + - depmod + - udevmon + - udevd \ No newline at end of file diff --git a/config/zinit.old/udevd.yaml b/config/zinit.old/udevd.yaml new file mode 100644 index 0000000..1da5469 --- /dev/null +++ b/config/zinit.old/udevd.yaml @@ -0,0 +1 @@ +exec: udevd \ No newline at end of file diff --git a/config/zinit.old/udevmon.yaml b/config/zinit.old/udevmon.yaml new file mode 100644 index 0000000..eb59948 --- /dev/null +++ b/config/zinit.old/udevmon.yaml @@ -0,0 +1 @@ +exec: udevadm monitor \ No newline at end of file diff --git a/config/zinit/zinit.conf b/config/zinit.old/zinit.conf similarity index 100% rename from config/zinit/zinit.conf rename to config/zinit.old/zinit.conf diff --git a/config/zinit/console.yaml b/config/zinit/console.yaml new file mode 100644 index 0000000..71cd1a3 --- /dev/null +++ b/config/zinit/console.yaml @@ -0,0 +1,2 @@ +exec: /sbin/getty -L 9600 console +restart: always \ No newline at end of file diff --git a/config/zinit/gettyconsole.yaml b/config/zinit/gettyconsole.yaml index e4074a8..2b921bc 100644 --- a/config/zinit/gettyconsole.yaml +++ b/config/zinit/gettyconsole.yaml @@ -1,2 +1,2 @@ -exec: /sbin/getty console linux +exec: /sbin/getty console restart: always \ No newline at end of file diff --git a/config/zinit/init/sshd-setup.sh b/config/zinit/init/sshd-setup.sh index 3909a79..f85ba6b 100755 --- a/config/zinit/init/sshd-setup.sh +++ b/config/zinit/init/sshd-setup.sh @@ -8,6 +8,7 @@ fi echo "Setting up sshd" mkdir -p /run/sshd +mkdir -p /var/empty ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa diff --git a/initramfs/etc/issue b/initramfs/etc/issue index 87ab9b4..6365385 100644 --- a/initramfs/etc/issue +++ b/initramfs/etc/issue @@ -1,3 +1,3 @@ -Welcome to Alpine Linux 3.22 -Kernel \r on \m (\l) +Zero-OS \r \m +Built on \l diff --git a/initramfs/etc/motd b/initramfs/etc/motd index 06dbae4..a2cf942 100644 --- a/initramfs/etc/motd +++ b/initramfs/etc/motd @@ -1,10 +1,8 @@ -Welcome to Alpine! -The Alpine Wiki contains a large amount of how-to guides and general -information about administrating Alpine systems. -See . +Welcome to Zero-OS! -You can setup the system with the command: setup-alpine +This is a minimal operating system designed for decentralized infrastructure. +Built on Alpine Linux with ThreeFold components. -You may change this message by editing /etc/motd. +For more information: https://github.com/threefoldtech/zos diff --git a/initramfs/etc/passwd b/initramfs/etc/passwd index 1130fa0..9bd427c 100644 --- a/initramfs/etc/passwd +++ b/initramfs/etc/passwd @@ -1,4 +1,4 @@ -root:x:0:0:root:/root:/bin/sh +root::0:0:root:/root:/bin/sh bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin diff --git a/scripts/lib/initramfs.sh b/scripts/lib/initramfs.sh index 16c3a68..6bfc199 100644 --- a/scripts/lib/initramfs.sh +++ b/scripts/lib/initramfs.sh @@ -327,24 +327,20 @@ function initramfs_resolve_module_dependencies() { # Set up container modules directory for proper modinfo -k usage local container_modules_path="/lib/modules/${kernel_version}" - local source_modules_path="${PROJECT_ROOT}/initramfs/lib/modules/${kernel_version}" log_debug "Using kernel version: ${kernel_version}" - log_debug "Source modules: ${source_modules_path}" log_debug "Container modules: ${container_modules_path}" - # Verify source modules exist - if [[ ! -d "$source_modules_path" ]]; then - log_warn "Built modules not found at: $source_modules_path" + # Check if modules are already installed in container (from kernel_modules stage) + if [[ ! -d "$container_modules_path" ]]; then + log_warn "Container modules not found at: $container_modules_path" + log_warn "This suggests kernel_modules stage didn't run or failed" log_warn "Falling back to simple module list" printf '%s\n' "${modules[@]}" return 0 fi - # Copy modules to container /lib/modules for proper modinfo -k usage - log_info "Setting up container modules for dependency resolution" - safe_mkdir "$container_modules_path" - safe_execute cp -r "${source_modules_path}"/* "$container_modules_path/" + log_info "Using existing container modules from kernel_modules stage" # Run depmod to build dependency database log_info "Running depmod -av for dependency resolution"