system

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

commit 54bb432a0fd0e6890ec36c7a457ff9182a860cf9
parent 82705162ff0ae747196d4182a499e2b3a80542dc
Author: torter <koubbamohamedrayan@gmail.com>
Date:   Sat, 14 Nov 2026 15:29:17 +0000

xorriso for the iso, the kernel from a package, no kernel build scripts, pkgsrc ids

Diffstat:
Mhandbook/handbook.md | 50+++++++++++++-------------------------------------
Miso/mkiso | 25+++++++++----------------
Miso/profile/packages | 19+++++++++++--------
Dkernel/build.sh | 38--------------------------------------
Dkernel/collect-hw.sh | 18------------------
Mtools/chamesle-bootstrap | 12+++---------
6 files changed, 36 insertions(+), 126 deletions(-)

diff --git a/handbook/handbook.md b/handbook/handbook.md @@ -8,7 +8,7 @@ and the package manager is `mag`. | part | what it is | |---|---| -| kernel | Linux 6.18, built by you (chapter 3) | +| kernel | Linux 6.18 LTS, the Alpine linux-lts build (chapter 3) | | musl | the C library | | rifle | the coreutils, one C file | | mag | the package manager, reads pkgsrc packages as they are | @@ -27,8 +27,7 @@ and the package manager is `mag`. 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/mksh 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. +`-s "shells/mksh editors/vim"` installs your own list, `-n name` sets the host name. ## 2. mag @@ -59,46 +58,25 @@ pkgsrc's `mk.conf` syntax, plain `VAR=value` lines, read from `$MAG_ROOT/etc/mag our own repo have no options, they only see `JOBS` and the flags. Environment wins over the file (`MAG_JOBS`, `CFLAGS`). -## 3. Building the kernel on the MSI +## 3. The kernel -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`. +Nobody here builds a kernel. `sys-kernel/linux` is the kernel and its modules from Alpine's linux-lts package +(6.18 LTS, built with the config of a distribution kernel, so it runs on nearly any machine). mag fetches it from +Alpine's mirror, checks the checksum and puts `vmlinuz`, `config`, `System.map` and the modules into `/boot` and +`/lib/modules`. Alpine drops a package from its mirror when a newer one comes out, so a new kernel is a new `version` +and `sha256` in `repo/sys-kernel/linux`. The firmware is `sys-kernel/linux-firmware`. ## 4. The ISO The ISO is an installer: it boots a small live system, and `chamesle-install` puts that on a disk. It boots on BIOS and UEFI machines with limine. - iso/mkiso -k chamesle-kernel-6.18.63.tar.xz -r $HOME/src/mag/repo:/usr/pkgsrc + iso/mkiso -r $HOME/src/mag/repo:/usr/pkgsrc What it does, in order: `chamesle-bootstrap` builds a root from `iso/profile/packages`, the files of -`iso/profile/overlay` are copied over it, the kernel tarball from chapter 3 is unpacked into it, `mkinitramfs` +`iso/profile/overlay` are copied over it, `mkinitramfs` makes the initrd (a few static tools, the modules in `iso/profile/modules` with what they depend on, `iso/init`), -the root becomes a zstd squashfs, and `mkisofs` writes the ISO with limine's BIOS and UEFI boot images. +the root becomes a zstd squashfs, and `xorriso` writes the ISO with limine's BIOS and UEFI boot images. `-R dir` uses a root you already have instead of building one (it is copied, not changed). At boot `init` looks for the medium that has `LiveOS/rootfs.sfs`, mounts it read-only, puts a tmpfs overlay over it, @@ -114,10 +92,8 @@ Try an ISO without a machine: qemu-system-x86_64 -cpu max -m 1G -cdrom chamesle.iso -boot d qemu-system-x86_64 -cpu max -m 1G -bios /usr/share/qemu/edk2-x86_64-code.fd -cdrom chamesle.iso # uefi -mkiso needs `mksquashfs` (filesystems/squashfs), `mkisofs` (sysutils/cdrtools, `MKISOFS` says which one), `zstd`, -`bsdcpio` and `limine` on the machine that builds. cdrtools' mkisofs makes an ISO that boots on BIOS machines and virtual machines from a CD. Limine's UEFI boot needs the -EFI image as a GPT partition inside the ISO, which only xorriso can write: for an ISO that boots on UEFI and from a stick, -build with `MKISOFS="xorriso -as mkisofs"`. `LIMINE` says where limine's files are (default /usr/share/limine). +mkiso needs `mksquashfs` (filesystems/squashfs), `xorriso` (sysutils/libisoburn), `zstd`, `bsdcpio` and `limine` on the +machine that builds. The ISO boots on BIOS and UEFI machines, from a CD and from a stick (dd it). `LIMINE` says where limine's files are (default /usr/share/limine). ## 5. Files diff --git a/iso/mkiso b/iso/mkiso @@ -1,28 +1,26 @@ #!/bin/sh # mkiso: builds the Chamesle installer ISO from a profile. -# mkiso -k kernel.tar.xz -r $HOME/src/mag/repo:/usr/pkgsrc -# mkiso -R /srv/rootfs -k kernel.tar.xz -o chamesle.iso +# mkiso -r $HOME/src/mag/repo:/usr/pkgsrc +# mkiso -R /srv/rootfs -o chamesle.iso set -e here=$(cd "$(dirname "$0")" && pwd) profile=$here/profile work=$PWD/work out=chamesle.iso -while getopts p:r:k:R:w:o: o; do +while getopts p:r:R:w:o: o; do case $o in p) profile=$OPTARG;; r) MAG_REPO=$OPTARG;; - k) kernel=$OPTARG;; R) rootfs=$OPTARG;; w) work=$OPTARG;; o) out=$OPTARG;; - *) echo "usage: mkiso [-p profile] [-r repos] [-k kernel.tar.xz] [-R rootfs] [-w workdir] [-o out.iso]" >&2; exit 2;; + *) echo "usage: mkiso [-p profile] [-r repos] [-R rootfs] [-w workdir] [-o out.iso]" >&2; exit 2;; esac done export MAG_REPO -: "${MKISOFS:=mkisofs}" +: "${MKISOFS:=xorriso -as mkisofs}" : "${LIMINE:=/usr/share/limine}" die() { echo "mkiso: $*" >&2; exit 1; } -[ -n "$kernel" ] || die "no kernel: build one with kernel/build.sh and give it with -k" [ -d "$LIMINE" ] && [ -f "$LIMINE/limine-bios-cd.bin" ] || die "no limine files in $LIMINE (set LIMINE)" for t in mksquashfs ${MKISOFS%% *} zstd bsdcpio limine; do command -v $t >/dev/null || die "$t is not installed"; done @@ -42,10 +40,9 @@ else fi tar -C "$profile/overlay" -cf - . | tar -C "$rootfs" -xf - -xz -dc "$kernel" | tar -C "$rootfs" -xf - vmlinuz=$(ls "$rootfs"/boot/vmlinuz-* | head -n 1) kver=$(ls "$rootfs/lib/modules" | head -n 1) -[ -f "$vmlinuz" ] && [ -n "$kver" ] || die "the kernel tarball has no boot/vmlinuz-* or lib/modules/*" +[ -f "$vmlinuz" ] && [ -n "$kver" ] || die "no kernel in the root: boot/vmlinuz-* and lib/modules/* are missing" cp "$vmlinuz" "$iso/boot/vmlinuz" "$here/mkinitramfs" -m "$profile/modules" "$rootfs" "$kver" "$iso/boot/initrd" @@ -57,13 +54,9 @@ cp "$LIMINE"/limine-bios.sys "$LIMINE"/limine-bios-cd.bin "$LIMINE"/limine-uefi- cp "$LIMINE"/BOOTX64.EFI "$iso/EFI/BOOT/" cp "$profile/limine.conf" "$iso/boot/limine/limine.conf" -case $MKISOFS in -xorriso*) efi="--efi-boot boot/limine/limine-uefi-cd.bin -efi-boot-part --efi-boot-image --protective-msdos-label" ;; -*) efi="-eltorito-alt-boot -eltorito-platform efi -b boot/limine/limine-uefi-cd.bin -no-emul-boot" - echo "mkiso: $MKISOFS cannot make the uefi image a partition, so this ISO boots on bios only; use MKISOFS=\"xorriso -as mkisofs\" for uefi" >&2 ;; -esac $MKISOFS -R -r -J -V CHAMESLE \ -b boot/limine/limine-bios-cd.bin -no-emul-boot -boot-load-size 4 -boot-info-table \ - $efi -o "$out" "$iso" >/dev/null 2>&1 || { echo "mkiso: $MKISOFS failed" >&2; exit 1; } -limine bios-install "$out" >/dev/null 2>&1 || echo "mkiso: no hybrid boot sector: the ISO boots from a CD or a virtual machine, not from a stick" >&2 + --efi-boot boot/limine/limine-uefi-cd.bin -efi-boot-part --efi-boot-image --protective-msdos-label \ + -o "$out" "$iso" >/dev/null 2>&1 || { echo "mkiso: $MKISOFS failed" >&2; exit 1; } +limine bios-install "$out" >/dev/null echo "$out: $(du -h "$out" | cut -f1)" diff --git a/iso/profile/packages b/iso/profile/packages @@ -1,17 +1,20 @@ # what goes into the installer image sys-libs/musl -dev-build/gmake -app-arch/libarchive -app-arch/pigz +devel/gmake +archivers/libarchive +archivers/pigz shells/mksh -sys-apps/dinit +sysutils/dinit sys-apps/util-linux sys-apps/kmod sys-apps/eudev -net-misc/dhcpcd -net-misc/curl -sys-fs/e2fsprogs -sys-fs/dosfstools +net/dhcpcd +www/curl +sysutils/e2fsprogs +sysutils/dosfstools sys-boot/limine +sys-kernel/linux +sys-kernel/linux-firmware +sys-firmware/sof-firmware sys-firmware/wireless-regdb editors/vim diff --git a/kernel/build.sh b/kernel/build.sh @@ -1,38 +0,0 @@ -#!/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 @@ -1,18 +0,0 @@ -#!/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 @@ -5,21 +5,19 @@ # chamesle-bootstrap -r ~/repos/ports -s "shells/mksh editors/vim" /srv/chroot set -e usage() { - echo "usage: chamesle-bootstrap [-r REPOS] [-s PACKAGES] [-n HOSTNAME] [-k KERNEL.tar.xz] TARGET" >&2 + echo "usage: chamesle-bootstrap [-r REPOS] [-s PACKAGES] [-n HOSTNAME] 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 shells/mksh 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" +base="sys-libs/musl devel/gmake archivers/libarchive archivers/pigz shells/mksh sysutils/dinit sys-apps/util-linux sys-apps/kmod sys-apps/eudev net/dhcpcd www/curl sysutils/e2fsprogs sysutils/dosfstools sys-boot/limine sys-kernel/linux sys-kernel/linux-firmware sys-firmware/sof-firmware sys-firmware/wireless-regdb editors/vim" name=chamesle -while getopts r:s:n:k: o; do +while getopts r:s:n: o; do case $o in r) MAG_REPO=$OPTARG;; s) base=$OPTARG;; n) name=$OPTARG;; - k) kernel=$OPTARG;; *) usage;; esac done @@ -54,8 +52,4 @@ export MAG_ROOT=$PWD MAG_PREFIX=/usr MAG_REPO echo "installing: $base" mag install $base [ -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"