system

the Chamesle handbook, init, live ISO and install helpers
git clone https://github.com/tortr-rs/system
Log | Files | Refs | README | LICENSE

commit dd34e9b30a9ad6e62c3db78afb3ed901f1e5839f
parent a97836fb46099093ee3c40e8d3a138e3eb8e0241
Author: torter <koubbamohamedrayan@gmail.com>
Date:   Mon, 16 Nov 2026 19:53:51 +0000

live image: doas, the evdev X driver, chamesle-vm to install into a disk image in qemu

Diffstat:
Miso/mkiso | 10+++++++---
Aiso/profile/overlay/etc/doas.conf | 2++
Aiso/profile/overlay/usr/bin/sudo | 2++
Miso/profile/packages | 4++--
Mtools/chamesle-bootstrap | 2+-
Atools/chamesle-vm | 102+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 116 insertions(+), 6 deletions(-)

diff --git a/iso/mkiso b/iso/mkiso @@ -48,8 +48,12 @@ fi [ -n "$MAG" ] || MAG=$(command -v mag) || die "no mag: put it in PATH or set MAG" MAG_ROOT=$rootfs MAG_PREFIX=/usr "$MAG" relocate ${from:+"$from"} -rm -rf "$rootfs"/var/cache/mag "$rootfs"/var/tmp/mag "$rootfs"/usr/include "$rootfs"/usr/lib/pkgconfig "$rootfs"/lib/firmware -find "$rootfs"/usr/lib -name "*.a" -o -name "*.la" | xargs rm -f +rm -rf "$rootfs"/var/cache/mag "$rootfs"/var/tmp/mag "$rootfs"/lib/firmware +# KEEPDEV=1 keeps the headers and static libraries, so the compiler in the image can build things +if [ -z "$KEEPDEV" ]; then + rm -rf "$rootfs"/usr/include "$rootfs"/usr/lib/pkgconfig + find "$rootfs"/usr/lib -name "*.a" -o -name "*.la" | xargs rm -f +fi tar -C "$profile/overlay" -cf - . | tar -C "$rootfs" -xf - for t in chamesle-bootstrap chamesle-chroot chamesle-disk; do install -Dm755 "$here/../tools/$t" "$rootfs/usr/bin/$t" @@ -69,7 +73,7 @@ depmod -b "$rootfs" "$kver" "$here/mkinitramfs" -m "$profile/modules" "$rootfs" "$kver" "$iso/boot/initrd" rm -f "$iso/LiveOS/rootfs.sfs" -mksquashfs "$rootfs" "$iso/LiveOS/rootfs.sfs" -comp zstd -Xcompression-level 19 -b 256K -noappend -no-progress >/dev/null +mksquashfs "$rootfs" "$iso/LiveOS/rootfs.sfs" -all-root -comp zstd -Xcompression-level 19 -b 256K -noappend -no-progress >/dev/null cp "$LIMINE"/limine-bios.sys "$LIMINE"/limine-bios-cd.bin "$LIMINE"/limine-uefi-cd.bin "$iso/boot/limine/" cp "$LIMINE"/BOOTX64.EFI "$iso/EFI/BOOT/" diff --git a/iso/profile/overlay/etc/doas.conf b/iso/profile/overlay/etc/doas.conf @@ -0,0 +1,2 @@ +permit persist :wheel +permit nopass root diff --git a/iso/profile/overlay/usr/bin/sudo b/iso/profile/overlay/usr/bin/sudo @@ -0,0 +1 @@ +doas +\ No newline at end of file diff --git a/iso/profile/packages b/iso/profile/packages @@ -31,7 +31,7 @@ x11/setxkbmap x11/xrdb x11/xf86-video-vesa x11/xf86-video-fbdev -x11/xf86-input-keyboard -x11/xf86-input-mouse +dev-libs/libevdev +x11-drivers/xf86-input-evdev fonts/dejavu-ttf fonts/fontconfig diff --git a/tools/chamesle-bootstrap b/tools/chamesle-bootstrap @@ -71,7 +71,7 @@ export PAGER=less umask 022 P [ -e etc/os-release ] || printf 'NAME=Chamesle\nID=chamesle\nPRETTY_NAME="Chamesle"\n' > etc/os-release -[ -e etc/mag.conf ] || printf '# read by mag, same syntax as pkgsrc mk.conf\nJOBS=%s\nCFLAGS=-O2 -std=gnu17 -include sys/sysmacros.h\nPKG_OPTIONS.tnftp=ssl\nCONFIGURE_ARGS.libtirpc=--disable-gssapi\nPKG_SYSCONFDIR.libressl=/etc/ssl\nMAKE.libunistring=gmake\nMAKE.sudo=gmake\nCONFIGURE_ARGS.gmp=--disable-assembly --disable-cxx\nPKG_OPTIONS.opendoas=persist\nCONFIGURE_ARGS.doas=--without-pam\n' "$(nproc 2>/dev/null || echo 4)" > etc/mag.conf +[ -e etc/mag.conf ] || printf '# read by mag, same syntax as pkgsrc mk.conf\nJOBS=%s\nCFLAGS=-O2 -std=gnu17 -include sys/sysmacros.h\nPKG_OPTIONS.tnftp=ssl\nCONFIGURE_ARGS.libtirpc=--disable-gssapi\nPKG_SYSCONFDIR.libressl=/etc/ssl\nMAKE.libunistring=gmake\nMAKE.sudo=gmake\nCONFIGURE_ARGS.gmp=--disable-assembly --disable-cxx --disable-fat\nPKG_OPTIONS.opendoas=persist\nCONFIGURE_ARGS.doas=--without-pam\n' "$(nproc 2>/dev/null || echo 4)" > etc/mag.conf export MAG_ROOT=$PWD MAG_PREFIX=/usr MAG_REPO echo "installing: $base" mag install $base diff --git a/tools/chamesle-vm b/tools/chamesle-vm @@ -0,0 +1,102 @@ +#!/bin/sh +# chamesle-vm: runs the Chamesle ISO or an installed disk in qemu, in this terminal, no window. +# chamesle-vm iso boot the live ISO with an empty disk attached, to install onto +# chamesle-vm disk boot the disk that was installed +# chamesle-vm install wipe the disk and put the live system on it, typing the steps into the vm for you +# chamesle-vm reset throw the disk away and make an empty one +# chamesle-vm -g iso same, but with a window +# the console is this terminal: ctrl-a x leaves qemu, ctrl-a c switches to the qemu monitor. +# the disk is UEFI, so /boot is the EFI partition and limine goes to EFI/BOOT/BOOTX64.EFI. +# ISO=path DISK=path SIZE=16G MEM=2048 CPUS=2 chamesle-vm iso +die() { echo "chamesle-vm: $*" >&2; exit 1; } +dir=${VMDIR:-$HOME/chamesle-build/vm} +: "${ISO:=$HOME/chamesle-build/iso-out/chamesle.iso}" +: "${DISK:=$dir/disk.img}" +: "${SIZE:=16G}" +: "${MEM:=2048}" +: "${CPUS:=2}" +: "${FW:=/usr/share/edk2-ovmf}" +gui= +if [ "$1" = -g ]; then gui=1; shift; fi +mode=${1:-iso} + +mkdir -p "$dir" +# a disk that a running qemu has open must not be touched +inuse() { + for p in $(pgrep qemu-system); do + for f in /proc/$p/fd/*; do [ "$(readlink "$f" 2>/dev/null)" = "$DISK" ] && return 0; done + done + return 1 +} +if inuse; then die "a vm is already running on $DISK, leave it with ctrl-a x first"; fi +[ -f "$FW/OVMF_CODE.fd" ] && [ -f "$FW/OVMF_VARS.fd" ] || die "no OVMF in $FW (set FW)" +case $mode in +reset) rm -f "$DISK" "$dir/vars.fd"; echo "disk removed"; exit 0;; +iso|disk|install) ;; +*) echo "usage: chamesle-vm [-g] iso|disk|install|reset" >&2; exit 2;; +esac +[ "$mode" = install ] && rm -f "$DISK" "$dir/vars.fd" +[ -f "$DISK" ] || { qemu-img create -f raw "$DISK" "$SIZE" >/dev/null || die "cannot make $DISK"; echo "new empty disk: $DISK ($SIZE)"; } +[ -f "$dir/vars.fd" ] || cp "$FW/OVMF_VARS.fd" "$dir/vars.fd" + +set -- -m "$MEM" -smp "$CPUS" -machine q35 \ + -drive if=pflash,format=raw,readonly=on,file="$FW/OVMF_CODE.fd" \ + -drive if=pflash,format=raw,file="$dir/vars.fd" \ + -drive file="$DISK",format=raw,if=virtio \ + -nic user,model=virtio-net-pci -device virtio-rng-pci +[ -w /dev/kvm ] && set -- "$@" -accel kvm -cpu host +if [ "$mode" = iso ] || [ "$mode" = install ]; then + [ -f "$ISO" ] || die "no ISO at $ISO (set ISO)" + set -- "$@" -drive file="$ISO",media=cdrom,readonly=on -boot order=d +else + [ -n "$(head -c 512 "$DISK" | tr -d '\000')" ] || die "the disk is empty, install onto it first (chamesle-vm iso)" +fi +if [ "$mode" = install ]; then + rm -f "$dir"/ser.*; mkfifo "$dir/ser.in" "$dir/ser.out" + qemu-system-x86_64 "$@" -display none -serial pipe:"$dir/ser" -monitor none & + qpid=$! + cat "$dir/ser.out" > "$dir/ser.log" & + exec 3> "$dir/ser.in" + # run CMD in the vm and wait until it has finished, stop if it failed. the sentinel is computed, so the echoed command line never matches it + run() { + echo "==> $1" + printf '%s; echo __R$((0+$?))_X\n' "$2" >&3 + t=0 + while ! grep -q '__R[0-9]*_X' "$dir/ser.log"; do + sleep 2; t=$((t + 2)) + [ $t -lt "${3:-300}" ] || { kill $qpid; die "'$1' took too long, see $dir/ser.log"; } + done + grep -q '__R0_X' "$dir/ser.log" || { tail -n 8 "$dir/ser.log" >&2; kill $qpid; die "'$1' failed"; } + : > "$dir/ser.log" + } + echo "==> booting the ISO (a minute or two without kvm)" + # any key stops the boot menu's countdown, so say nothing until the kernel is up + n=0 + until grep -q 'Linux version' "$dir/ser.log"; do + sleep 2; n=$((n + 2)) + [ $n -lt 240 ] || { kill $qpid; die "the kernel did not start, see $dir/ser.log"; } + done + sleep 20 + n=0 + while ! grep -q '__U42_X' "$dir/ser.log"; do + printf 'echo __U$((6*7))_X\n' >&3; sleep 5; n=$((n + 5)) + [ $n -lt 300 ] || { kill $qpid; die "the live system did not come up, see $dir/ser.log"; } + done + : > "$dir/ser.log" + run "partitioning" "printf 'label: gpt\nsize=512M, type=U\ntype=L\n' | sfdisk /dev/vda >/dev/null && sleep 2" + run "boot partition" "modprobe vfat; mkfs.fat -F32 /dev/vda1 >/dev/null" + run "zfs pool" "modprobe zfs && zpool create -f -o ashift=12 -O compression=zstd -O acltype=posixacl -O xattr=sa -O mountpoint=none -R /mnt rpool /dev/vda2 && zfs create -o mountpoint=/ -o canmount=noauto rpool/root && zfs create -o mountpoint=/home rpool/home && zfs create -o mountpoint=/var rpool/var && zpool set bootfs=rpool/root rpool && zfs mount rpool/root && zfs mount -a && mkdir -p /mnt/boot && mount -t vfat /dev/vda1 /mnt/boot" + run "copying the system" "tar -C /run/live/rootfs -cf - . | tar -C /mnt -xpf - && cp /run/live/medium/boot/initrd /mnt/boot/initrd && cp /mnt/boot/vmlinuz-* /mnt/boot/vmlinuz" 900 + run "fstab, password, boot entry" "printf 'UUID=%s /boot vfat rw,noatime 0 2\n' \$(blkid -s UUID -o value /dev/vda1) >> /mnt/etc/fstab && sed -i 's/^root:x:/root:/' /mnt/etc/passwd && mkdir -p /mnt/boot/EFI/BOOT && cp /mnt/usr/share/limine/BOOTX64.EFI /mnt/boot/EFI/BOOT/ && printf 'timeout: 3\nserial: yes\n\n/Chamesle\n protocol: linux\n path: boot():/vmlinuz\n module_path: boot():/initrd\n cmdline: root=ZFS=rpool/root rw console=tty0 console=ttyS0,115200\n' > /mnt/boot/limine.conf" + run "unmounting" "umount -R /mnt && zpool export rpool" + echo "==> shutting down" + printf 'poweroff\n' >&3 + wait $qpid + rm -f "$dir"/ser.in "$dir"/ser.out + echo "installed. start it with: chamesle-vm disk (root has no password)" + exit 0 +fi +if [ -n "$gui" ]; then + exec qemu-system-x86_64 "$@" +fi +exec qemu-system-x86_64 "$@" -nographic