commit da5d6965b5a22245447a9716c45f7b51819df050 parent ffc9d939bfd955e56a408ce74a85c160ebcc0272 Author: torter <koubbamohamedrayan@gmail.com> Date: Sun, 22 Nov 2026 20:02:07 +0000 OpenRC instead of dinit, chamesle-install, chamesle-disk -t ext4|btrfs|zfs -y, chamesle-boot -b grub, btrfs; base r20 Diffstat:
87 files changed, 450 insertions(+), 522 deletions(-)
diff --git a/files/etc/dinit.d/NetworkManager b/files/etc/dinit.d/NetworkManager @@ -1,4 +0,0 @@ -type = process -command = /usr/sbin/NetworkManager -n -depends-on = dbus -smooth-recovery = true diff --git a/files/etc/dinit.d/acpid b/files/etc/dinit.d/acpid @@ -1,4 +0,0 @@ -type = process -command = /sbin/acpid -f -depends-on = system -smooth-recovery = true diff --git a/files/etc/dinit.d/avahi-daemon b/files/etc/dinit.d/avahi-daemon @@ -1,4 +0,0 @@ -type = process -command = /usr/sbin/avahi-daemon -s -depends-on = dbus -smooth-recovery = true diff --git a/files/etc/dinit.d/bluetoothd b/files/etc/dinit.d/bluetoothd @@ -1,4 +0,0 @@ -type = process -command = /usr/lib/bluetooth/bluetoothd -n -depends-on = dbus -smooth-recovery = true diff --git a/files/etc/dinit.d/boot b/files/etc/dinit.d/boot @@ -1,4 +0,0 @@ -# what dinit starts: the system, then every service enabled with dinitctl enable -type = internal -depends-on = system -waits-for.d = /etc/dinit.d/boot.d diff --git a/files/etc/dinit.d/chronyd b/files/etc/dinit.d/chronyd @@ -1,4 +0,0 @@ -type = process -command = /usr/sbin/chronyd -n -depends-on = system -smooth-recovery = true diff --git a/files/etc/dinit.d/connmand b/files/etc/dinit.d/connmand @@ -1,4 +0,0 @@ -type = process -command = /usr/sbin/connmand -n -depends-on = dbus -smooth-recovery = true diff --git a/files/etc/dinit.d/crond b/files/etc/dinit.d/crond @@ -1,4 +0,0 @@ -type = process -command = /usr/lib/chamesle/foreground crond -depends-on = system -smooth-recovery = true diff --git a/files/etc/dinit.d/cupsd b/files/etc/dinit.d/cupsd @@ -1,4 +0,0 @@ -type = process -command = /usr/sbin/cupsd -f -depends-on = system -smooth-recovery = true diff --git a/files/etc/dinit.d/dbus b/files/etc/dinit.d/dbus @@ -1,4 +0,0 @@ -type = process -command = /usr/lib/chamesle/dbus -depends-on = system -smooth-recovery = true diff --git a/files/etc/dinit.d/dhcpcd b/files/etc/dinit.d/dhcpcd @@ -1,4 +0,0 @@ -type = process -command = /usr/lib/chamesle/dhcpcd -depends-on = system -smooth-recovery = true diff --git a/files/etc/dinit.d/elogind b/files/etc/dinit.d/elogind @@ -1,4 +0,0 @@ -type = process -command = /usr/libexec/elogind/elogind -depends-on = dbus -smooth-recovery = true diff --git a/files/etc/dinit.d/gdm b/files/etc/dinit.d/gdm @@ -1,5 +0,0 @@ -type = process -command = /usr/sbin/gdm -depends-on = dbus -waits-for = elogind -restart = true diff --git a/files/etc/dinit.d/greetd b/files/etc/dinit.d/greetd @@ -1,6 +0,0 @@ -type = process -command = /usr/sbin/greetd -depends-on = system -waits-for = seatd -waits-for = elogind -restart = true diff --git a/files/etc/dinit.d/iwd b/files/etc/dinit.d/iwd @@ -1,4 +0,0 @@ -type = process -command = /usr/libexec/iwd -depends-on = dbus -smooth-recovery = true diff --git a/files/etc/dinit.d/klogd b/files/etc/dinit.d/klogd @@ -1,4 +0,0 @@ -type = process -command = /usr/lib/chamesle/foreground klogd -depends-on = rootfs -smooth-recovery = true diff --git a/files/etc/dinit.d/lightdm b/files/etc/dinit.d/lightdm @@ -1,5 +0,0 @@ -type = process -command = /usr/bin/lightdm -depends-on = dbus -waits-for = elogind -restart = true diff --git a/files/etc/dinit.d/ntpd b/files/etc/dinit.d/ntpd @@ -1,4 +0,0 @@ -type = process -command = /usr/lib/chamesle/foreground ntpd -depends-on = system -smooth-recovery = true diff --git a/files/etc/dinit.d/recovery b/files/etc/dinit.d/recovery @@ -1,5 +0,0 @@ -# what dinit runs when boot fails -type = process -command = /usr/lib/chamesle/rescue -options = runs-on-console -restart = false diff --git a/files/etc/dinit.d/rootfs b/files/etc/dinit.d/rootfs @@ -1,4 +0,0 @@ -type = scripted -command = /usr/lib/chamesle/rootfs -options = starts-on-console -restart = false diff --git a/files/etc/dinit.d/sddm b/files/etc/dinit.d/sddm @@ -1,5 +0,0 @@ -type = process -command = /usr/bin/sddm -depends-on = dbus -waits-for = elogind -restart = true diff --git a/files/etc/dinit.d/seatd b/files/etc/dinit.d/seatd @@ -1,4 +0,0 @@ -type = process -command = /usr/bin/seatd -g video -depends-on = system -smooth-recovery = true diff --git a/files/etc/dinit.d/setup b/files/etc/dinit.d/setup @@ -1,4 +0,0 @@ -type = scripted -command = /usr/lib/chamesle/setup -depends-on = rootfs -restart = false diff --git a/files/etc/dinit.d/single b/files/etc/dinit.d/single @@ -1,6 +0,0 @@ -# "single" on the kernel line: a root shell and nothing else -type = process -command = /usr/lib/chamesle/rescue -options = runs-on-console -restart = false -chain-to = boot diff --git a/files/etc/dinit.d/sshd b/files/etc/dinit.d/sshd @@ -1,4 +0,0 @@ -type = process -command = /bin/sh -c "ssh-keygen -A && exec /usr/sbin/sshd -D -e" -depends-on = system -smooth-recovery = true diff --git a/files/etc/dinit.d/syslogd b/files/etc/dinit.d/syslogd @@ -1,4 +0,0 @@ -type = process -command = /usr/lib/chamesle/foreground syslogd -depends-on = rootfs -smooth-recovery = true diff --git a/files/etc/dinit.d/system b/files/etc/dinit.d/system @@ -1,4 +0,0 @@ -# the file systems, devices and settings every other service needs -type = internal -depends-on = setup -waits-for = udev-trigger diff --git a/files/etc/dinit.d/tty1 b/files/etc/dinit.d/tty1 @@ -1,6 +0,0 @@ -type = process -command = /usr/lib/chamesle/getty tty1 -depends-on = system -restart = true -restart-delay = 2 -termsignal = HUP diff --git a/files/etc/dinit.d/tty2 b/files/etc/dinit.d/tty2 @@ -1,6 +0,0 @@ -type = process -command = /usr/lib/chamesle/getty tty2 -depends-on = system -restart = true -restart-delay = 2 -termsignal = HUP diff --git a/files/etc/dinit.d/tty3 b/files/etc/dinit.d/tty3 @@ -1,6 +0,0 @@ -type = process -command = /usr/lib/chamesle/getty tty3 -depends-on = system -restart = true -restart-delay = 2 -termsignal = HUP diff --git a/files/etc/dinit.d/tty4 b/files/etc/dinit.d/tty4 @@ -1,6 +0,0 @@ -type = process -command = /usr/lib/chamesle/getty tty4 -depends-on = system -restart = true -restart-delay = 2 -termsignal = HUP diff --git a/files/etc/dinit.d/tty5 b/files/etc/dinit.d/tty5 @@ -1,6 +0,0 @@ -type = process -command = /usr/lib/chamesle/getty tty5 -depends-on = system -restart = true -restart-delay = 2 -termsignal = HUP diff --git a/files/etc/dinit.d/tty6 b/files/etc/dinit.d/tty6 @@ -1,6 +0,0 @@ -type = process -command = /usr/lib/chamesle/getty tty6 -depends-on = system -restart = true -restart-delay = 2 -termsignal = HUP diff --git a/files/etc/dinit.d/ttyS0 b/files/etc/dinit.d/ttyS0 @@ -1,6 +0,0 @@ -type = process -command = /usr/lib/chamesle/getty ttyS0 -depends-on = system -restart = true -restart-delay = 2 -termsignal = HUP diff --git a/files/etc/dinit.d/udev-trigger b/files/etc/dinit.d/udev-trigger @@ -1,5 +0,0 @@ -type = scripted -command = /bin/sh -c "udevadm trigger --type=subsystems --action=add; udevadm trigger --type=devices --action=add; udevadm settle -t 5" -depends-on = udevd -depends-on = setup -restart = false diff --git a/files/etc/dinit.d/udevd b/files/etc/dinit.d/udevd @@ -1,4 +0,0 @@ -type = process -command = /sbin/udevd -depends-on = rootfs -smooth-recovery = true diff --git a/files/etc/dinit.d/wpa_supplicant b/files/etc/dinit.d/wpa_supplicant @@ -1,4 +0,0 @@ -type = process -command = /sbin/wpa_supplicant -u -s -depends-on = dbus -smooth-recovery = true diff --git a/files/etc/dinit.d/xdm b/files/etc/dinit.d/xdm @@ -1,4 +0,0 @@ -type = process -command = /usr/bin/xdm -nodaemon -depends-on = system -restart = true diff --git a/files/sbin/halt b/files/sbin/halt @@ -1,2 +0,0 @@ -#!/bin/sh -exec /usr/sbin/dinit-halt "$@" diff --git a/files/sbin/init b/files/sbin/init diff --git a/files/sbin/poweroff b/files/sbin/poweroff @@ -1,2 +0,0 @@ -#!/bin/sh -exec /usr/sbin/dinit-poweroff "$@" diff --git a/files/sbin/reboot b/files/sbin/reboot @@ -1,2 +0,0 @@ -#!/bin/sh -exec /usr/sbin/dinit-reboot "$@" diff --git a/files/sbin/service b/files/sbin/service @@ -1,8 +0,0 @@ -#!/bin/sh -# service NAME start|stop|restart|status|enable|disable, service -l: dinitctl, the old way round -case $1 in --l) exec dinitctl list;; --*|'') echo "usage: service -l | NAME start|stop|restart|status|enable|disable" >&2; exit 2;; -esac -[ $# = 2 ] || { echo "usage: service -l | NAME start|stop|restart|status|enable|disable" >&2; exit 2; } -exec dinitctl "$2" "$1" diff --git a/files/sbin/shutdown b/files/sbin/shutdown @@ -1,18 +0,0 @@ -#!/bin/sh -# shutdown -r|-h|-p [now|+minutes] [message] -usage() { echo "usage: shutdown -r|-h|-p [now|+minutes] [message]" >&2; exit 2; } -case $1 in --r) how=reboot;; --h) how=halt;; --p) how=poweroff;; -*) usage;; -esac -shift -when=${1:-now} -[ $# -gt 0 ] && shift -case $when in -now) ;; -+[0-9]*) [ $# -gt 0 ] && wall "$*"; sleep $((${when#+} * 60));; -*) usage;; -esac -exec /usr/sbin/dinit-$how diff --git a/files/usr/bin/arch-chroot b/files/usr/bin/arch-chroot @@ -220,7 +220,7 @@ offline_mode() { [[ $userspec ]] && chroot_args+=(--userspec "$userspec") - SHELL=/bin/bash SYSTEMD_IN_CHROOT=1 $pid_unshare chroot "${chroot_args[@]}" -- "$chrootdir" "${args[@]}" + SHELL=/bin/bash SYSTEMD_IN_CHROOT=1 $pid_unshare chroot "${chroot_args[@]}" "$chrootdir" "${args[@]}" } arch-chroot() { diff --git a/files/usr/lib/chamesle/dbus b/files/usr/lib/chamesle/dbus @@ -1,7 +0,0 @@ -#!/bin/sh -# the system bus, in the foreground for dinit -mkdir -p /var/lib/dbus /run/dbus -chown messagebus:messagebus /run/dbus -[ -s /var/lib/dbus/machine-id ] || /usr/bin/dbus-uuidgen --ensure=/var/lib/dbus/machine-id -rm -f /run/dbus/pid -exec /usr/bin/dbus-daemon --system --nofork --nopidfile diff --git a/files/usr/lib/chamesle/dhcpcd b/files/usr/lib/chamesle/dhcpcd @@ -1,3 +0,0 @@ -#!/bin/sh -mkdir -p /var/db/dhcpcd /run/dhcpcd -exec /sbin/dhcpcd -B diff --git a/files/usr/lib/chamesle/foreground b/files/usr/lib/chamesle/foreground @@ -1,12 +0,0 @@ -#!/bin/sh -# foreground NAME ARGS...: crond, ntpd, syslogd or klogd in the foreground, busybox's or the real one; they spell it differently -n=$1 -shift -p=$(command -v "$n") || exit 127 -case $n:$(readlink -f "$p") in -crond:*/busybox) exec "$p" -f "$@";; -crond:*) exec "$p" -n "$@";; -ntpd:*/busybox) exec "$p" -n "$@";; -ntpd:*) exec "$p" -d "$@";; -*) exec "$p" -n "$@";; -esac diff --git a/files/usr/lib/chamesle/getty b/files/usr/lib/chamesle/getty @@ -1,10 +0,0 @@ -#!/bin/sh -# getty TTY: a login on TTY. a serial port the machine does not have gets no getty, instead of one failing over and over -t=$1 -shift -case $t in -ttyS*) - grep -q "^${t#ttyS}: uart:unknown" /proc/tty/driver/serial 2>/dev/null && exec sleep 2147483647 - exec /sbin/agetty "$@" -L $t 115200 vt100;; -*) exec /sbin/agetty "$@" --noclear $t linux;; -esac diff --git a/files/usr/lib/chamesle/rescue b/files/usr/lib/chamesle/rescue @@ -1,5 +0,0 @@ -#!/bin/sh -# a root shell on the console, when the boot cannot go on -command -v sulogin >/dev/null && exec sulogin -echo "a root shell; exit to go on" -exec /bin/mksh -l diff --git a/files/usr/lib/chamesle/rootfs b/files/usr/lib/chamesle/rootfs @@ -1,27 +0,0 @@ -#!/bin/sh -# at boot, before any service: checks and mounts the file systems. a failed check gives a root shell -export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -mkdir -p /dev/pts /dev/shm -mountpoint -q /dev/pts || mount -t devpts devpts /dev/pts -mountpoint -q /dev/shm || mount -t tmpfs -o mode=1777,nosuid,nodev tmpfs /dev/shm -mountpoint -q /sys/fs/cgroup || mount -t cgroup2 -o nsdelegate cgroup2 /sys/fs/cgroup -if ! grep -q " / overlay " /proc/mounts; then - read -r cmdline < /proc/cmdline - case " $cmdline " in - *" fastboot "*) ;; - *) - fsck -A -R -p -T - case $? in 0|1) ;; *) echo "the file system check failed, fix it in this shell and exit to go on"; /usr/lib/chamesle/rescue;; esac - ;; - esac - mount -o remount,rw / || echo "/ stays read-only" -fi -mount -a -command -v zfs >/dev/null && zfs mount -a -swapon -a -mountpoint -q /tmp || rm -rf /tmp/* /tmp/.[!.]* -chmod 1777 /tmp -mkdir -p /var/log /var/db /var/lib /var/cache /var/tmp -chmod 1777 /var/tmp -[ -e /var/run ] || ln -s ../run /var/run -exit 0 diff --git a/files/usr/lib/chamesle/setup b/files/usr/lib/chamesle/setup @@ -1,12 +0,0 @@ -#!/bin/sh -# at boot, once the file systems are there: clock, host name, kernel settings and modules -export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin -ip link set lo up -hwclock --hctosys --utc 2>/dev/null -[ -s /etc/hostname ] && read -r host < /etc/hostname && echo "$host" > /proc/sys/kernel/hostname -for f in /etc/sysctl.d/*.conf /etc/sysctl.conf; do [ -f "$f" ] && sysctl -q -p "$f"; done -cat /usr/lib/modules-load.d/*.conf /etc/modules-load.d/*.conf /etc/modules 2>/dev/null | sed 's/#.*//' | while read -r m args; do - [ -n "$m" ] && modprobe "$m" $args 2>/dev/null -done -dmesg > /var/log/dmesg.boot -exit 0 diff --git a/files/usr/sbin/dinitctl b/files/usr/sbin/dinitctl @@ -1,15 +0,0 @@ -#!/bin/sh -# dinitctl for the system's dinit. someone who is not root goes through doas, and where dinit is not running (a chroot, -# a system being installed) enable and disable work on the files. -u or --user is left to a user's own dinit -for a; do case $a in -u|--user|-p|--socket-path) exec /usr/bin/dinitctl "$@";; esac; done -[ "$(id -u)" = 0 ] || exec doas /usr/bin/dinitctl "$@" -if [ ! -S /run/dinitctl ]; then - for a; do - case $a in - enable|disable) exec /usr/bin/dinitctl --offline "$@";; - -*) ;; - *) echo "dinitctl: dinit is not running here, only enable and disable work" >&2; exit 1;; - esac - done -fi -exec /usr/bin/dinitctl "$@" diff --git a/handbook/__pycache__/html.cpython-314.pyc b/handbook/__pycache__/html.cpython-314.pyc Binary files differ. diff --git a/handbook/handbook.md b/handbook/handbook.md @@ -2,7 +2,7 @@ 1. About Chamesle 2. Preparing -3. Installing by hand +3. Installing 4. mag 5. rifle 6. The base system @@ -16,9 +16,9 @@ ### 1.1 What it is -Chamesle is a small Linux distribution on musl that you put on a disk yourself, from the ISO. There is no installer and -nothing is compiled: `chamesle-bootstrap` puts the base into an empty root with the package manager, and you write the -fstab, the password and the boot entry by hand. This handbook goes through every step. +Chamesle is a small Linux distribution on musl, installed from the ISO. Nothing is compiled: `chamesle-bootstrap` puts +the base into an empty root with the package manager. `chamesle-install` does the whole install from a few questions, +or you do it by hand, writing the fstab, the password and the boot entry yourself. This handbook goes through every step. The parts: @@ -29,7 +29,7 @@ The parts: | mag | the package manager, binary packages only, in one C file | | rifle | the coreutils, all in one C file; `cat`, `ls`, `cp` and the rest are links to one program | | mksh | the login shell; `/bin/sh` is busybox's ash | -| init | dinit, with Chamesle's services in `/etc/dinit.d` | +| init | OpenRC, the services come with their packages | | limine | the boot loader, BIOS and UEFI | Chamesle is made to be the most UNIX distribution possible, and to run on almost anything: the same base goes on a new @@ -39,7 +39,7 @@ laptop and on a Pentium 4 with 256 MB of memory. It is a system for the tty firs mag reads two kinds of repository, both signed: -* Chamesle's own, at `https://chamesle.org/repo`: `chamesle-base` (the dinit services, the tools of this +* Chamesle's own, at `https://chamesle.org/repo`: `chamesle-base` (the files in `/etc`, the tools of this book and the keys), `mag` and `rifle` * a large musl repository with everything else: the kernel, the firmware, the libraries, editors, compilers, X, about 28,000 packages for x86_64 @@ -113,18 +113,29 @@ For wireless, `iwctl` (iwd runs at boot on the ISO): It asks for the passphrase. dhcpcd gives the interface an address once it is connected. -## 3. Installing by hand +## 3. Installing + +The live system has `chamesle-install`, which asks for the disk, the file system (ZFS, btrfs or ext4), the bootloader +(limine or GRUB), the firmware (what the machine has is ticked), wifi, the host name, the root password and a user, and +then does this chapter on the whole disk. The log is `/var/log/chamesle-install.log`, and a copy is kept on the new +system. The rest of the chapter is the same install by hand, for another layout or to know what it did. Follow the BIOS or the UEFI variant where they differ. The disk here is `/dev/sda`; change it to yours. Everything below is run as root on the live system, and it erases the disk. -There are two ways through 3.1 and 3.2: `chamesle-disk` does the partitioning and the file systems and leaves the -root on ZFS, or you do both yourself with the root on ext4. From 3.3 on the steps are the same, and they are yours: +There are two ways through 3.1 and 3.2: `chamesle-disk` does the partitioning and the file systems, or you do both +yourself. From 3.3 on the steps are the same, and they are yours: `chamesle-disk` is only a helper. ### 3.1 chamesle-disk chamesle-disk /dev/sda + chamesle-disk -t btrfs /dev/sda + chamesle-disk -t ext4 -y /dev/sda + +`-t` is the file system of the root: `zfs` (the default), `btrfs` or `ext4`. btrfs gets the subvolumes `@` for `/` +and `@home` for `/home`, mounted with `compress=zstd`. `-y` asks nothing and lays out the whole disk as in the table +below. It lists the disk and asks you to type its name before it touches anything. Then it starts `cfdisk` so you lay out the partitions. Three of them work for BIOS and UEFI both: @@ -197,7 +208,7 @@ Packages after the target go in too. A ThinkPad with Intel wireless and graphics chamesle-bootstrap -n t480 -f linux-firmware-intel /mnt vim -What `chamesle-base` brings: dinit and the files of chapter 6, mag, rifle, mksh, busybox for the tools rifle does not +What `chamesle-base` brings: OpenRC and the files of chapter 6, mag, rifle, mksh, busybox for the tools rifle does not have, bash, `agetty`, eudev, kmod, dhcpcd, e2fsprogs, curl and `arch-chroot`. ### 3.4 Working inside the new root @@ -239,11 +250,16 @@ The hash goes into `/etc/shadow`. The login shell of root is mksh. ### 3.7 The boot entry chamesle-boot /mnt + chamesle-boot -b grub /mnt + +`-b grub` installs GRUB instead of limine, for UEFI and for BIOS, and writes `/boot/grub/grub.cfg` the same way. It looks at what is mounted on `/mnt` and `/mnt/boot` and * installs `limine` into the new root, so its boot files and its `limine` are the same version -* for a root on ZFS, installs `zfs` and `zfs-lts` and adds `zfs` to the initramfs (7.5) +* for a root on ZFS, installs `zfs` and `zfs-lts`, adds `zfs` to the initramfs (7.5) and `zfs-import` and + `zfs-mount` to the sysinit runlevel; for btrfs, installs `btrfs-progs`, adds `btrfs` to the initramfs and puts the + subvolume on the kernel command line * writes `/mnt/boot/limine.conf` with an entry for every kernel in `/mnt/boot`, the root by UUID, or by dataset on ZFS * copies `BOOTX64.EFI` to `EFI/BOOT/` on the boot partition, for UEFI * runs `limine bios-install` on the disk, for BIOS; on a GPT disk only when it has a BIOS boot partition, else it says @@ -306,8 +322,8 @@ Do both and the disk boots either way. Leave out `zpool export` if the root is not on ZFS. -Take out the installation medium. limine shows the entry for three seconds and boots the kernel. dinit mounts the -file systems, starts the services of `/etc/dinit.d/boot.d` and puts a login on the ttys. Log in as root. `dhcpcd` brings up a +Take out the installation medium. limine shows the entry for three seconds and boots the kernel. OpenRC mounts the +file systems, starts the services of the runlevels and puts a login on the ttys. Log in as root. `dhcpcd` brings up a cable at boot; for wireless see section 6.8. ### 3.9 What to install next @@ -549,70 +565,47 @@ not. `./build.sh` has to have run first. A case that starts with `@ro` runs with ### 6.1 init -The init is dinit. `/sbin/init` is a short script: it mounts `proc`, `sysfs`, `devtmpfs` and `/run`, and hands over -to `dinit`, which stays process 1. dinit starts the service called `boot` and everything it needs, keeps the -services running, and stops them all in order when the machine goes down. The files are in `files/` in the sources and -`chamesle-bootstrap` copies them into the root. +The init is OpenRC. `/sbin/init` is busybox init, which reads `/etc/inittab`: it runs `openrc sysinit`, `openrc boot` +and `openrc default` in turn, then puts a login on `tty1` to `tty6`. OpenRC starts the services of each runlevel, each +after what it needs, and stops them in order when the machine goes down. -A boot goes: +A runlevel is a directory in `/etc/runlevels` with links to the services in `/etc/init.d`. A fresh install has: -1. `rootfs`: `fsck` checks the file systems (not with `fastboot` on the kernel command line), `/` is remounted - read-write, `devpts`, `/dev/shm` and the cgroup2 hierarchy are mounted, `mount -a` mounts `/etc/fstab`, `zfs mount -a` - mounts the ZFS datasets, `swapon -a`, and `/tmp` is emptied. A failed check gives a root shell; leave it to go on. -2. `udevd`, then `setup`: loopback up, the clock, the host name from `/etc/hostname`, `/etc/sysctl.d/*.conf`, the - modules (6.6), and `dmesg` into `/var/log/dmesg.boot`. -3. `udev-trigger` replays the devices and waits for them. -4. Every service in `/etc/dinit.d/boot.d`, all at once, each after what it depends on. +| runlevel | services | +|---|---| +| sysinit | `devfs`, `dmesg`, `udev`, `udev-trigger`, `udev-settle` | +| boot | `modules`, `hwclock`, `sysctl`, `hostname`, `bootmisc`, `syslog`, `seedrng`, `swap` | +| default | `udev-postmount`, `dhcpcd` | +| shutdown | `killprocs`, `mount-ro`, `savecache` | -`single` on the kernel command line starts a root shell and nothing else; the boot goes on when you leave it. If the -boot fails, dinit starts a root shell too. +`fsck`, `root` and `localmount` come in because the boot ones need them: the file systems are checked, `/` is remounted +read-write and `/etc/fstab` is mounted. On ZFS, `zfs-import` and `zfs-mount` are in sysinit too. ### 6.2 Services -A service is a file in `/etc/dinit.d` named after it. The base set has one for every common daemon, ready for when its -package is installed: `dbus`, `elogind`, `seatd`, `dhcpcd`, `iwd`, `wpa_supplicant`, `NetworkManager`, `connmand`, -`lightdm`, `sddm`, `gdm`, `xdm`, `greetd`, `sshd`, `chronyd`, `ntpd`, `crond`, `syslogd`, `klogd`, `acpid`, `cupsd`, -`bluetoothd`, `avahi-daemon`, and the logins `tty1` to `tty6` and `ttyS0`. `dinitctl` does the rest: - - dinitctl list every service that is loaded, and its state - dinitctl start iwd - dinitctl stop iwd - dinitctl restart dhcpcd - dinitctl status dbus - dinitctl enable NetworkManager start it now and at every boot - dinitctl disable dhcpcd not at boot any more - -`enable` and `disable` make and remove a link in `/etc/dinit.d/boot.d`; that directory is the list of what starts -at boot. A fresh install has `dhcpcd` and `tty1` to `tty6` in it. As a user in `wheel`, `dinitctl` asks for your -password through doas. Where dinit is not running, in `arch-chroot /mnt` for one, `enable` and `disable` still work. `service NAME start` and the rest still work and -run `dinitctl`. - -A service whose process dies is started again, unless it dies over and over in a few seconds; then dinit gives up and -`dinitctl list` shows it stopped. To add a service, write its file. A daemon that can stay in the foreground is a -`process`: - - # /etc/dinit.d/chronyd - type = process - command = /usr/sbin/chronyd -d - depends-on = system - smooth-recovery = true - -`depends-on = system` waits for the file systems and devices; `depends-on = dbus` for the system bus. `dinit-service(5)` -has every setting. - -Chamesle before base r18 ran Winchester, a shell init with `/etc/init.conf` and scripts in `/etc/rc.d`. The upgrade -to r18 moves you over by itself: the host name goes to `/etc/hostname`, the services of `boot-services` and the -`ttys` are enabled in dinit (`network` is `dhcpcd` now, `udev` and `modules` are part of the boot), and `init.conf` -is kept as `/etc/init.conf.old`. A changed `getty` line is not carried over; edit `/etc/dinit.d/ttyN` for that. +Every package with a daemon has its service next to it, in a package called after it with `-openrc` on the end. mag +installs that one by itself once OpenRC and the daemon are both there, so `mag install lightdm` brings `lightdm-openrc` +too. Then: -### 6.3 Shutting down + rc-update add lightdm start it at every boot + rc-update del dhcpcd not at boot any more + rc-service iwd start + rc-service iwd stop + rc-service dhcpcd restart + rc-status what runs, by runlevel + rc-update what starts at boot, and in which runlevel -`reboot`, `halt` and `poweroff` ask dinit to stop. It stops the services, the ones others depend on last, sends -`TERM` and then `KILL` to what is left, turns swap off, unmounts the file systems and powers off. `shutdown -r`, `-h` or -`-p` does the same, at once (`now`) or after `+minutes`, with an optional message sent through `wall`: +`rc-update add` puts a service in the default runlevel unless you name another. `service NAME start` works too. The +service files are in `/etc/init.d` and their settings in `/etc/conf.d/NAME`. `openrc-run(8)` has the rest. + +Chamesle before base r20 ran dinit, and before r18 Winchester. The upgrade to r20 moves you over by itself: what was +enabled there (`/etc/dinit.d/boot.d`, or `boot-services` of `/etc/init.conf`) is added to the default runlevel. dinit +is still process 1 until the next boot, so reboot that once with `dinit-reboot`. + +### 6.3 Shutting down - shutdown -r now - shutdown -p +10 back in ten minutes +`reboot`, `halt` and `poweroff` ask init to stop. `openrc shutdown` stops the services, the ones others need last, +sends `TERM` and then `KILL` to what is left, turns swap off and remounts the file systems read-only. ### 6.4 The files in /etc @@ -621,7 +614,7 @@ is kept as `/etc/init.conf.old`. A changed `getty` line is not carried over; edi | `passwd`, `shadow`, `group` | accounts, password hashes, groups | | `shells` | the login shells; `/bin/mksh` is one | | `hostname` | the host name | -| `dinit.d/` | the services, and in `boot.d` the ones started at boot (6.2) | +| `init.d/`, `runlevels/` | the services, and the ones started at boot (6.2) | | `modules` | kernel modules loaded at boot, one a line | | `fstab` | the file systems (3.5) | | `profile` | `PATH`, `PAGER`, `umask 022`, and `/etc/profile.d/*.sh` | @@ -668,7 +661,7 @@ A static address: ip route add default via 192.168.1.1 echo 'nameserver 192.168.1.1' > /etc/resolv.conf -and `dinitctl disable dhcpcd`. +and `rc-update del dhcpcd`. ### 6.8 Wireless @@ -676,9 +669,10 @@ The card needs its firmware (7.4). Then iwd: mag install iwd dbus -and enable it, which starts dbus with it: +and add it, which starts dbus with it: - dinitctl enable iwd + rc-update add iwd + rc-service iwd start `iwctl` connects, the same as on the ISO (2.3), and remembers the network. dhcpcd gives it an address. @@ -859,7 +853,7 @@ A changed file under `/etc` is never written over. When a package brings a new o | a BIOS machine does not boot | `limine bios-install /dev/sda` was not run, or `limine-bios.sys` is not in `/boot` | | a UEFI machine does not boot | `EFI/BOOT/BOOTX64.EFI` is not on the EFI partition, or the partition is not of type EFI System | | no wireless interface | the firmware is missing (7.4); `dmesg` names the file | -| no devices in `/dev` | udev did not start; `dinitctl status udevd` | +| no devices in `/dev` | udev did not start; `rc-service udev status` | ## 10. X and a window manager @@ -959,8 +953,8 @@ X writes `~/.local/share/xorg/Xorg.0.log`; `grep EE` in it shows the errors. | path | what | |------|------| -| `/sbin/init` | mounts what dinit needs and starts it | -| `/etc/dinit.d/`, `/etc/dinit.d/boot.d/` | the services, and the ones started at boot | +| `/sbin/init`, `/etc/inittab` | busybox init, which runs OpenRC | +| `/etc/init.d/`, `/etc/runlevels/` | the services, and the ones started at boot | | `/usr/lib/chamesle/` | the boot scripts the services run | | `/etc/hostname`, `/etc/modules` | host name, modules loaded at boot | | `/etc/profile` | `PATH`, `umask` | @@ -989,7 +983,7 @@ X writes `~/.local/share/xorg/Xorg.0.log`; `grep EE` in it shows the errors. | `system/tools/chamesle-boot` | limine.conf and limine for the system in a directory | | `system/tools/chamesle-disk` | cfdisk, vfat boot partition, ZFS root, mounted on `/mnt` | | `system/tools/mkapk`, `mkrepo`, `mkpkgs` | packages, signed indexes, Chamesle's own repo | -| `system/files/` | `/sbin/init`, the dinit services and boot scripts, `service`, in `chamesle-base` | +| `system/files/` | the files in `/etc` and the tools, in `chamesle-base` | | `system/pkg/chamesle-base/` | its scripts, `repos`, `os-release`, `issue` | | `system/keys/` | the public keys the repos are signed with | | `system/iso/mkiso`, `mkinitramfs`, `init` | the live ISO, its initramfs and the first process in it | diff --git a/handbook/html.py b/handbook/html.py @@ -50,7 +50,7 @@ def page(title, desc, url, body): <hr> <div id="foot"> Something wrong on this page? Tell us on the <a href="board.html">board</a>.<br> -Chamesle is installed by hand, from the <a href="docs.html">handbook</a>.<br> +Chamesle installs with <code>chamesle-install</code>, or by hand from the <a href="docs.html">handbook</a>.<br> <a href="https://ko-fi.com/L6N725GI1V">Ko-fi</a><br> <a href="#" id="edit-link">Edit text</a><br> $Date: {time.strftime('%Y-%m-%d')} $ @@ -148,7 +148,7 @@ for k, (title, body) in enumerate(chapters): toc.append('<ul>' + ''.join(f'<li><a href="{fname(k)}#{ident(s)}">{html.escape(s)}</a></li>' for s in subs) + '</ul>') toc.append('</li>') toc.append('</ol>') -open(os.path.join(out, 'docs.html'), 'w').write(page('Handbook', 'The Chamesle handbook, chapter by chapter: preparing, installing by hand, SPAS, rifle, the base system, the kernel, the live ISO and the files of the system.', 'docs.html', '\n'.join(toc))) +open(os.path.join(out, 'docs.html'), 'w').write(page('Handbook', 'The Chamesle handbook, chapter by chapter: preparing, installing, mag, rifle, the base system, the kernel, the live ISO and the files of the system.', 'docs.html', '\n'.join(toc))) for k, (title, body) in enumerate(chapters): name = re.sub(r'^\d+\. ', '', title) diff --git a/iso/profile/overlay/etc/dinit.d/boot.d/dbus b/iso/profile/overlay/etc/dinit.d/boot.d/dbus @@ -1 +0,0 @@ -../dbus -\ No newline at end of file diff --git a/iso/profile/overlay/etc/dinit.d/boot.d/dhcpcd b/iso/profile/overlay/etc/dinit.d/boot.d/dhcpcd @@ -1 +0,0 @@ -../dhcpcd -\ No newline at end of file diff --git a/iso/profile/overlay/etc/dinit.d/boot.d/iwd b/iso/profile/overlay/etc/dinit.d/boot.d/iwd @@ -1 +0,0 @@ -../iwd -\ No newline at end of file diff --git a/iso/profile/overlay/etc/dinit.d/boot.d/tty1 b/iso/profile/overlay/etc/dinit.d/boot.d/tty1 @@ -1 +0,0 @@ -../tty1 -\ No newline at end of file diff --git a/iso/profile/overlay/etc/dinit.d/boot.d/tty2 b/iso/profile/overlay/etc/dinit.d/boot.d/tty2 @@ -1 +0,0 @@ -../tty2 -\ No newline at end of file diff --git a/iso/profile/overlay/etc/dinit.d/boot.d/tty3 b/iso/profile/overlay/etc/dinit.d/boot.d/tty3 @@ -1 +0,0 @@ -../tty3 -\ No newline at end of file diff --git a/iso/profile/overlay/etc/dinit.d/boot.d/tty4 b/iso/profile/overlay/etc/dinit.d/boot.d/tty4 @@ -1 +0,0 @@ -../tty4 -\ No newline at end of file diff --git a/iso/profile/overlay/etc/dinit.d/boot.d/tty5 b/iso/profile/overlay/etc/dinit.d/boot.d/tty5 @@ -1 +0,0 @@ -../tty5 -\ No newline at end of file diff --git a/iso/profile/overlay/etc/dinit.d/boot.d/tty6 b/iso/profile/overlay/etc/dinit.d/boot.d/tty6 @@ -1 +0,0 @@ -../tty6 -\ No newline at end of file diff --git a/iso/profile/overlay/etc/dinit.d/boot.d/ttyS0 b/iso/profile/overlay/etc/dinit.d/boot.d/ttyS0 @@ -1 +0,0 @@ -../ttyS0 -\ No newline at end of file diff --git a/iso/profile/overlay/etc/dinit.d/tty1 b/iso/profile/overlay/etc/dinit.d/tty1 @@ -1,6 +0,0 @@ -type = process -command = /usr/lib/chamesle/getty tty1 --autologin root -depends-on = system -restart = true -restart-delay = 2 -termsignal = HUP diff --git a/iso/profile/overlay/etc/dinit.d/tty2 b/iso/profile/overlay/etc/dinit.d/tty2 @@ -1,6 +0,0 @@ -type = process -command = /usr/lib/chamesle/getty tty2 --autologin root -depends-on = system -restart = true -restart-delay = 2 -termsignal = HUP diff --git a/iso/profile/overlay/etc/dinit.d/tty3 b/iso/profile/overlay/etc/dinit.d/tty3 @@ -1,6 +0,0 @@ -type = process -command = /usr/lib/chamesle/getty tty3 --autologin root -depends-on = system -restart = true -restart-delay = 2 -termsignal = HUP diff --git a/iso/profile/overlay/etc/dinit.d/tty4 b/iso/profile/overlay/etc/dinit.d/tty4 @@ -1,6 +0,0 @@ -type = process -command = /usr/lib/chamesle/getty tty4 --autologin root -depends-on = system -restart = true -restart-delay = 2 -termsignal = HUP diff --git a/iso/profile/overlay/etc/dinit.d/tty5 b/iso/profile/overlay/etc/dinit.d/tty5 @@ -1,6 +0,0 @@ -type = process -command = /usr/lib/chamesle/getty tty5 --autologin root -depends-on = system -restart = true -restart-delay = 2 -termsignal = HUP diff --git a/iso/profile/overlay/etc/dinit.d/tty6 b/iso/profile/overlay/etc/dinit.d/tty6 @@ -1,6 +0,0 @@ -type = process -command = /usr/lib/chamesle/getty tty6 --autologin root -depends-on = system -restart = true -restart-delay = 2 -termsignal = HUP diff --git a/iso/profile/overlay/etc/dinit.d/ttyS0 b/iso/profile/overlay/etc/dinit.d/ttyS0 @@ -1,6 +0,0 @@ -type = process -command = /usr/lib/chamesle/getty ttyS0 --autologin root -depends-on = system -restart = true -restart-delay = 2 -termsignal = HUP diff --git a/iso/profile/overlay/etc/inittab b/iso/profile/overlay/etc/inittab @@ -0,0 +1,14 @@ +::sysinit:/sbin/openrc sysinit +::sysinit:/sbin/openrc boot +::wait:/sbin/openrc default + +tty1::respawn:/sbin/agetty --autologin root --noclear tty1 linux +tty2::respawn:/sbin/agetty --autologin root tty2 linux +tty3::respawn:/sbin/agetty --autologin root tty3 linux +tty4::respawn:/sbin/agetty --autologin root tty4 linux +tty5::respawn:/sbin/agetty --autologin root tty5 linux +tty6::respawn:/sbin/agetty --autologin root tty6 linux +ttyS0::respawn:/bin/sh -c 'grep -q "^0: uart:unknown" /proc/tty/driver/serial && exec sleep 2147483647; exec /sbin/agetty --autologin root -L 115200 ttyS0 vt100' + +::ctrlaltdel:/sbin/reboot +::shutdown:/sbin/openrc shutdown diff --git a/iso/profile/overlay/etc/motd b/iso/profile/overlay/etc/motd @@ -1,3 +1,5 @@ - Chamesle live system. The handbook is /usr/share/doc/chamesle/handbook.md, chapter 3 is the install. + + Chamesle live system. To install: chamesle-install + By hand: the handbook, /usr/share/doc/chamesle/handbook.md, chapter 3. Network: dhcpcd on a cable, iwctl for wireless. diff --git a/iso/profile/overlay/etc/runlevels/default/dbus b/iso/profile/overlay/etc/runlevels/default/dbus @@ -0,0 +1 @@ +/etc/init.d/dbus +\ No newline at end of file diff --git a/iso/profile/overlay/etc/runlevels/default/iwd b/iso/profile/overlay/etc/runlevels/default/iwd @@ -0,0 +1 @@ +/etc/init.d/iwd +\ No newline at end of file diff --git a/iso/profile/packages b/iso/profile/packages @@ -19,3 +19,8 @@ linux-firmware-intel curl vim less +dialog +btrfs-progs +iwd-openrc +dbus-openrc +wipefs diff --git a/pkg/chamesle-base/post-install b/pkg/chamesle-base/post-install @@ -5,5 +5,13 @@ Chamesle. The handbook is /usr/share/doc/chamesle/handbook.md, mag help says how M sed -i 's|^root:\([^:]*\):0:0:\([^:]*\):/root:/bin/sh$|root:\1:0:0:\2:/root:/bin/mksh|' /etc/passwd grep -qx /bin/mksh /etc/shells || echo /bin/mksh >> /etc/shells -mkdir -p /etc/dinit.d/boot.d +levels() { + add() { l=$1; shift; mkdir -p /etc/runlevels/$l; for s; do [ -e /etc/runlevels/$l/$s ] || [ -L /etc/runlevels/$l/$s ] || ln -s /etc/init.d/$s /etc/runlevels/$l/$s; done; } + add sysinit devfs dmesg udev udev-trigger udev-settle + add boot modules hwclock sysctl hostname bootmisc syslog seedrng swap + add shutdown killprocs mount-ro savecache + add default udev-postmount +} +levels +add default dhcpcd exit 0 diff --git a/pkg/chamesle-base/post-upgrade b/pkg/chamesle-base/post-upgrade @@ -0,0 +1,29 @@ +#!/bin/sh +# from dinit (or Winchester) to OpenRC, once: what was enabled there is enabled in the default runlevel +[ -e /etc/runlevels/boot/hostname ] && exit 0 +levels() { + add() { l=$1; shift; mkdir -p /etc/runlevels/$l; for s; do [ -e /etc/runlevels/$l/$s ] || [ -L /etc/runlevels/$l/$s ] || ln -s /etc/init.d/$s /etc/runlevels/$l/$s; done; } + add sysinit devfs dmesg udev udev-trigger udev-settle + add boot modules hwclock sysctl hostname bootmisc syslog seedrng swap + add shutdown killprocs mount-ro savecache + add default udev-postmount +} +levels +on=$(ls /etc/dinit.d/boot.d 2>/dev/null) +[ -f /etc/init.conf.old ] && on="$on $(sed -n 's/^\(boot-services\|ttys\) *= *//p' /etc/init.conf.old | tr -d '{}' | tr ',' ' ')" +for s in $on; do + case $s in + tty*|udev|modules|setup|rootfs) continue;; + network) s=dhcpcd;; + NetworkManager) s=networkmanager;; + bluetoothd) s=bluetooth;; + connmand) s=connman;; + syslogd) s=syslog;; + esac + add default $s +done +command -v zpool >/dev/null && add sysinit zfs-import zfs-mount +rm -rf /etc/dinit.d +echo "chamesle-base: the init is OpenRC now. enabled: $(ls /etc/runlevels/default | tr '\n' ' ')" +[ -d /run/dinit ] || [ -S /run/dinitctl ] && echo "chamesle-base: dinit is still running, so reboot this once with: dinit-reboot" +exit 0 diff --git a/pkg/chamesle-base/pre-upgrade b/pkg/chamesle-base/pre-upgrade @@ -1,13 +1,7 @@ #!/bin/sh -# from Winchester to dinit, once: the host name to /etc/hostname, the boot services and logins of init.conf enabled in dinit +# Winchester's init.conf: its host name to /etc/hostname, the rest is read by post-upgrade [ -f /etc/init.conf ] || exit 0 -mkdir -p /etc/dinit.d/boot.d -conf() { sed -n "s/^$1 *= *//p" /etc/init.conf | tr -d '{}' | tr ',' ' '; } -h=$(conf hostname) +h=$(sed -n 's/^hostname *= *//p' /etc/init.conf) [ -n "$h" ] && { [ ! -s /etc/hostname ] || [ "$(cat /etc/hostname)" = localhost ]; } && echo "$h" > /etc/hostname -for s in $(conf boot-services) $(conf ttys); do - case $s in udev|modules) continue;; network) s=dhcpcd;; esac - ln -sf ../$s /etc/dinit.d/boot.d/$s -done cp /etc/init.conf /etc/init.conf.old exit 0 diff --git a/pkg/chamesle-init/pre-install b/pkg/chamesle-init/pre-install @@ -0,0 +1,5 @@ +#!/bin/sh +# the base before r20 had its own /sbin/service, which OpenRC now brings: let go of it before openrc is installed +f=/var/lib/mag/chamesle-base/files +[ -f $f ] && grep -qx sbin/service $f && sed -i "/^sbin\/service$/d" $f && rm -f /sbin/service +exit 0 diff --git a/tools/chamesle-boot b/tools/chamesle-boot @@ -1,20 +1,30 @@ #!/bin/sh -# chamesle-boot [DIR]: makes the system in DIR (/mnt) bootable. writes /boot/limine.conf from what is mounted there, -# installs limine into it and puts limine on the disk for UEFI, and for BIOS when the disk has room for it. -# if /boot is not FAT, limine cannot read it, so it prints an entry for the GRUB of the other system instead. +# chamesle-boot [-b limine|grub] [DIR]: makes the system in DIR (/mnt) bootable. writes the boot entries from what is +# mounted there, installs the bootloader (limine unless -b grub) into it and puts it on the disk for UEFI, and for BIOS +# when the disk has room for it. if /boot is not FAT, it prints an entry for the GRUB of the other system instead. # chamesle-boot -# chamesle-boot /mnt +# chamesle-boot -b grub /mnt die() { echo "chamesle-boot: $*" >&2; exit 1; } -[ $# -le 1 ] || { echo "usage: chamesle-boot [DIR]" >&2; exit 2; } +usage() { echo "usage: chamesle-boot [-b limine|grub] [DIR]" >&2; exit 2; } +loader=limine +while getopts b: o; do + case $o in + b) loader=$OPTARG;; + *) usage;; + esac +done +shift $((OPTIND - 1)) +case $loader in limine|grub) ;; *) die "-b is limine or grub";; esac +[ $# -le 1 ] || usage [ "$(id -u)" = 0 ] || die "needs root" t=${1:-/mnt} t=${t%/} [ -x "$t/sbin/init" ] || die "$t has no system in it, run chamesle-bootstrap first" -mnt() { awk -v m="$1" '$2 == m { print $1, $3 }' /proc/mounts | tail -1; } +mnt() { awk -v m="$1" '$2 == m { print $1, $3, $4 }' /proc/mounts | tail -1; } set -- $(mnt "$t") -[ $# = 2 ] || die "nothing is mounted on $t" -rootdev=$1 rootfs=$2 +[ $# = 3 ] || die "nothing is mounted on $t" +rootdev=$1 rootfs=$2 rootopts=$3 set -- $(mnt "$t/boot") bootdev=$1 bootfs=$2 @@ -22,18 +32,30 @@ kernels= for k in "$t"/boot/vmlinuz-*; do [ -e "$k" ] && kernels="$kernels ${k##*/vmlinuz-}"; done [ -n "$kernels" ] || die "no kernel in $t/boot, install linux-lts first" +# feature NAME PACKAGE...: puts NAME in the initramfs, with the packages it needs +feature() { + conf=$t/etc/mkinitfs/mkinitfs.conf + grep -qE "^features=\"([^\"]* )?$1( |\")" "$conf" && return + echo "adding $1 to the initramfs" + f=$1 + shift + arch-chroot "$t" mag install "$@" || die "mag install $* failed" + sed -i "/^features=/s/\"\$/ $f\"/" "$conf" + for m in "$t"/lib/modules/*; do arch-chroot "$t" mkinitfs "${m##*/}" || die "mkinitfs failed"; done +} + if [ "$rootfs" = zfs ]; then cmdline="root=ZFS=$rootdev rootfstype=zfs" - conf=$t/etc/mkinitfs/mkinitfs.conf - if ! grep -q '^features=.*zfs' "$conf"; then - echo "adding zfs to the initramfs" - arch-chroot "$t" mag install zfs $(for k in $kernels; do echo zfs-$k; done) || die "mag install zfs failed" - sed -i '/^features=/s/"$/ zfs"/' "$conf" - for m in "$t"/lib/modules/*; do arch-chroot "$t" mkinitfs "${m##*/}" || die "mkinitfs failed"; done - fi + feature zfs zfs zfs-openrc $(for k in $kernels; do echo zfs-$k; done) + for s in zfs-import zfs-mount; do [ -e "$t/etc/runlevels/sysinit/$s" ] || ln -s /etc/init.d/$s "$t/etc/runlevels/sysinit/$s"; done else uuid=$(blkid -s UUID -o value "$rootdev") || die "no UUID for $rootdev" cmdline="root=UUID=$uuid modules=sd-mod,usb-storage,nvme,$rootfs rootfstype=$rootfs" + if [ "$rootfs" = btrfs ]; then + sub=$(echo "$rootopts" | tr , '\n' | sed -n 's|^subvol=/*||p') + [ -n "$sub" ] && cmdline="$cmdline rootflags=subvol=$sub" + feature btrfs btrfs-progs + fi fi if [ "$bootfs" != vfat ]; then @@ -55,6 +77,34 @@ G exit 0 fi +disk=/dev/$(lsblk -no PKNAME "$bootdev" | head -1) +bios=1 +if [ "$(lsblk -dno PTTYPE "$disk")" = gpt ] && ! lsblk -no PARTTYPE "$disk" | grep -qi 21686148-6449-6e6f-744e-656564454649; then bios=; fi + +if [ $loader = grub ]; then + case $(cat "$t/etc/mag/arch" 2>/dev/null) in x86) efi=i386-efi;; *) efi=x86_64-efi;; esac + arch-chroot "$t" mag install grub grub-efi ${bios:+grub-bios} >/dev/null || die "mag install grub failed" + arch-chroot "$t" grub-install --target=$efi --efi-directory=/boot --boot-directory=/boot --removable --no-nvram >/dev/null || die "grub-install for UEFI failed" + echo "UEFI: GRUB in EFI/BOOT on $bootdev" + if [ -n "$bios" ]; then + arch-chroot "$t" grub-install --target=i386-pc --boot-directory=/boot "$disk" >/dev/null || die "grub-install for BIOS failed" + echo "BIOS: GRUB is on $disk" + else + echo "BIOS: $disk is GPT with no BIOS boot partition, so it boots by UEFI only" + fi + c=$t/boot/grub/grub.cfg + [ -e "$c" ] && mv "$c" "$c.old" && echo "the old grub.cfg is grub.cfg.old" + { + echo "set timeout=3" + for k in $kernels; do + printf "\nmenuentry 'Chamesle (%s)' {\n\tsearch --no-floppy --fs-uuid --set=root %s\n" "$k" "$(blkid -s UUID -o value "$bootdev")" + printf '\tlinux /vmlinuz-%s %s quiet\n\tinitrd /initramfs-%s\n}\n' "$k" "$cmdline" "$k" + done + } > "$c" + cat "$c" + exit 0 +fi + [ -e "$t/usr/share/limine/limine-bios.sys" ] || arch-chroot "$t" mag install limine || die "mag install limine failed" c=$t/boot/limine.conf @@ -74,8 +124,7 @@ for e in BOOTX64.EFI BOOTIA32.EFI; do [ -e "$t/usr/share/limine/$e" ] && cp "$t/ echo "UEFI: EFI/BOOT on $bootdev" cp "$t/usr/share/limine/limine-bios.sys" "$t/boot/" -disk=/dev/$(lsblk -no PKNAME "$bootdev" | head -1) -if [ "$(lsblk -dno PTTYPE "$disk")" = gpt ] && ! lsblk -no PARTTYPE "$disk" | grep -qi 21686148-6449-6e6f-744e-656564454649; then +if [ -z "$bios" ]; then echo "BIOS: $disk is GPT with no BIOS boot partition, so it boots by UEFI only" else arch-chroot "$t" limine bios-install "$disk" >/dev/null || die "limine bios-install $disk failed" diff --git a/tools/chamesle-bootstrap b/tools/chamesle-bootstrap @@ -40,7 +40,6 @@ mag update case $firmware in linux-firmware|linux-firmware-none) ;; *) firmware="linux-firmware-none $firmware";; esac mag install chamesle-base $firmware $kernel "$@" echo "$name" > "$target/etc/hostname" -mkdir -p "$target/etc/dinit.d/boot.d" -for s in tty1 tty2 tty3 tty4 tty5 tty6 dhcpcd; do ln -sf ../$s "$target/etc/dinit.d/boot.d/$s"; done +[ -e "$target/etc/resolv.conf" ] || cp /etc/resolv.conf "$target/etc/" 2>/dev/null || : echo echo "the base is in $target. go on with the fstab, a password and the boot entry (handbook, 3.4)." diff --git a/tools/chamesle-disk b/tools/chamesle-disk @@ -1,69 +1,129 @@ #!/bin/sh -# chamesle-disk DISK: erases a disk and sets it up for Chamesle: you lay out the partitions in cfdisk, then the boot partition becomes -# vfat and the root partition a ZFS pool, both mounted under /mnt with a fstab written. the install itself stays by hand, see the handbook. +# chamesle-disk [-t ext4|btrfs|zfs] [-y] DISK: erases a disk and sets it up for Chamesle. the boot partition becomes vfat, +# the root partition ext4, btrfs (subvolumes @ and @home) or a ZFS pool (the default), all mounted under /mnt with a +# fstab written. you lay out the partitions in cfdisk; -y skips the questions and takes the whole disk: +# a BIOS boot partition, 512M for /boot and the rest for the root. # chamesle-disk /dev/nvme0n1 +# chamesle-disk -t btrfs -y /dev/sda die() { echo "chamesle-disk: $*" >&2; exit 1; } -[ $# = 1 ] || { echo "usage: chamesle-disk DISK" >&2; exit 2; } +usage() { echo "usage: chamesle-disk [-t ext4|btrfs|zfs] [-y] DISK" >&2; exit 2; } +fs=zfs yes= +while getopts t:y o; do + case $o in + t) fs=$OPTARG;; + y) yes=1;; + *) usage;; + esac +done +shift $((OPTIND - 1)) +[ $# = 1 ] || usage +case $fs in ext4|btrfs|zfs) ;; *) die "-t is ext4, btrfs or zfs";; esac [ "$(id -u)" = 0 ] || die "needs root" disk=$1 [ -b "$disk" ] || die "$disk is not a block device" -for t in cfdisk mkfs.fat zpool zfs blkid lsblk; do command -v $t >/dev/null || die "$t is not installed"; done +need="mkfs.fat blkid lsblk wipefs" +[ -n "$yes" ] && need="$need sfdisk" || need="$need cfdisk" +case $fs in +ext4) need="$need mkfs.ext4";; +btrfs) need="$need mkfs.btrfs btrfs";; +zfs) need="$need zpool zfs";; +esac +for t in $need; do command -v $t >/dev/null || die "$t is not installed"; done mountpoint -q /mnt && die "/mnt is in use, unmount it first" -zpool list rpool >/dev/null 2>&1 && die "a pool called rpool is already imported (zpool export -f rpool to let go of it)" +[ $fs = zfs ] && zpool list rpool >/dev/null 2>&1 && die "a pool called rpool is already imported (zpool export -f rpool to let go of it)" -lsblk "$disk" -echo "Everything on $disk will be erased." -printf 'Type the name of the disk (%s) to go on: ' "${disk##*/}" -read -r answer -[ "$answer" = "${disk##*/}" ] || [ "$answer" = "$disk" ] || die "not confirmed, nothing was changed" +# part N: the Nth partition of the disk, nvme0n1p2 as well as sda2 +part() { case $disk in *[0-9]) echo "${disk}p$1";; *) echo "$disk$1";; esac; } -cfdisk "$disk" || die "cfdisk failed" -sleep 1 -echo -lsblk "$disk" - -# part WHAT: asks for a partition of the disk, takes sda1 as well as /dev/sda1 -part() { - printf '%s: ' "$1" >&2 - read -r p - case $p in /dev/*) ;; *) p=/dev/$p;; esac - [ -b "$p" ] || die "$p is not a block device" - case $p in "$disk"?*) ;; *) die "$p is not a partition of $disk";; esac - echo "$p" -} -boot=$(part "Which partition is the boot partition (vfat, the EFI system partition)") || exit 1 -root=$(part "Which partition is the root (ZFS)") || exit 1 -[ "$boot" != "$root" ] || die "boot and root cannot be the same partition" +if [ -n "$yes" ]; then + wipefs -aq "$disk" + sfdisk -q "$disk" <<P || die "sfdisk failed" +label: gpt +size=1M, type=21686148-6449-6E6F-744E-656564454649 +size=512M, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B +type=0FC63DAF-8483-4772-8E79-3D69D8477DE4 +P + command -v udevadm >/dev/null && udevadm settle + sleep 1 + boot=$(part 2) root=$(part 3) + [ -b "$boot" ] && [ -b "$root" ] || die "the new partitions $boot and $root are not there" +else + lsblk "$disk" + echo "Everything on $disk will be erased." + printf 'Type the name of the disk (%s) to go on: ' "${disk##*/}" + read -r answer + [ "$answer" = "${disk##*/}" ] || [ "$answer" = "$disk" ] || die "not confirmed, nothing was changed" + cfdisk "$disk" || die "cfdisk failed" + sleep 1 + echo + lsblk "$disk" + ask() { + printf '%s: ' "$1" >&2 + read -r p + case $p in /dev/*) ;; *) p=/dev/$p;; esac + [ -b "$p" ] || die "$p is not a block device" + case $p in "$disk"?*) ;; *) die "$p is not a partition of $disk";; esac + echo "$p" + } + boot=$(ask "Which partition is the boot partition (vfat, the EFI system partition)") || exit 1 + root=$(ask "Which partition is the root ($fs)") || exit 1 + [ "$boot" != "$root" ] || die "boot and root cannot be the same partition" +fi -[ -e /dev/zfs ] || modprobe zfs || die "the zfs module is not there" -modprobe vfat; modprobe nls_utf8 -mkfs.fat -F32 "$boot" || die "mkfs.fat failed" -undo() { umount /mnt/boot 2>/dev/null; zpool export -f rpool 2>/dev/null; die "$1, rpool was exported again, run chamesle-disk again"; } -zpool create -f -o ashift=12 -O compression=zstd -O acltype=posixacl -O xattr=sa -O mountpoint=none -R /mnt rpool "$root" || die "zpool create failed" -zfs create -o mountpoint=/ -o canmount=noauto rpool/root || undo "zfs create failed" -zfs mount rpool/root || undo "cannot mount rpool/root" -zfs create -o mountpoint=/home rpool/home -zfs create -o mountpoint=/var rpool/var -zpool set bootfs=rpool/root rpool +wipefs -aq "$boot" "$root" +modprobe vfat 2>/dev/null; modprobe nls_utf8 2>/dev/null +mkfs.fat -F32 "$boot" >/dev/null || die "mkfs.fat failed" +case $fs in +zfs) + [ -e /dev/zfs ] || modprobe zfs || die "the zfs module is not there" + undo() { umount /mnt/boot 2>/dev/null; zpool export -f rpool 2>/dev/null; die "$1, rpool was exported again, run chamesle-disk again"; } + zpool create -f -o ashift=12 -O compression=zstd -O acltype=posixacl -O xattr=sa -O mountpoint=none -R /mnt rpool "$root" || die "zpool create failed" + zfs create -o mountpoint=/ -o canmount=noauto rpool/root || undo "zfs create failed" + zfs mount rpool/root || undo "cannot mount rpool/root" + zfs create -o mountpoint=/home rpool/home + zfs create -o mountpoint=/var rpool/var + zpool set bootfs=rpool/root rpool + ;; +ext4) + undo() { umount -R /mnt 2>/dev/null; die "$1"; } + mkfs.ext4 -F -q "$root" || die "mkfs.ext4 failed" + mount -t ext4 "$root" /mnt || die "cannot mount $root" + ;; +btrfs) + undo() { umount -R /mnt 2>/dev/null; die "$1"; } + modprobe btrfs 2>/dev/null + mkfs.btrfs -f -q "$root" >/dev/null || die "mkfs.btrfs failed" + mount -t btrfs "$root" /mnt || die "cannot mount $root" + btrfs -q subvolume create /mnt/@ && btrfs -q subvolume create /mnt/@home || undo "cannot make the subvolumes" + umount /mnt + mount -t btrfs -o subvol=@,compress=zstd,noatime "$root" /mnt || die "cannot mount $root" + mkdir -p /mnt/home + mount -t btrfs -o subvol=@home,compress=zstd,noatime "$root" /mnt/home || undo "cannot mount @home" + ;; +esac mkdir -p /mnt/boot /mnt/etc mount -t vfat "$boot" /mnt/boot || undo "cannot mount $boot" if [ -e /mnt/etc/fstab ]; then echo "/mnt/etc/fstab is there already, left alone" else - cat > /mnt/etc/fstab <<F -# the zfs datasets mount themselves, so they are not listed here -# device mount type options dump pass -UUID=$(blkid -s UUID -o value "$boot") /boot vfat rw,noatime 0 2 -proc /proc proc defaults 0 0 -sysfs /sys sysfs defaults 0 0 -tmpfs /tmp tmpfs mode=1777,nosuid,nodev 0 0 -F + r=$(blkid -s UUID -o value "$root") + { + echo "# device mount type options dump pass" + case $fs in + zfs) echo "# the zfs datasets mount themselves, so they are not listed here";; + ext4) echo "UUID=$r / ext4 rw,noatime 0 1";; + btrfs) + echo "UUID=$r / btrfs rw,noatime,compress=zstd,subvol=@ 0 0" + echo "UUID=$r /home btrfs rw,noatime,compress=zstd,subvol=@home 0 0";; + esac + echo "UUID=$(blkid -s UUID -o value "$boot") /boot vfat rw,noatime 0 2" + echo "proc /proc proc defaults 0 0" + echo "sysfs /sys sysfs defaults 0 0" + echo "tmpfs /tmp tmpfs mode=1777,nosuid,nodev 0 0" + } > /mnt/etc/fstab fi -cat <<N - -$boot is vfat and mounted on /mnt/boot, the pool rpool is on $root and mounted on /mnt. -Now install the system into /mnt, then limine.conf, the host name and a password: chapter 3 of the handbook, -section 3.3 onwards (cat /usr/share/doc/chamesle/handbook.md). -N +echo +echo "$boot is vfat on /mnt/boot, $root is $fs on /mnt." +[ -n "$yes" ] || echo "Now install the system into /mnt: chapter 3 of the handbook, section 3.3 onwards." diff --git a/tools/chamesle-install b/tools/chamesle-install @@ -0,0 +1,122 @@ +#!/bin/sh +# chamesle-install: the install of chapter 3 of the handbook, asked for in dialog boxes. it takes a whole disk and runs +# chamesle-disk, chamesle-bootstrap and chamesle-boot with what you chose. +die() { clear; echo "chamesle-install: $*" >&2; exit 1; } +[ "$(id -u)" = 0 ] || die "needs root" +command -v dialog >/dev/null || die "dialog is not installed: mag install dialog" +T="Chamesle" +d() { dialog --stdout --backtitle "$T installer" "$@"; } +msg() { d --msgbox "$1" 0 0; } +log=/var/log/chamesle-install.log + +online() { curl -fsS -m 8 -o /dev/null https://chamesle.org/repo/x86_64/APKINDEX.tar.gz; } +while ! online; do + c=$(d --menu "There is no network. A cable just works; for wifi, connect with iwctl:\n station wlan0 scan\n station wlan0 get-networks\n station wlan0 connect NAME" 0 0 0 \ + wifi "connect in iwctl, then come back" retry "try again" quit "leave the installer") || die "left" + case $c in + wifi) clear; iwctl;; + quit) die "left";; + esac +done + +disks= +for b in /sys/block/*; do + n=${b##*/} + case $n in loop*|ram*|sr*|zram*|fd*|md*|dm-*) continue;; esac + grep -q "^/dev/$n" /proc/mounts && continue + [ "$(cat "$b/size")" -gt 0 ] || continue + disks="$disks /dev/$n '$(lsblk -dno SIZE,MODEL "/dev/$n" | tr -cd 'A-Za-z0-9 ._-' | tr -s ' ')'" +done +[ -n "$disks" ] || die "there is no disk to install on" +disk=$(eval d --menu "'Which disk? Everything on it will be erased.'" 0 0 0 "$disks") || die "left" + +fs=$(d --default-item zfs --menu "The file system of the root" 0 0 0 \ + zfs "ZFS: compression, snapshots, checksums (the handbook's default)" \ + btrfs "btrfs: compression, snapshots, subvolumes @ and @home" \ + ext4 "ext4: plain and simple") || die "left" + +loader=$(d --menu "The bootloader" 0 0 0 \ + limine "limine: small, UEFI and BIOS" \ + grub "GRUB: UEFI and BIOS") || die "left" + +# the firmware the hardware here wants, ticked already +has() { for v in /sys/bus/pci/devices/*; do [ "$(cat $v/vendor)" = "$1" ] && case $(cat $v/class) in $2*) return 0;; esac; done; return 1; } +on() { has "$@" && echo on || echo off; } +fw=$(d --separate-output --checklist "Firmware for the hardware (ticked: what this machine has)" 0 0 0 \ + linux-firmware-intel "Intel wifi and bluetooth" $(on 0x8086 0x0280) \ + linux-firmware-i915 "Intel graphics" $(on 0x8086 0x03) \ + linux-firmware-amdgpu "AMD graphics" $(on 0x1002 0x03) \ + linux-firmware-rtw88 "Realtek wifi (older)" $(on 0x10ec 0x0280) \ + linux-firmware-rtw89 "Realtek wifi (newer)" off \ + linux-firmware-mediatek "MediaTek wifi" $(on 0x14c3 0x0280) \ + linux-firmware-nvidia "NVIDIA graphics (nouveau)" $(on 0x10de 0x03) \ + linux-firmware-rtl_nic "Realtek ethernet" $(on 0x10ec 0x0200)) || die "left" + +wifi=$(d --menu "Wifi on the installed system" 0 0 0 \ + iwd "iwd, connect with iwctl" \ + networkmanager "NetworkManager, connect with nmtui" \ + none "cable only") || die "left" + +host=$(d --inputbox "The host name" 0 0 chamesle) || die "left" +host=$(echo "$host" | tr -cd 'a-zA-Z0-9-') +[ -n "$host" ] || host=chamesle + +pw() { + while :; do + a=$(d --insecure --passwordbox "$1" 0 0) || die "left" + b=$(d --insecure --passwordbox "$1, again" 0 0) || die "left" + [ -n "$a" ] && [ "$a" = "$b" ] && { echo "$a"; return; } + msg "They are not the same, or empty. Again." + done +} +rootpw=$(pw "The root password") +user=$(d --inputbox "Your user name (empty for none)" 0 0) || die "left" +user=$(echo "$user" | tr -cd 'a-z0-9_-') +[ -n "$user" ] && userpw=$(pw "The password of $user") + +d --yesno "Install now?\n\n disk $disk (ERASED)\n file system $fs\n bootloader $loader\n firmware $(echo $fw)\n network $wifi\n host name $host\n user ${user:-none}" 0 0 || die "nothing was changed" + +pkgs= +case $wifi in +iwd) pkgs=iwd;; +networkmanager) pkgs="networkmanager networkmanager-wifi networkmanager-tui";; +esac +first=$(echo $fw | cut -d' ' -f1) +rest=$(echo $fw | cut -s -d' ' -f2-) + +step() { echo "==> $1" >> $log; d --infobox "$1" 3 60; } +: > $log +( + step "Making the file systems on $disk" + chamesle-disk -t $fs -y "$disk" >> $log 2>&1 || exit 1 + step "Installing the base (a few minutes)" + n=0 + until chamesle-bootstrap -n "$host" ${first:+-f $first} /mnt $rest $pkgs >> $log 2>&1; do + n=$((n + 1)) + [ $n -lt 3 ] || exit 1 + sleep 5 + done + step "Passwords and the user" + echo "root:$rootpw" | arch-chroot /mnt chpasswd >> $log 2>&1 || exit 1 + if [ -n "$user" ]; then + arch-chroot /mnt adduser -D "$user" >> $log 2>&1 || exit 1 + echo "$user:$userpw" | arch-chroot /mnt chpasswd >> $log 2>&1 || exit 1 + for g in wheel video input audio netdev; do arch-chroot /mnt addgroup "$user" $g >> $log 2>&1; done + fi + step "Services" + case $wifi in + iwd) arch-chroot /mnt rc-update add iwd default >> $log 2>&1;; + networkmanager) + arch-chroot /mnt rc-update del dhcpcd default >> $log 2>&1 + arch-chroot /mnt rc-update add networkmanager default >> $log 2>&1;; + esac + step "The bootloader" + chamesle-boot -b $loader /mnt >> $log 2>&1 || exit 1 + cp $log /mnt/var/log/ 2>/dev/null + umount -R /mnt + [ $fs = zfs ] && zpool export rpool + exit 0 +) || { d --title "It failed" --textbox $log 0 0; die "the install failed, the log is $log"; } + +d --yesno "Chamesle is installed on $disk.\n\nTake out the USB stick and reboot?" 0 0 && reboot +clear diff --git a/tools/mkpkgs b/tools/mkpkgs @@ -16,7 +16,10 @@ mkdir -p "$tmp/mag/usr/bin" install -m755 "$MAG" "$tmp/mag/usr/bin/mag" mkapk -n mag -v "$("$MAG" --version | cut -d' ' -f2)" -d "the package manager" "$tmp/mag" -deps="alpine-baselayout busybox busybox-binsh busybox-suid doas mksh agetty bash mount umount findmnt util-linux-misc dinit dinit-shutdown eudev kmod dhcpcd e2fsprogs dosfstools curl mag" +mkdir -p "$tmp/init" +mkapk -n chamesle-init -v 1 -d "moves a base from before r20 over to OpenRC" -s "$here/pkg/chamesle-init" "$tmp/init" + +deps="alpine-baselayout busybox busybox-binsh busybox-suid doas mksh agetty bash mount umount findmnt util-linux-misc chamesle-init openrc busybox-openrc eudev eudev-openrc dhcpcd-openrc kmod dhcpcd e2fsprogs dosfstools curl mag" if [ -n "$RIFLE" ]; then mkdir -p "$tmp/rifle/usr/bin" install -m755 "$RIFLE" "$tmp/rifle/usr/bin/rifle" @@ -33,9 +36,9 @@ cp "$here/keys/"*.pub "$b/etc/mag/keys/" ln -s ../mag/keys "$b/etc/apk/keys" cp "$here/pkg/chamesle-base/repos" "$b/etc/mag/repos" cp "$here/pkg/chamesle-base/os-release" "$here/pkg/chamesle-base/issue" "$b/etc/" -for t in chamesle-bootstrap chamesle-disk chamesle-boot; do install -m755 "$here/tools/$t" "$b/usr/bin/$t"; done +for t in chamesle-bootstrap chamesle-disk chamesle-boot chamesle-install; do install -m755 "$here/tools/$t" "$b/usr/bin/$t"; done cp "$here/handbook/handbook.md" "$b/usr/share/doc/chamesle/handbook.md" -mkapk -n chamesle-base -v "$(date +%Y%m%d)-r${REL:-0}" -d "dinit's services, the files in /etc and the tools of Chamesle" \ +mkapk -n chamesle-base -v "$(date +%Y%m%d)-r${REL:-0}" -d "the files in /etc and the tools of Chamesle" \ -D "$deps" -s "$here/pkg/chamesle-base" "$b" if [ -n "$WMREL" ]; then