Files
darkforge/toolchain/scripts/024-chroot-essentials.sh
2026-03-20 14:08:01 +01:00

96 lines
3.7 KiB
Bash
Executable File

#!/bin/bash
# ============================================================================
# DarkForge Linux — Phase 0, Chapter 7: Create Essential Files and Symlinks
# ============================================================================
# Purpose: Create the essential system files (/etc/passwd, /etc/group,
# log files) and symlinks that programs expect to exist.
# This script runs INSIDE the chroot environment.
# Inputs: None (creates files from scratch)
# Outputs: /etc/passwd, /etc/group, log files, essential symlinks
# Assumes: Running inside chroot (script 023 completed)
# Ref: LFS 13.0 §7.6
# ============================================================================
set -euo pipefail
echo "=== DarkForge: Creating essential files and symlinks ==="
# --- Create essential symlinks ------------------------------------------------
# Some programs hardcode paths to /bin/sh, /bin/cat, etc.
# With the unified /usr layout, these are already correct via symlinks
# created in 000-env-setup.sh, but verify:
[ -L /bin ] || { echo "ERROR: /bin should be a symlink to usr/bin"; exit 1; }
[ -L /lib ] || { echo "ERROR: /lib should be a symlink to usr/lib"; exit 1; }
[ -L /sbin ] || { echo "ERROR: /sbin should be a symlink to usr/sbin"; exit 1; }
# --- Create toolchain cross-prefix symlinks -----------------------------------
# GCC pass 2 was configured with --target=x86_64-darkforge-linux-gnu, so it
# looks for the linker (ld) and assembler (as) at:
# /usr/x86_64-darkforge-linux-gnu/bin/ld
# But binutils pass 2 installed them to /usr/bin/ld. We need symlinks.
echo ">>> Creating cross-prefix symlinks for gcc to find ld/as..."
mkdir -pv /usr/x86_64-darkforge-linux-gnu/bin
for tool in ld ld.bfd ar as nm objcopy objdump ranlib readelf strip; do
if [ -f "/usr/bin/${tool}" ]; then
ln -sfv "../../bin/${tool}" "/usr/x86_64-darkforge-linux-gnu/bin/${tool}"
fi
done
# --- Create /etc/passwd -------------------------------------------------------
cat > /etc/passwd << "EOF"
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/dev/null:/usr/bin/false
daemon:x:6:6:Daemon User:/dev/null:/usr/bin/false
messagebus:x:18:18:D-Bus Message Daemon User:/run/dbus:/usr/bin/false
uuidd:x:80:80:UUID Generation Daemon User:/dev/null:/usr/bin/false
nobody:x:65534:65534:Unprivileged User:/dev/null:/usr/bin/false
EOF
# --- Create /etc/group --------------------------------------------------------
cat > /etc/group << "EOF"
root:x:0:
bin:x:1:daemon
sys:x:2:
kmem:x:3:
tape:x:4:
tty:x:5:
daemon:x:6:
floppy:x:7:
disk:x:8:
lp:x:9:
dialout:x:10:
audio:x:11:
video:x:12:
utmp:x:13:
cdrom:x:15:
adm:x:16:
messagebus:x:18:
input:x:24:
mail:x:34:
kvm:x:61:
uuidd:x:80:
wheel:x:97:
users:x:999:
nogroup:x:65534:
EOF
# --- Create log files ---------------------------------------------------------
# These must exist for certain programs to function correctly
install -o root -g utmp -m 664 /dev/null /var/log/lastlog
install -o root -g root -m 600 /dev/null /var/log/btmp
install -o root -g root -m 664 /dev/null /var/log/faillog
install -o root -g utmp -m 664 /dev/null /var/log/wtmp
echo "=== Essential files and symlinks created ==="
echo ""
echo ">>> Checking gcc and ld are present..."
echo " gcc: $(ls /usr/bin/gcc 2>/dev/null && echo 'OK' || echo 'MISSING')"
echo " ld: $(ls /usr/bin/ld 2>/dev/null && echo 'OK' || echo 'MISSING')"
echo " ld-linux-x86-64.so.2: $(ls /lib64/ld-linux-x86-64.so.2 2>/dev/null && echo 'OK' || echo 'MISSING')"
echo " crt1.o: $(ls /usr/lib/crt1.o 2>/dev/null && echo 'OK' || echo 'MISSING')"
echo ""
echo " NOTE: gcc won't link until zlib is built (ld needs libz.so.1)."
echo " 024a-zlib.sh runs next to fix this."
echo ""
echo "Next: Build zlib, then the remaining chroot tools."