Faster ISO builds (69 s to 9 s) and a faster write.sh check

make iso recompiled the kernel and every command each time: iso and
ramroot wiped build/kernel, build/lib and build/cmd to make sure nothing
was compiled for the wrong RAMROOT setting. Only kernel/proc/proc.c and
kernel/dev/ramdisk.c read RAMDISK_ROOT, so only their objects go now.

Even then a no-op make iso took 69 s, because sysroot.stamp lists every
staged file with its mtime and two things re-copied files on every run:
the plain cp in etc-install (now cp -p) and fastfetch's install (now
install -C). A changed stamp rebuilds the Alpine root, the root image
and its zstd -19 compression. A no-op, and a one-file kernel change,
now take about 9 s.

write.sh read the stick back with a buffered cmp, slowly and possibly from
the page cache. It now reads 4 MB at a time with iflag=direct, which
checks the stick itself; --no-verify skips the check.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015f73FesGZGYPkmDvUcj6QX
This commit is contained in:
Nexoniarz 2026-10-25 19:28:03 +01:00
commit 7d2eca8271
3 changed files with 38 additions and 16 deletions

View file

@ -3,6 +3,7 @@
#
# ./write.sh sdc or ./write.sh /dev/sdc
# ./write.sh sdc other.iso to write a different image
# ./write.sh sdc --no-verify skip the read-back check (halves the time)
#
# Shows what is on the device, asks you to type the device's name back, then
# asks for your password and writes. Everything on the device is destroyed;
@ -26,7 +27,7 @@ fi
die() { printf '%swrite.sh:%s %s\n' "$R" "$N" "$*" >&2; exit 1; }
usage() {
echo "usage: ./write.sh <device> [image.iso] [--any-disk]"
echo "usage: ./write.sh <device> [image.iso] [--any-disk] [--no-verify]"
echo " ./write.sh sdc writes schos.iso to /dev/sdc"
echo
echo "Removable disks on this machine:"
@ -36,11 +37,13 @@ usage() {
}
ANY=0
VERIFY=1
DEV=
ISO=
for a in "$@"; do
case "$a" in
--any-disk) ANY=1 ;;
--no-verify) VERIFY=0 ;;
-h|--help) usage ;;
*) if [ -z "$DEV" ]; then DEV=$a; elif [ -z "$ISO" ]; then ISO=$a; else usage; fi ;;
esac
@ -127,12 +130,22 @@ sync
# --- check ------------------------------------------------------------------
# Read it back. A stick that takes the write and keeps none of it is common
# enough among cheap ones to be worth thirty seconds.
echo "Checking what was written..."
if sudo cmp -n "$ISO_BYTES" "$ISO" "$DEV"; then
echo "${G}Done.${N} $DEV holds $(basename "$ISO") and can be removed."
# enough among cheap ones to be worth the time.
#
# iflag=direct and 4 MB reads: a plain `cmp ISO /dev/sdX` reads through the page
# cache in small requests, which a USB stick serves slowly -- and may be answered
# from the cache rather than from the stick, checking nothing. Direct reads
# check the stick itself, and at the speed it can actually deliver.
if [ "$VERIFY" = 1 ]; then
echo "Checking what was written..."
BLOCKS=$(( (ISO_BYTES + 4194303) / 4194304 ))
if sudo dd if="$DEV" bs=4M count="$BLOCKS" iflag=direct status=none | cmp -n "$ISO_BYTES" - "$ISO"; then
echo "${G}Done.${N} $DEV holds $(basename "$ISO") and can be removed."
else
die "the device does not read back what was written -- the stick may be failing"
fi
else
die "the device does not read back what was written -- the stick may be failing"
echo "${G}Done.${N} $DEV holds $(basename "$ISO") (not verified) and can be removed."
fi
# The kernel re-reads the partition table so the new layout shows up here