Commit 42bb0edd authored by jan.koester's avatar jan.koester
Browse files

test

parent c3c9c851
Loading
Loading
Loading
Loading
+74 −24
Changes for build-chroot.sh: 74 added lines, 24 removed lines.
Original line number Diff line number Diff line
@@ -12,8 +12,10 @@
#   7. chroot        systempp + clang/lld/lldb + fresh + tools assembled into a rootfs
#   8. packages      FenrirOS specs (../scripts/files/rpm) built with rpmbuild in the chroot
#   8b. repo         the package repository of those RPMs (createrepo_c), for dnf5 on FenrirOS
#   9. iso           live ISO of the RPM-built system (Limine BIOS+UEFI; CD, USB stick,
#                    Ventoy compatible), needs host xorriso+mksquashfs
#   9. iso           live ISOs of the RPM-built system (Limine BIOS+UEFI; CD, USB stick,
#                    Ventoy compatible): <ISO_NAME>-server (no compilers, build tools,
#                    headers or -dev/-devel packages) and <ISO_NAME>-devel (every
#                    package built); needs host xorriso+mksquashfs
#  10. docker        container images of the RPMs: fenriros (minimal: DOCKER_MINIMAL and
#                    what it requires) and fenriros-devel (every package built)
#
@@ -48,7 +50,13 @@
#   REPO_ARCH     repository architecture    (default: x86_64; fenriros.repo's $basearch)
#   REPO_UPLOAD   rsync target the repository is copied to after the 'repo' step, e.g.
#                 host:/srv/www/fenriros (served as https://repo.tuxist.de/fenriros; default: none)
#   ISO_NAME/ISO_TITLE/ISO_VOLID/ISO_HOSTNAME  naming of the live ISO
#   ISO_NAME/ISO_TITLE/ISO_VOLID/ISO_HOSTNAME  naming of the live ISOs (the variant
#                 is appended: <ISO_NAME>-server.iso, "<ISO_TITLE> server", <ISO_VOLID>_SERVER)
#   ISO_VARIANTS  ISOs the 'iso' step builds (default: server devel)
#   ISO_DEVEL_TOOLS  packages besides *-dev, *-devel, *-headers left out of the server ISO
#                 (default: clang lld lldb llvm-project llvm-tools cmake ninja makeplus dwarves createrepo_c)
#   ISO_DEVEL_PATHS  paths not installed on the server ISO besides *.a, *.la and perl's CORE/
#                 (default: /usr/include, pkgconfig, cmake and aclocal dirs)
#   DOCKER        container tool for 'docker'  (default: docker; podman works too)
#   DOCKER_PREFIX registry/namespace prefix of the image names, e.g. registry.tuxist.de/tuxist/
#   DOCKER_TAG    image tag besides latest   (default: date, YYYYMMDD)
@@ -1021,7 +1029,8 @@ fetch_url() {
# USB sticks and the file systems an ISO file may lie on (Ventoy: exFAT,
# also NTFS, FAT, ext4), so the initramfs finds a live ISO that isn't a CD;
# the hwmon temperature sensors webctl's dashboard reads from
# /sys/class/hwmon of NVMe and SATA drives (drivetemp has no modalias).
# /sys/class/hwmon of NVMe and SATA drives (drivetemp has no modalias);
# zstd-compressed firmware (kernel.spec compresses /lib/firmware).
KERNEL_OPTIONS="SYSFB SYSFB_SIMPLEFB DRM DRM_SIMPLEDRM DRM_FBDEV_EMULATION FB FB_CORE
    FRAMEBUFFER_CONSOLE FRAMEBUFFER_CONSOLE_DETECT_PRIMARY SQUASHFS SQUASHFS_ZSTD SQUASHFS_XATTR
    SQUASHFS_FILE_DIRECT NETDEVICES ETHERNET NET_VENDOR_REALTEK PHYLIB REALTEK_PHY BLK_DEV_NVME
@@ -1035,6 +1044,7 @@ KERNEL_OPTIONS="SYSFB SYSFB_SIMPLEFB DRM DRM_SIMPLEDRM DRM_FBDEV_EMULATION FB FB
    BPF_JIT_ALWAYS_ON XDP_SOCKETS BPF_STREAM_PARSER
    FUNCTION_TRACER DYNAMIC_FTRACE FTRACE_SYSCALLS BPF_LSM IKHEADERS
    NVME_HWMON SENSORS_DRIVETEMP
    FW_LOADER_COMPRESS FW_LOADER_COMPRESS_ZSTD
    USB_STORAGE USB_UAS EXFAT_FS NTFS3_FS FAT_FS VFAT_FS NLS NLS_CODEPAGE_437 NLS_ISO8859_1 NLS_UTF8"
# DEBUG_INFO_BTF needs DWARF (pahole turns it into BTF): DWARF5 replaces
# defconfig's DEBUG_INFO_NONE in that choice
@@ -1417,6 +1427,14 @@ step_repo() {

# every RPM a bootable system can't do without
ISO_REQUIRED="systempp fresh syslite kernel limine"
# server: every package except development ones -- *-dev, *-devel and
# *-headers, and the compilers/build tools of ISO_DEVEL_TOOLS -- and without
# the headers, static libraries and pkg-config/cmake files of the packages
# that have no -dev subpackage (ISO_DEVEL_PATHS, plus every *.a and *.la);
# devel: all
ISO_VARIANTS="${ISO_VARIANTS:-server devel}"
ISO_DEVEL_TOOLS="${ISO_DEVEL_TOOLS:-clang lld lldb llvm-project llvm-tools cmake ninja makeplus dwarves createrepo_c}"
ISO_DEVEL_PATHS="${ISO_DEVEL_PATHS:-/usr/include /usr/lib/pkgconfig /usr/share/pkgconfig /usr/lib/cmake /usr/share/cmake /usr/share/aclocal}"

# newest_rpms <list> -- the newest build of each package in RPMS/, one
# chroot path per line, into $CHROOT/build/rpmbuild/<list>: after a version
@@ -1435,10 +1453,12 @@ newest_rpms() {
    [[ -s $list ]] || die "no RPMs in /build/repo/x86_64/Packages"
}

# install_rpm_root <log> <root> <list> -- a fresh merged-/usr system root at
# $CHROOT<root> with the RPMs of $CHROOT/build/rpmbuild/<list> installed
# install_rpm_root <log> <root> <list> [<excludes>] -- a fresh merged-/usr
# system root at $CHROOT<root> with the RPMs of $CHROOT/build/rpmbuild/<list>
# installed, without the paths of rpmbuild/<excludes> (rpm --excludepath:
# the database marks them "not installed", so rpm -V stays clean)
install_rpm_root() {
    local log="$1" root="$2" list="$3"
    local log="$1" root="$2" list="$3" excl="${4:-}"
    rm -rf --one-file-system "${CHROOT:?}${root:?}"
    mkdir -p "$CHROOT$root/usr/bin" "$CHROOT$root/usr/sbin" "$CHROOT$root/usr/lib"
    ln -s usr/bin  "$CHROOT$root/bin"
@@ -1447,31 +1467,63 @@ install_rpm_root() {
    ln -s usr/lib  "$CHROOT$root/lib64"
    setup_merged_usr "$CHROOT$root"
    run "$log" in_chroot rpm --root "$root" --initdb
    run "$log" in_chroot /bin/sh -c 'rpm -ivh --nodeps --force --root "$1" $(cat "$2")' \
        sh "$root" "/build/rpmbuild/$list"
    run "$log" in_chroot /bin/sh -c 'x=; [ -z "$3" ] || x=$(sed "s/^/--excludepath=/" "$3")
            rpm -ivh --nodeps --force --root "$1" $x $(cat "$2")' \
        sh "$root" "/build/rpmbuild/$list" "${excl:+/build/rpmbuild/$excl}"
    mkdir -p "$CHROOT$root"/{dev,proc,sys,run,tmp,root,home,mnt,var/tmp,var/log}
    [[ -e $CHROOT$root/var/run ]] || ln -s ../run "$CHROOT$root/var/run"
    chmod 1777 "$CHROOT$root/tmp" "$CHROOT$root/var/tmp"
}

step_iso() {
    local t
    local t v
    for t in mksquashfs xorriso; do
        command -v "$t" >/dev/null || die "'$t' missing on the host (Fedora: sudo dnf install squashfs-tools xorriso)"
    done
    local rpmdir="$CHROOT/build/rpmbuild/RPMS" root="$CHROOT/build/iso-root" iso="$WORK/iso"
    local out="$WORK/$ISO_NAME.iso" p
    local rpmdir="$CHROOT/build/rpmbuild/RPMS" p
    for p in $ISO_REQUIRED; do
        compgen -G "$rpmdir/*/$p-[0-9]*.rpm" >/dev/null || die "no $p RPM -- build it with the 'packages' step first"
    done
    for v in $ISO_VARIANTS; do
        case $v in server|devel) ;; *) die "unknown ISO variant '$v' (ISO_VARIANTS: server devel)" ;; esac
    done
    fetch_git "$WORK/src/limine" https://github.com/limine-bootloader/limine.git "$LIMINE_REF"
    run iso "$HOST_CC" -O2 -std=c99 -o "$BUILD/limine-host" "$WORK/src/limine/limine.c"

    newest_rpms iso-rpms
    for v in $ISO_VARIANTS; do iso_image "$v"; done
}

# iso_image <server|devel> -- $WORK/<ISO_NAME>-<variant>.iso
iso_image() {
    local v="$1" d="$CHROOT/build/rpmbuild" p
    local root="$CHROOT/build/iso-root-$v" iso="$WORK/iso-$v" out="$WORK/$ISO_NAME-$v.iso"
    local title="$ISO_TITLE $v" volid="${ISO_VOLID}_${v^^}"

    if [[ $v = server ]]; then
        # iso-candidates: "name evr path" of every RPM, iso-rpms the newest paths
        awk -v ex=" $ISO_DEVEL_TOOLS " 'NR == FNR { keep[$1]; next }
            ($3 in keep) && $1 !~ /-(dev|devel|headers)$/ && index(ex, " " $1 " ") == 0 { print $3 }' \
            "$d/iso-rpms" "$d/iso-candidates" >"$d/iso-rpms-$v"
        for p in $ISO_REQUIRED; do
            grep -q "/$p-[0-9][^/]*\.rpm$" "$d/iso-rpms-$v" || die "iso: $p filtered out of the server ISO -- check ISO_DEVEL_TOOLS"
        done
        # perl's CORE/ (headers + libperl.a for XS modules) is a directory
        { printf '%s\n' $ISO_DEVEL_PATHS
          in_chroot /bin/sh -c 'rpm -qpl $(cat "$1") 2>/dev/null' sh "/build/rpmbuild/iso-rpms-$v" |
              grep -E '\.l?a$|/perl5/.*/CORE$'
        } | sort -u >"$d/iso-exclude-$v"
    else
        cp "$d/iso-rpms" "$d/iso-rpms-$v"
        : >"$d/iso-exclude-$v"
    fi

    msg "iso: installing the RPMs into the image root"
    msg "iso $v: installing $(wc -l <"$d/iso-rpms-$v") RPMs into the image root"
    rm -rf --one-file-system "${iso:?}"
    mkdir -p "$iso/boot/limine" "$iso/EFI/BOOT"
    newest_rpms iso-rpms
    install_rpm_root iso /build/iso-root iso-rpms
    install_rpm_root iso "/build/iso-root-$v" "iso-rpms-$v" "iso-exclude-$v"

    msg "iso: configuring the system"
    msg "iso $v: configuring the system"
    write_system_config "$root" "$ISO_HOSTNAME"
    # the live system: DHCP on every interface (sshd, webctl and the
    # installer's downloads need the network). A catch-all the installer's
@@ -1489,7 +1541,7 @@ EOF
    [[ -x $root/usr/sbin/syslite ]] || die "no /usr/sbin/syslite in the image"
    [[ -s $root/boot/vmlinuz && -s $root/boot/initramfs.zst ]] || die "kernel RPM without /boot/vmlinuz or /boot/initramfs.zst"

    msg "iso: filesystem.squashfs"
    msg "iso $v: filesystem.squashfs"
    run iso mksquashfs "$root" "$iso/boot/filesystem.squashfs" -comp zstd -noappend -all-root -no-progress

    # Limine: the images from the limine RPM, its config, and a host build
@@ -1515,30 +1567,28 @@ EOF
    cat >"$iso/boot/limine/limine.conf" <<EOF
timeout: 3

/$ISO_TITLE
/$title
    protocol: linux
    kernel_path: boot():/boot/vmlinuz
    module_path: boot():/boot/initramfs.zst
    cmdline: console=ttyS0,115200 console=tty0 loglevel=4 fenriros.id=$id

/$ISO_TITLE (verbose)
/$title (verbose)
    protocol: linux
    kernel_path: boot():/boot/vmlinuz
    module_path: boot():/boot/initramfs.zst
    cmdline: console=ttyS0,115200 console=tty0 loglevel=7 fenriros.id=$id
EOF
    fetch_git "$WORK/src/limine" https://github.com/limine-bootloader/limine.git "$LIMINE_REF"
    run iso "$HOST_CC" -O2 -std=c99 -o "$BUILD/limine-host" "$WORK/src/limine/limine.c"

    msg "iso: mastering $out"
    msg "iso $v: mastering $out"
    run iso xorriso -as mkisofs -R -r -J \
        -b boot/limine/limine-bios-cd.bin -no-emul-boot -boot-load-size 4 -boot-info-table \
        --efi-boot boot/limine/limine-uefi-cd.bin -efi-boot-part --efi-boot-image --protective-msdos-label \
        -volid "$ISO_VOLID" "$iso" -o "$out"
        -volid "$volid" "$iso" -o "$out"
    # BIOS from a USB stick (dd): stage 1 in the MBR of the hybrid image;
    # from CD it is El Torito (limine-bios-cd.bin), UEFI EFI/BOOT/BOOTX64.EFI
    run iso "$BUILD/limine-host" bios-install "$out"
    msg "iso ready: $out ($(du -h "$out" | cut -f1), id $id): BIOS + UEFI, CD, USB (dd) and Ventoy; root login without password"
    msg "iso $v ready: $out ($(du -h "$out" | cut -f1), id $id): BIOS + UEFI, CD, USB (dd) and Ventoy; root login without password"
}

# ---------------------------------------------------------------------------