#!/bin/sh # /etc/runit/1 - rawnix system boot PATH=/sbin:/bin:/usr/sbin:/usr/bin export PATH msg() { printf '\033[1m%s\033[0m\n' "$1" } err() { printf '\033[1;31m%s\033[0m\n' "$1" >&2 } emergency_shell() { err "Dropping to emergency shell. Type 'exit' to reboot." sulogin -p printf '%s\n' "Rebooting..." umount -a -r mount -o remount,ro / reboot -f exit 0 } printf '%s\n' "rawnix is starting..." msg "Mounting /proc..." mountpoint -q /proc || mount -t proc proc /proc msg "Mounting /sys..." mountpoint -q /sys || mount -t sysfs sysfs /sys msg "Mounting /run..." mountpoint -q /run || mount -t tmpfs -o mode=0755,nosuid,nodev tmpfs /run msg "Mounting /dev..." if ! mountpoint -q /dev; then mount -t devtmpfs -o mode=0755,nosuid devtmpfs /dev else mount -o remount,mode=0755,nosuid devtmpfs /dev fi msg "Mounting /dev/pts..." mkdir -m 755 -p /dev/pts mountpoint -q /dev/pts || mount -t devpts -o gid=tty,mode=0620,noexec,nosuid devpts /dev/pts msg "Mounting /dev/shm..." mkdir -m 1777 -p /dev/shm mountpoint -q /dev/shm || mount -t tmpfs -o mode=1777,nosuid,nodev tmpfs /dev/shm msg "Mounting cgroups v2..." if ! mountpoint -q /sys/fs/cgroup; then mount -t cgroup2 none /sys/fs/cgroup 2>/dev/null || err "cgroup2 mount failed - containers will not work" fi # Bootstrap udevd for coldplug; sv/udevd takes over in stage 2 msg "Starting udevd..." if udevd --daemon 2>/dev/null; then msg "Triggering udev coldplug..." udevadm trigger --type=subsystems --action=add udevadm trigger --type=devices --action=add msg "Waiting for udev to settle..." udevadm settle --timeout=30 || err "Timeout waiting for udev events" else err "udevd not available - continuing without hotplug" fi msg "Bringing up loopback..." ip addr add 127.0.0.1/8 dev lo 2>/dev/null ip link set lo up 2>/dev/null # LUKS volumes. The root volume is not here -- the initramfs opened it # before this script existed. These are the extras: /home, data disks. # # The file is read on fd 3, not stdin. With `done < /etc/crypttab` the # passphrase prompt for a keyless entry reads the *next line of the # crypttab* instead of the console: the volume fails to open with no # indication why, and the line it ate is never processed. if command -v cryptsetup >/dev/null 2>&1 && [ -r /etc/crypttab ]; then msg "Opening LUKS volumes..." while read -r name device key opts <&3; do case "$name" in ''|\#*) continue ;; esac case ",$opts," in *,noauto,*) continue ;; esac [ -n "$device" ] || { err "crypttab: $name has no device"; continue; } [ -e "/dev/mapper/$name" ] && continue case "$device" in UUID=*|PARTUUID=*|LABEL=*) _d=$(blkid -t "$device" -o device 2>/dev/null | head -1) [ -n "$_d" ] || { err "crypttab: $name: no device for $device"; continue; } device=$_d ;; esac case "$key" in ''|none|-) cryptsetup open "$device" "$name" ;; *) cryptsetup open --key-file "$key" "$device" "$name" ;; esac || err "Failed to open LUKS volume: $name" done 3< /etc/crypttab fi msg "Remounting / read-only..." mount -o remount,ro / if [ -f /forcefsck ]; then msg "Forced filesystem check..." FORCEFSCK="-f" fi msg "Checking filesystems..." fsck $FORCEFSCK -A -T -C -a 2>/dev/null if [ $? -gt 1 ]; then err "Filesystem check failed!" err "Please repair manually. Root is mounted read-only." err "To remount read-write: mount -n -o remount,rw /" emergency_shell fi msg "Remounting / read-write..." mount -o remount,rw / msg "Seeding urandom..." if [ -f /var/lib/random/seed ]; then cat /var/lib/random/seed >/dev/urandom rm -f /var/lib/random/seed fi msg "Setting shared mount propagation..." mount --make-rshared / msg "Activating swap..." swapon -a 2>/dev/null msg "Mounting local filesystems..." mount -a -O no_netdev 2>/dev/null || emergency_shell mkdir -m 0755 -p /run/user mkdir -m 1777 -p /run/lock : >/run/utmp rm -rf /forcefsck /fastboot /etc/nologin /etc/shutdownpid 2>/dev/null rm -rf /tmp/* /tmp/.* 2>/dev/null if [ -x /etc/rc.modules ]; then msg "Loading kernel modules..." /etc/rc.modules fi if [ -f /etc/sysctl.conf ]; then msg "Setting kernel parameters..." sysctl -p >/dev/null 2>&1 fi if [ -f /etc/hostname ]; then msg "Setting hostname: $(cat /etc/hostname)" hostname "$(cat /etc/hostname)" fi hwclock --hctosys 2>/dev/null [ -x /etc/rc.local ] && /etc/rc.local touch /etc/runit/stopit chmod 100 /etc/runit/stopit touch /etc/runit/reboot chmod 100 /etc/runit/reboot dmesg > /var/log/boot.log 2>/dev/null msg "Boot complete." exit 0