system

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

commit c5f2ed6e6544c3f554774e1ced99038c53b8aab3
Author: torter <koubbamohamedrayan@gmail.com>
Date:   Sat, 14 Nov 2026 14:29:12 +0000

chamesle: bootstrap tool, kernel scripts for the MSI, handbook

Diffstat:
AREADME.md | 1+
Ahandbook/handbook.md | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Akernel/build.sh | 38++++++++++++++++++++++++++++++++++++++
Akernel/collect-hw.sh | 18++++++++++++++++++
Atools/chamesle-bootstrap | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 213 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md @@ -0,0 +1 @@ +Chamesle: the system around mag, rifle and musl. `handbook/handbook.md` has the how, `tools/chamesle-bootstrap` makes a root file system, `kernel/` builds the kernel. diff --git a/handbook/handbook.md b/handbook/handbook.md @@ -0,0 +1,90 @@ +# The Chamesle handbook + +Chamesle is a Linux system you build from source and keep small. The kernel is the only thing in it that comes +from outside the Unix family: the C library is musl, the shell is ksh, the packages come from NetBSD's pkgsrc +and the package manager is `mag`. + +## What is in it + +| part | what it is | +|---|---| +| kernel | Linux 6.18, built by you (chapter 3) | +| musl | the C library | +| rifle | the coreutils, one C file | +| mag | the package manager, reads pkgsrc packages as they are | +| dinit | init and service manager | +| oksh | the login shell (the OpenBSD ksh), `/bin/sh` is dash | +| vim | the editor, installed on the ISO | +| limine | the boot loader | + +## 1. Getting a root file system + +`tools/chamesle-bootstrap` is to Chamesle what debootstrap is to Debian. It makes the directories and the files in +`/etc`, then builds and installs the base packages into the directory you give it with `mag`: + + MAG_REPO=$HOME/src/mag/repo:/usr/pkgsrc chamesle-bootstrap /mnt/root + +Building everything from source takes a while (LLVM is the long one). Packages are not built twice: the sources +are kept in `var/cache/mag` inside the target. + +`-s "shells/oksh editors/vim"` installs your own list, `-n name` sets the host name, `-k kernel.tar.xz` unpacks a +kernel from chapter 3 into the target. + +## 2. mag + + mag install editors/vim fetch, check the checksum, build, install, dependencies first + mag remove vim + mag upgrade rebuild what has a newer version + mag search word | info pkg | files pkg | owns /path | deps pkg | list + +`MAG_REPO` is a list of repos split by colons. Two kinds of package live in them and can be mixed: + +* our own recipes, `category/name`, a file with `url`, `sha256`, `deps` and plain sh `steps` +* NetBSD pkgsrc packages, a directory with a `Makefile`, a `distinfo` and `patches/`, read without `bmake` + +A file called `PROVIDES` in a repo says which of our packages stands in for a pkgsrc one (so a pkgsrc package gets +our zlib and not a second one) and which dependencies a pkgsrc Makefile forgets (`needs`). Everything lands in +`$MAG_ROOT`, nothing is ever installed over a file another package owns, and `/etc` files you changed stay. + +## 3. Building the kernel on the MSI + +The MSI is the machine the kernel has to boot on, so it is the one that knows what hardware there is. Any +Linux that already runs on it will do for the building. + +Step one. Tell us what is in the machine: + + sh kernel/collect-hw.sh # writes hw.txt: cpu, pci, usb, loaded modules, UEFI or BIOS. no serial numbers, no addresses + +Step two. Build: + + sh kernel/build.sh # config of the running kernel as the start, safe and big + sh kernel/build.sh small # only what the machine uses right now (plug in everything you own first) + +It downloads linux-6.18.63 from kernel.org, checks the checksum, builds `bzImage` and the modules and packs them into +`~/chamesle-kernel/chamesle-kernel-6.18.63.tar.xz`. It needs gcc or clang, make, flex, bison, bc, perl, curl, xz. +On a recent MSI with many cores it takes a quarter of an hour, with `small` less. + +Step three. Get the files to the computer that builds Chamesle. Any of these: + +* **a USB stick:** copy `chamesle-kernel-6.18.63.tar.xz`, `chamesle-kernel-6.18.63.sha256` and `hw.txt` onto it +* **over the network with nc:** on the receiving computer `nc -l 9000 > kernel.tar.xz`, on the MSI + `nc ADDRESS 9000 < chamesle-kernel-6.18.63.tar.xz` (address is what `ip -4 addr` shows on the receiving one) +* **the MSI serves, the other fetches:** on the MSI `cd ~/chamesle-kernel && python3 -m http.server 8000`, on the + other `curl -O http://MSI-ADDRESS:8000/chamesle-kernel-6.18.63.tar.xz` +* **scp** works when sshd runs on the receiving side + +Check it on arrival: `sha256sum -c chamesle-kernel-6.18.63.sha256`. + +## 4. The ISO + +One ISO boots on any machine and has oksh as the login shell and vim installed. It is a squashfs root file system +made by `chamesle-bootstrap`, the kernel from chapter 3 and limine on top. The builder is not written yet. + +## 5. Files + + /etc/profile PATH, EDITOR=vim + /etc/ksh.kshrc prompt and aliases of every ksh + /etc/dinit.d/ services + /etc/fstab, hostname, passwd, group, shells + /var/lib/mag what is installed, per package + /var/cache/mag downloaded sources diff --git a/kernel/build.sh b/kernel/build.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# builds linux 6.18 on this machine and packs the result in one tarball you can hand over. +# ./build.sh the running kernel's config as the start (safe, big) +# ./build.sh small only what this machine uses right now (small, make sure everything you own is plugged in) +# needs: a C compiler, make, flex, bison, bc, perl, openssl headers or libelf are NOT needed (we switch those parts off), curl, tar, xz +set -e +ver=6.18.63 +sum=81764a545072d160748beff4d9de2e7d95aa9f16e8261110288f067a2cc61d71 +jobs=$(nproc 2>/dev/null || echo 4) +work=${WORK:-$HOME/chamesle-kernel} +mkdir -p "$work" && cd "$work" +if [ ! -f linux-$ver.tar.xz ]; then + curl -fL -o linux-$ver.tar.xz https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-$ver.tar.xz +fi +[ "$(sha256sum linux-$ver.tar.xz | cut -d' ' -f1)" = $sum ] || { echo "the tarball does not match its checksum, delete it and run again"; exit 1; } +[ -d linux-$ver ] || tar -xf linux-$ver.tar.xz +cd linux-$ver +if [ -r /proc/config.gz ]; then zcat /proc/config.gz > .config +elif [ -r /boot/config-$(uname -r) ]; then cp /boot/config-$(uname -r) .config +else make defconfig; fi +if [ "$1" = small ]; then lsmod > "$work/lsmod.txt"; make LSMOD="$work/lsmod.txt" localmodconfig; fi +scripts/config -d MODULE_SIG -d MODULE_SIG_ALL -d SYSTEM_TRUSTED_KEYRING -d SYSTEM_REVOCATION_KEYS -d DEBUG_INFO_BTF -d DEBUG_INFO_BTF_MODULES \ + -d UNWINDER_ORC -e UNWINDER_FRAME_POINTER -d WERROR \ + -e DEVTMPFS -e DEVTMPFS_MOUNT -e EFI_STUB -e BLK_DEV_INITRD -e FW_LOADER -e FW_LOADER_COMPRESS -e FW_LOADER_COMPRESS_ZSTD \ + -e EXT4_FS -e VFAT_FS -e ISO9660_FS -e SQUASHFS -e SQUASHFS_ZSTD -e OVERLAY_FS -e TMPFS -e PROC_FS -e SYSFS \ + --set-str LOCALVERSION "-chamesle" --set-str SYSTEM_TRUSTED_KEYS "" --set-str SYSTEM_REVOCATION_KEYS "" +make olddefconfig +make -j"$jobs" bzImage modules +rm -rf "$work/out" && mkdir -p "$work/out/boot" +cp arch/x86/boot/bzImage "$work/out/boot/vmlinuz-$ver-chamesle" +cp System.map "$work/out/boot/System.map-$ver-chamesle" +cp .config "$work/out/boot/config-$ver-chamesle" +make INSTALL_MOD_PATH="$work/out" INSTALL_MOD_STRIP=1 modules_install +rm -f "$work"/out/lib/modules/*/build +cd "$work" +tar -C out -cf - . | xz -T0 > chamesle-kernel-$ver.tar.xz +sha256sum chamesle-kernel-$ver.tar.xz | tee chamesle-kernel-$ver.sha256 +echo "done: $work/chamesle-kernel-$ver.tar.xz" diff --git a/kernel/collect-hw.sh b/kernel/collect-hw.sh @@ -0,0 +1,18 @@ +#!/bin/sh +# run this on the MSI, from any distro that boots there. it writes hw.txt: what the machine has, so the kernel can be +# configured for it. nothing private in it (no serials, no ip addresses) +out=${1:-hw.txt} +{ + echo "## cpu"; grep -m1 'model name' /proc/cpuinfo; grep -c '^processor' /proc/cpuinfo + echo "## dmi"; for f in sys_vendor product_name board_name bios_version; do printf '%s: ' $f; cat /sys/class/dmi/id/$f 2>/dev/null; done + echo "## memory"; grep MemTotal /proc/meminfo + echo "## pci"; lspci -nnk 2>/dev/null + echo "## usb"; lsusb 2>/dev/null + echo "## modules"; lsmod | awk 'NR>1{print $1}' | sort + echo "## block"; lsblk -o NAME,SIZE,TYPE,FSTYPE,MODEL 2>/dev/null + echo "## efi"; [ -d /sys/firmware/efi ] && echo uefi || echo bios + echo "## kernel"; uname -r + echo "## wifi"; ls /sys/class/net + echo "## firmware asked for"; dmesg 2>/dev/null | grep -i 'firmware' | sed 's/^\[[^]]*\] //' | sort -u | head -40 +} > "$out" +echo "wrote $out" diff --git a/tools/chamesle-bootstrap b/tools/chamesle-bootstrap @@ -0,0 +1,66 @@ +#!/bin/sh +# chamesle-bootstrap TARGET: makes a root file system in TARGET, like debootstrap does for Debian. +# the directories, the files in /etc, then every package of the base set built and installed there with mag. +# chamesle-bootstrap /mnt/root +# chamesle-bootstrap -r ~/repos/ports -s "shells/oksh editors/vim" /srv/chroot +set -e +usage() { + echo "usage: chamesle-bootstrap [-r REPOS] [-s PACKAGES] [-n HOSTNAME] [-k KERNEL.tar.xz] TARGET" >&2 + echo " -r repos split by colons, what mag takes in MAG_REPO (default: \$MAG_REPO)" >&2 + echo " -s the packages to install instead of the base set" >&2 + echo " -n host name of the new system (default chamesle)" >&2 + echo " -k a kernel tarball made by kernel/build.sh, unpacked into TARGET" >&2 + exit 2 +} +base="sys-libs/musl dev-build/gmake app-arch/libarchive app-arch/pigz app-shells/dash app-shells/oksh sys-apps/dinit sys-apps/util-linux sys-apps/kmod sys-apps/eudev net-misc/dhcpcd net-misc/curl sys-fs/e2fsprogs sys-fs/dosfstools sys-boot/limine editors/vim" +name=chamesle +while getopts r:s:n:k: o; do + case $o in + r) MAG_REPO=$OPTARG;; + s) base=$OPTARG;; + n) name=$OPTARG;; + k) kernel=$OPTARG;; + *) usage;; + esac +done +shift $((OPTIND - 1)) +[ $# = 1 ] || usage +target=$1 +[ -n "$MAG_REPO" ] || { echo "chamesle-bootstrap: no repos: give -r or set MAG_REPO" >&2; exit 1; } +command -v mag >/dev/null || { echo "chamesle-bootstrap: mag is not in PATH" >&2; exit 1; } +[ "$(id -u)" = 0 ] || echo "chamesle-bootstrap: not root, so files will belong to you and the device nodes are skipped" >&2 +mkdir -p "$target" +cd "$target" +for d in bin boot dev etc/dinit.d etc/skel home lib lib/firmware mnt proc root run sbin srv sys tmp usr/bin usr/lib usr/sbin usr/share usr/local/bin var/cache var/lib var/log var/tmp; do + mkdir -p "$d" +done +chmod 1777 tmp var/tmp +chmod 700 root +[ -e etc/passwd ] || cat > etc/passwd <<P +root:x:0:0:root:/root:/usr/bin/oksh +P +[ -e etc/group ] || printf 'root:x:0:\nwheel:x:10:\nusers:x:100:\n' > etc/group +[ -e etc/shells ] || printf '/bin/sh\n/usr/bin/oksh\n/usr/bin/dash\n' > etc/shells +[ -e etc/hostname ] || echo "$name" > etc/hostname +[ -e etc/fstab ] || printf '# device mount type options dump pass\nproc /proc proc defaults 0 0\nsysfs /sys sysfs defaults 0 0\ntmpfs /tmp tmpfs mode=1777 0 0\n' > etc/fstab +[ -e etc/profile ] || cat > etc/profile <<'P' +export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin +export EDITOR=vim +export PAGER=less +umask 022 +P +[ -e etc/ksh.kshrc ] || cat > etc/ksh.kshrc <<'P' +PS1='\u@\h:\w\$ ' +alias ls='ls -F' +P +[ -e etc/os-release ] || printf 'NAME=Chamesle\nID=chamesle\nPRETTY_NAME="Chamesle"\n' > etc/os-release +export MAG_ROOT=$PWD MAG_PREFIX=/usr MAG_REPO +echo "installing: $base" +mag install $base +ln -sf dash usr/bin/sh 2>/dev/null || true +[ -e bin/sh ] || ln -s ../usr/bin/sh bin/sh 2>/dev/null || true +if [ -n "$kernel" ]; then + echo "kernel: $kernel" + xz -dc "$kernel" | tar -C "$target" -xf - +fi +echo "done: $target"