Files
aero3/scripts/08-image.sh
T

118 lines
4.6 KiB
Bash
Raw Normal View History

2026-06-19 10:02:12 -04:00
#!/usr/bin/env bash
# scripts/08-image.sh — assemble the bootable hybrid (BIOS+UEFI) live ISO.
#
# Layout produced:
# ISO/
# boot/vmlinuz-aeros (kernel)
# boot/initrd-aeros.img (busybox initramfs: squashfs+overlay+switch_root)
# boot/grub/grub.cfg
# boot/grub/aero-splash.png (wallpaper, as boot splash)
# LiveOS/aeros.squashfs (the whole AeroOS root, compressed)
# -> xorriso/grub-mkrescue -> out/aeros-<ver>-x86_64.iso (isohybrid)
source "$(dirname "${BASH_SOURCE[0]}")/lib/common.sh"
require_root
LFS="$AEROS_ROOT"
WORK="$AEROS_OUT/imgwork"
ISODIR="$WORK/iso"
trap 'mountpoint -q "$LFS/sources" && umount -l "$LFS/sources"; umount_vkfs 2>/dev/null || true' EXIT
build_image_tools() {
step "Image tooling (busybox/squashfs/xorriso/grub-efi)"
mount_vkfs
mkdir -p "$LFS/sources"
mountpoint -q "$LFS/sources" || mount --bind "$AEROS_SOURCES" "$LFS/sources"
install -m755 "$AEROS_TOP/packages/chroot-imagetools.sh" "$LFS/root/build-imgtools.sh"
in_chroot "MAKEFLAGS='-j${AEROS_JOBS}' /root/build-imgtools.sh"
mountpoint -q "$LFS/sources" && umount -l "$LFS/sources" || true
umount_vkfs
}
make_initramfs() {
step "Initramfs"
local IR="$WORK/initramfs"
rm -rf "$IR"; mkdir -p "$IR"/{bin,sbin,proc,sys,dev,run,sysroot,etc}
mknod -m 600 "$IR/dev/console" c 5 1
mknod -m 666 "$IR/dev/null" c 1 3
mknod -m 666 "$IR/dev/tty" c 5 0
# busybox provides sh, mount, switch_root, blkid, etc. (static => no libs)
install -Dm755 "$LFS/usr/bin/busybox-static" "$IR/bin/busybox"
# init script with the ISO label substituted in
sed "s/@@ISO_LABEL@@/$AEROS_ISO_LABEL/g" "$AEROS_TOP/assets/live/init" \
> "$IR/init"
chmod +x "$IR/init"
ln -sf bin/busybox "$IR/sbin/busybox" 2>/dev/null || true
( cd "$IR" && find . | cpio -o -H newc 2>/dev/null | gzip -9 ) \
> "$ISODIR/boot/initrd-aeros.img"
ok "initramfs -> boot/initrd-aeros.img ($(du -h "$ISODIR/boot/initrd-aeros.img" | cut -f1))"
}
make_squashfs() {
step "SquashFS root (compressing the AeroOS system)"
install -d "$ISODIR/LiveOS"
# exclude build-only/transient content from the shipped root
local EXCL=(
--exclude-regex '^sources(/|$)'
--exclude-regex '^tools(/|$)'
--exclude-regex '^root/build-.*\.sh$'
--exclude-regex '^root/setup-users\.sh$'
--exclude-regex '^root/aeros\.config$'
--exclude-regex '^\.stamps(/|$)'
--exclude-regex '^tmp/.+'
--exclude-regex '^usr/src/aerowm/build(/|$)'
)
"$LFS/usr/bin/mksquashfs" "$LFS" "$ISODIR/LiveOS/aeros.squashfs" \
-comp zstd -Xcompression-level 19 -noappend -no-progress \
-e sources tools 2>/dev/null \
|| mksquashfs "$LFS" "$ISODIR/LiveOS/aeros.squashfs" -comp zstd -noappend \
-e sources tools
ok "squashfs -> LiveOS/aeros.squashfs ($(du -h "$ISODIR/LiveOS/aeros.squashfs" | cut -f1))"
}
assemble_iso() {
step "GRUB config + kernel + splash"
install -d "$ISODIR/boot/grub"
# kernel
cp -v "$LFS"/boot/vmlinuz-aeros-* "$ISODIR/boot/vmlinuz-aeros"
# grub.cfg
sed -e "s/@@ISO_LABEL@@/$AEROS_ISO_LABEL/g" \
-e "s/@@VERSION@@/$AEROS_VERSION/g" \
"$AEROS_TOP/assets/live/grub.cfg" > "$ISODIR/boot/grub/grub.cfg"
# boot splash = wallpaper
cp -v "$LFS/usr/share/backgrounds/aeros/frutiger-aero.png" \
"$ISODIR/boot/grub/aero-splash.png" 2>/dev/null || true
step "Building hybrid ISO with grub-mkrescue"
mkdir -p "$AEROS_OUT"
local OUT="$AEROS_OUT/$AEROS_ISO_NAME"
rm -f "$OUT"
# Run grub-mkrescue from inside the chroot so it uses the AeroOS grub +
# xorriso + mtools we built; bind-mount the iso tree in.
mount_vkfs
in_chroot "mkdir -p /usr/share/grub && if [ ! -s /usr/share/grub/unicode.pf2 ]; then grub-mkfont -o /usr/share/grub/unicode.pf2 /usr/share/fonts/dejavu/DejaVuSans.ttf; fi"
mkdir -p "$LFS/mnt/isobuild" "$LFS/mnt/isoout"
mount --bind "$ISODIR" "$LFS/mnt/isobuild"
mount --bind "$AEROS_OUT" "$LFS/mnt/isoout"
if ! in_chroot "set -o pipefail; grub-mkrescue -o /mnt/isoout/$AEROS_ISO_NAME /mnt/isobuild \
--volid $AEROS_ISO_LABEL 2>&1 | tail -20"; then
rm -f "$OUT"
warn "chroot grub-mkrescue failed; trying host grub-mkrescue"
fi
umount "$LFS/mnt/isobuild" 2>/dev/null || true
umount "$LFS/mnt/isoout" 2>/dev/null || true
umount_vkfs
if [[ ! -s "$OUT" ]] && command -v grub-mkrescue >/dev/null 2>&1; then
grub-mkrescue -o "$OUT" "$ISODIR" --volid "$AEROS_ISO_LABEL"
fi
[[ -s "$OUT" ]] || die "ISO build failed"
ok "ISO ready: $OUT ($(du -h "$OUT" | cut -f1))"
echo "$OUT" > "$AEROS_OUT/.last-iso"
}
mkdir -p "$ISODIR/boot/grub"
build_image_tools
make_squashfs
make_initramfs
assemble_iso
ok "live image complete"