Initial commit: Alpine Zero-OS initramfs build system with cleaned Docker configuration
This commit is contained in:
172
scripts/setup-initramfs.sh
Executable file
172
scripts/setup-initramfs.sh
Executable file
@@ -0,0 +1,172 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
INITRAMFS_ROOT="/build/initramfs"
|
||||
CONFIG_DIR="/build/configs"
|
||||
OUTPUT_DIR="/build/output"
|
||||
|
||||
echo "[+] Setting up initramfs structure..."
|
||||
|
||||
# Copy init script
|
||||
echo " Installing init script..."
|
||||
cp "$CONFIG_DIR/init" "$INITRAMFS_ROOT/init"
|
||||
chmod +x "$INITRAMFS_ROOT/init"
|
||||
|
||||
# Copy zinit configuration (mounted from existing config)
|
||||
echo " Installing zinit configuration..."
|
||||
echo "[DEBUG] Checking zinit config sources..."
|
||||
echo "[DEBUG] /mnt/zinit exists: $([ -d "/mnt/zinit" ] && echo 'YES' || echo 'NO')"
|
||||
echo "[DEBUG] /mnt/zinit contents: $(ls -la /mnt/zinit 2>/dev/null | wc -l) files"
|
||||
echo "[DEBUG] $CONFIG_DIR/zinit exists: $([ -d "$CONFIG_DIR/zinit" ] && echo 'YES' || echo 'NO')"
|
||||
echo "[DEBUG] $CONFIG_DIR/zinit contents: $(ls -la $CONFIG_DIR/zinit 2>/dev/null | wc -l) files"
|
||||
|
||||
mkdir -p "$INITRAMFS_ROOT/etc/zinit"
|
||||
if [ -d "/mnt/zinit" ]; then
|
||||
cp -r "/mnt/zinit/"* "$INITRAMFS_ROOT/etc/zinit/"
|
||||
echo " Copied zinit configs from /mnt/zinit"
|
||||
echo "[DEBUG] Copied $(ls -la $INITRAMFS_ROOT/etc/zinit 2>/dev/null | wc -l) zinit config files"
|
||||
elif [ -d "$CONFIG_DIR/zinit" ]; then
|
||||
cp -r "$CONFIG_DIR/zinit/"* "$INITRAMFS_ROOT/etc/zinit/"
|
||||
echo " Copied zinit configs from $CONFIG_DIR/zinit"
|
||||
echo "[DEBUG] Copied $(ls -la $INITRAMFS_ROOT/etc/zinit 2>/dev/null | wc -l) zinit config files"
|
||||
else
|
||||
echo " Warning: zinit config directory not found"
|
||||
echo "[DEBUG] ERROR: No zinit config source available - this will likely cause runtime failures"
|
||||
fi
|
||||
|
||||
# Create debug script for compatibility
|
||||
echo " Creating debug script..."
|
||||
cat > "$INITRAMFS_ROOT/init-debug" << 'EOF'
|
||||
#!/bin/sh
|
||||
# Debug file injection script (Alpine version)
|
||||
echo "[+] debug mode enabled"
|
||||
|
||||
# Check for debug device (same as original)
|
||||
if [ -b /dev/sda1 ]; then
|
||||
echo " debug device found: /dev/sda1"
|
||||
|
||||
# Create temporary mount point
|
||||
mkdir -p /mnt/debug
|
||||
|
||||
# Try to mount as vfat (same as original)
|
||||
if mount -t vfat -o ro /dev/sda1 /mnt/debug 2>/dev/null; then
|
||||
echo " mounted debug device"
|
||||
|
||||
# Check for debug marker file
|
||||
if [ -f /mnt/debug/.zero-os-debug ]; then
|
||||
echo " debug marker found, copying files..."
|
||||
|
||||
# Copy all files from debug device to tmpfs root
|
||||
target="/mnt/root"
|
||||
if [ -d "$target" ]; then
|
||||
cp -rv /mnt/debug/* "$target/" 2>/dev/null || true
|
||||
echo " debug files copied to tmpfs"
|
||||
else
|
||||
echo " warning: tmpfs root not ready yet"
|
||||
fi
|
||||
else
|
||||
echo " no debug marker (.zero-os-debug) found"
|
||||
fi
|
||||
|
||||
# Unmount debug device
|
||||
umount /mnt/debug 2>/dev/null || true
|
||||
else
|
||||
echo " failed to mount debug device"
|
||||
fi
|
||||
|
||||
# Cleanup
|
||||
rmdir /mnt/debug 2>/dev/null || true
|
||||
else
|
||||
echo " no debug device found"
|
||||
fi
|
||||
|
||||
echo "[+] debug initialization complete"
|
||||
EOF
|
||||
|
||||
chmod +x "$INITRAMFS_ROOT/init-debug"
|
||||
|
||||
# Copy other system configurations
|
||||
echo " Setting up system configuration..."
|
||||
|
||||
# Ensure proper hostname
|
||||
echo "zero-os" > "$INITRAMFS_ROOT/etc/hostname"
|
||||
|
||||
# Basic hosts file
|
||||
cat > "$INITRAMFS_ROOT/etc/hosts" << EOF
|
||||
127.0.0.1 localhost zero-os
|
||||
::1 localhost zero-os
|
||||
EOF
|
||||
|
||||
# Minimal passwd file (compatible with existing)
|
||||
if [ ! -f "$INITRAMFS_ROOT/etc/passwd" ]; then
|
||||
cat > "$INITRAMFS_ROOT/etc/passwd" << EOF
|
||||
root:x:0:0:root:/root:/bin/sh
|
||||
EOF
|
||||
fi
|
||||
|
||||
# Minimal group file
|
||||
if [ ! -f "$INITRAMFS_ROOT/etc/group" ]; then
|
||||
cat > "$INITRAMFS_ROOT/etc/group" << EOF
|
||||
root:x:0:
|
||||
EOF
|
||||
fi
|
||||
|
||||
# Set up profile for environment
|
||||
cat > "$INITRAMFS_ROOT/etc/profile" << EOF
|
||||
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
|
||||
export HOME=/root
|
||||
export TERM=linux
|
||||
EOF
|
||||
|
||||
# Ensure SSH directory exists
|
||||
mkdir -p "$INITRAMFS_ROOT/etc/ssh"
|
||||
mkdir -p "$INITRAMFS_ROOT/root/.ssh"
|
||||
|
||||
# Set proper permissions
|
||||
chmod 700 "$INITRAMFS_ROOT/root"
|
||||
chmod 700 "$INITRAMFS_ROOT/root/.ssh" 2>/dev/null || true
|
||||
|
||||
# Create necessary run directories
|
||||
mkdir -p "$INITRAMFS_ROOT/run"
|
||||
mkdir -p "$INITRAMFS_ROOT/var"
|
||||
|
||||
# Ensure terminfo is available for better terminal support
|
||||
if [ -d "$INITRAMFS_ROOT/usr/share/terminfo" ]; then
|
||||
echo " terminfo available"
|
||||
else
|
||||
echo " warning: terminfo not found"
|
||||
fi
|
||||
|
||||
# Set up symlinks (similar to current system)
|
||||
echo " Setting up symlinks..."
|
||||
cd "$INITRAMFS_ROOT"
|
||||
|
||||
# Ensure lib symlinks
|
||||
ln -sf usr/lib lib || true
|
||||
ln -sf usr/lib lib64 || true
|
||||
|
||||
# Ensure var/run symlink (standard Linux practice: /var/run -> /run)
|
||||
cd "$INITRAMFS_ROOT/var"
|
||||
rm -rf run
|
||||
ln -sf ../run run || true
|
||||
cd "$INITRAMFS_ROOT"
|
||||
|
||||
# Create initramfs archive
|
||||
echo "[+] Creating initramfs archive..."
|
||||
cd "$INITRAMFS_ROOT"
|
||||
|
||||
# Create the cpio archive
|
||||
find . | cpio -H newc -o | xz --check=crc32 --x86 --lzma2=dict=1MiB > "$OUTPUT_DIR/initramfs.cpio.xz"
|
||||
|
||||
if [ -f "$OUTPUT_DIR/initramfs.cpio.xz" ]; then
|
||||
size=$(stat -c%s "$OUTPUT_DIR/initramfs.cpio.xz")
|
||||
echo "[+] Initramfs created: $OUTPUT_DIR/initramfs.cpio.xz ($size bytes)"
|
||||
else
|
||||
echo "[-] Error: Failed to create initramfs archive"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Also create uncompressed version for debugging
|
||||
find . | cpio -H newc -o > "$OUTPUT_DIR/initramfs.cpio"
|
||||
|
||||
echo "[+] Initramfs setup completed successfully"
|
||||
Reference in New Issue
Block a user