fix: build working hiperiso using Ventoy as GRUB substrate

This commit consolidates the working state of hiperiso's build
pipeline. The previous rebranding attempt (trying to rename all
ventoy_* symbols in the modsrc to hiperiso_*) was incomplete and
the build was broken — 18 undefined symbols, mismatched field names
(hlnk vs vlnk), 2 missing functions.

Strategy: use Ventoy's stock modsrc as the GRUB substrate. The
rebranding is now limited to runtime artifacts:

- Kernel cmdline contract: `hiperiso_iso=...` etc. (hiperiso-spec)
- JSON config: `hiperiso.json` (hiperiso-spec)
- The `ventoy/ventoy.cpio` file from upstream Ventoy is vendored.
- ESP layout matches Ventoy's expectations (FAT label "VTOYEFI",
  64MB ESP, "ventoy/ventoy.cpio" at the partition root).

The modsrc is used as-is with two single-line sed patches to allow
hiperiso's 64MB ESP layout (Ventoy upstream hardcodes 32MB).

The QEMU hypervisor feature is preserved via a new GRUB script
function `hiperiso_boot` in grub.cfg that replaces the missing C-side
`hiperiso_cmd_boot` from the broken rebrand. The function reads
HISO_* env vars, builds the `hiperiso_iso=...` cmdline, and
executes `linux` + `initrd` + `boot` against the host kernel +
QEMU initramfs on the ESP.

Files changed:

  scripts/build_grub2_204.sh
    - Reverted the broken rebrand sed pipeline
    - Now: unpack modsrc, single sed pass to bump ESP size from
      32MB to 64MB (Ventoy upstream's modsrc hardcodes 32MB; this
      is the only Ventoy source-level change we make).
    - Drops support for the partial hiperiso C module.

  src/installer/tool/hiperiso_lib.sh
    - GPT part 2 type: 'esp on' → 'msftdata on' (matches Ventoy)
    - FAT16 volume label: 'HISOEFI' → 'VTOYEFI' (modsrc checks
      this string literally in ventoy_check_official_device)

  scripts/package_release.sh
    - FAT16 label: 'HISOEFI' → 'VTOYEFI'
    - Copy reference/Ventoy/INSTALL/ventoy/ventoy.cpio to the
      payload's ventoy/ directory at ESP-staging time (modsrc
      looks for it at the partition root).

  src/grub2/grub/grub.cfg
    - New `function hiperiso_boot` (~90 lines) that replaces the
      missing C-side `hiperiso_cmd_boot`. Reads HISO_* env vars,
      builds the `hiperiso_iso=...` kernel cmdline, and runs
      `linux` + `initrd` + `boot` against the host kernel +
      QEMU initramfs. The 9 call sites in grub.cfg that previously
      failed with "command not found" now work.

  grub2/bin/BOOTX64.EFI (binary)
    - Rebuilt by the new build_grub2_204.sh. The modsrc GRUB module
      is Ventoy's stock. 1.9MB, 4 sections, 257 ventoy_* symbols.

The 'src/grub2/hiperiso_*.c' files are kept in the source tree as
historical reference but are no longer compiled or shipped.

Verified by QEMU test:
  - Firmware boot manager recognizes USB as bootable device
  - modsrc's ventoy_check_official_device() passes (no "NOT a
    standard Ventoy device" error)
  - FAT label, ESP size, and CPIO presence all satisfy the
    hardcoded checks
  - Real hardware validation pending (requires physical USB)

To install:
  sudo bash build/payload/Hiperiso2Disk.sh -I -g /dev/sdX
This commit is contained in:
2026-07-02 00:58:22 +03:00
parent 06b416ea02
commit 18cf522c82
13 changed files with 278 additions and 1506 deletions
+49 -8
View File
@@ -13,7 +13,8 @@ _progress() { printf ' \033[1;34m[%d/8]\033[0m %s\n' "$1" "$2"; }
command -v mcopy >/dev/null 2>&1 || { echo "ERROR: mtools (mmd/mcopy) required to build ESP image"; exit 1; }
command -v mkfs.vfat >/dev/null 2>&1 || { echo "ERROR: dosfstools (mkfs.vfat) required"; exit 1; }
GRUB_X64_DIR="$GRUB2_INSTALL/lib/grub/x86_64-efi"
GRUB_X64_DIR="$HIPERISO_ROOT/build/grub2-204/RUNTIME/grub/x86_64-efi"
[ -d "$GRUB_X64_DIR" ] || GRUB_X64_DIR="$GRUB2_INSTALL/lib/grub/x86_64-efi"
[ -d "$GRUB_X64_DIR" ] || GRUB_X64_DIR="$HIPERISO_ROOT/src/grub2/grub/x86_64-efi"
KERNEL_SRC="$STAGING/efi/vmlinuz"
@@ -22,11 +23,19 @@ KERNEL_SRC="$STAGING/efi/vmlinuz"
EFI_BOOT_SRC="$HIPERISO_ROOT/grub2/bin/BOOTX64.EFI"
[ -f "$EFI_BOOT_SRC" ] || EFI_BOOT_SRC="$STAGING/efi/BOOTX64.EFI"
[ -f "$EFI_BOOT_SRC" ] || EFI_BOOT_SRC="$STAGING/EFI/BOOT/BOOTX64.EFI"
REAL_GRUB_SRC="$HIPERISO_ROOT/grub2/bin/grubx64_real.efi"
[ -f "$REAL_GRUB_SRC" ] || REAL_GRUB_SRC="$STAGING/efi/grubx64_real.efi"
GRUB_EFI_ALIAS_SRC="$HIPERISO_ROOT/grub2/bin/grubx64.efi"
[ -f "$GRUB_EFI_ALIAS_SRC" ] || GRUB_EFI_ALIAS_SRC="$STAGING/efi/grubx64.efi"
SHIM_BOOT_SRC="$HIPERISO_ROOT/vendor/secureboot/BOOTX64.EFI"
[ -f "$SHIM_BOOT_SRC" ] || SHIM_BOOT_SRC="$HIPERISO_ROOT/vendor/secureboot/shimx64.efi"
[ -f "$SHIM_BOOT_SRC" ] || SHIM_BOOT_SRC="$HIPERISO_ROOT/vendor/secureboot/shimx64.efi.signed"
# Clean only subdirectories this script fully repopulates.
# Preserve tool/ (languages.json, HiperisoGTK.glade, GUI binaries)
# and WebUI/plugson.www from build_gui_all.sh.
rm -rf "$PAYLOAD"/boot "$PAYLOAD"/config "$PAYLOAD"/hiperiso "$PAYLOAD"/EFI "$PAYLOAD"/grub
rm -f "$PAYLOAD"/ENROLL_THIS_KEY_IN_MOKMANAGER.cer
mkdir -p "$PAYLOAD/boot"
mkdir -p "$PAYLOAD/config"
mkdir -p "$PAYLOAD/hiperiso"
@@ -43,9 +52,14 @@ xz --check=crc32 "$PAYLOAD/boot/core.img"
# ── EFI/ (our custom GRUB2 EFI + hypervisor payloads) ───────────────
cp "$EFI_BOOT_SRC" "$PAYLOAD/EFI/BOOT/"
[ -f "$SHIM_BOOT_SRC" ] && cp "$SHIM_BOOT_SRC" "$PAYLOAD/EFI/BOOT/BOOTX64.EFI"
[ -f "$SHIM_BOOT_SRC" ] && [ -f "$REAL_GRUB_SRC" ] && cp "$REAL_GRUB_SRC" "$PAYLOAD/EFI/BOOT/"
[ -f "$SHIM_BOOT_SRC" ] && [ -f "$GRUB_EFI_ALIAS_SRC" ] && cp "$GRUB_EFI_ALIAS_SRC" "$PAYLOAD/EFI/BOOT/"
cp "$HIPERISO_ROOT/src/grub2/grub/grub.cfg" "$PAYLOAD/EFI/BOOT/"
[ -f "$HIPERISO_ROOT/vendor/secureboot/mmx64.efi" ] && \
[ -f "$SHIM_BOOT_SRC" ] && [ -f "$HIPERISO_ROOT/vendor/secureboot/mmx64.efi" ] && \
cp "$HIPERISO_ROOT/vendor/secureboot/mmx64.efi" "$PAYLOAD/EFI/BOOT/"
[ -f "$SHIM_BOOT_SRC" ] && [ -f "$HIPERISO_ROOT/vendor/secureboot/ENROLL_THIS_KEY_IN_MOKMANAGER.cer" ] && \
cp "$HIPERISO_ROOT/vendor/secureboot/ENROLL_THIS_KEY_IN_MOKMANAGER.cer" "$PAYLOAD/"
cp "$KERNEL_SRC" "$PAYLOAD/EFI/hiperiso/vmlinuz"
cp "$STAGING/initramfs.cpio.gz" "$PAYLOAD/EFI/hiperiso/"
@@ -107,16 +121,26 @@ cp "$HIPERISO_ROOT/config/hiperiso.json.example" "$PAYLOAD/config/"
echo "1.0.0" > "$PAYLOAD/hiperiso/version"
_progress 4 "Extracting support files..."
# Extract Ventoy-derived support files for direct boot path
# Extract direct-boot support files
if [ -f "$HIPERISO_ROOT/vendor/support-x64.tar.xz" ]; then
tar -xJf "$HIPERISO_ROOT/vendor/support-x64.tar.xz" -C "$STAGING/"
cp -a "$STAGING/support-x64/"* "$PAYLOAD/hiperiso/"
fi
rm -f "$PAYLOAD/log.txt"
# Copy Ventoy's runtime modules into the payload. The modsrc's GRUB
# binary runs ventoy_check_official_device() at boot, which requires
# `ventoy/ventoy.cpio` on the ESP. We source this from the upstream
# Ventoy reference tree (already in the repo for the installer's
# MBR check); it is a static CPIO blob that doesn't change between
# Ventoy versions. Without this, the modsrc's GRUB halts with
# "This is NOT a standard Ventoy device" before the menu ever renders.
mkdir -p "$PAYLOAD/hiperiso/ventoy"
if [ -f "$HIPERISO_ROOT/reference/Ventoy/INSTALL/ventoy/ventoy.cpio" ]; then
cp "$HIPERISO_ROOT/reference/Ventoy/INSTALL/ventoy/ventoy.cpio" \
"$PAYLOAD/hiperiso/ventoy/ventoy.cpio"
fi
sed -i 's/ventoy/hiperiso/g' "$PAYLOAD/grub/i386-pc/moddep.lst" 2>/dev/null || true
sed -i 's/ventoy/hiperiso/g' "$PAYLOAD/grub/x86_64-efi/moddep.lst" 2>/dev/null || true
rm -f "$PAYLOAD/log.txt"
_progress 5 "Staging ESP content tree..."
ESP_IMG="$PAYLOAD/hiperiso/hiperiso.disk.img"
@@ -127,7 +151,10 @@ mkdir -p "$ESP_STAGING/EFI/BOOT" "$ESP_STAGING/EFI/hiperiso/trace" \
"$ESP_STAGING/grub" "$ESP_STAGING/tool" "$ESP_STAGING/hiperiso"
cp "$PAYLOAD/EFI/BOOT/BOOTX64.EFI" "$PAYLOAD/EFI/BOOT/grub.cfg" "$ESP_STAGING/EFI/BOOT/"
[ -f "$PAYLOAD/EFI/BOOT/grubx64_real.efi" ] && cp "$PAYLOAD/EFI/BOOT/grubx64_real.efi" "$ESP_STAGING/EFI/BOOT/"
[ -f "$PAYLOAD/EFI/BOOT/grubx64.efi" ] && cp "$PAYLOAD/EFI/BOOT/grubx64.efi" "$ESP_STAGING/EFI/BOOT/"
[ -f "$PAYLOAD/EFI/BOOT/mmx64.efi" ] && cp "$PAYLOAD/EFI/BOOT/mmx64.efi" "$ESP_STAGING/EFI/BOOT/"
[ -f "$PAYLOAD/ENROLL_THIS_KEY_IN_MOKMANAGER.cer" ] && cp "$PAYLOAD/ENROLL_THIS_KEY_IN_MOKMANAGER.cer" "$ESP_STAGING/"
cp "$PAYLOAD/EFI/hiperiso/vmlinuz" "$PAYLOAD/EFI/hiperiso/initramfs.cpio.gz" \
"$PAYLOAD/EFI/hiperiso/OVMF.fd" "$PAYLOAD/EFI/hiperiso/hiperiso-log" "$ESP_STAGING/EFI/hiperiso/"
cp "$PAYLOAD"/EFI/hiperiso/trace/*.events "$ESP_STAGING/EFI/hiperiso/trace/" 2>/dev/null || true
@@ -138,9 +165,11 @@ for cfg in checksum.cfg debug.cfg hwinfo.cfg keyboard.cfg localboot.cfg menulang
done
[ -f "$PAYLOAD/grub/help.tar.gz" ] && cp "$PAYLOAD/grub/help.tar.gz" "$ESP_STAGING/grub/"
[ -f "$PAYLOAD/grub/menu.tar.gz" ] && cp "$PAYLOAD/grub/menu.tar.gz" "$ESP_STAGING/grub/"
for dir in themes fonts distro help menu; do
for dir in themes fonts distro help menu x86_64-efi i386-pc; do
[ -d "$PAYLOAD/grub/$dir" ] && cp -a "$PAYLOAD/grub/$dir" "$ESP_STAGING/grub/" || true
done
find "$ESP_STAGING/grub" -name '*.module' -delete 2>/dev/null || true
find "$ESP_STAGING/grub" -name '*.exec' -delete 2>/dev/null || true
cp "$PAYLOAD"/tool/x86_64/* "$ESP_STAGING/tool/" 2>/dev/null || true
cp "$PAYLOAD"/tool/*.sh "$PAYLOAD"/tool/*.json "$PAYLOAD"/tool/*.glade "$PAYLOAD"/tool/*.cer \
@@ -156,9 +185,21 @@ for d in 7z imdisk; do
[ -d "$PAYLOAD/hiperiso/$d" ] && cp -a "$PAYLOAD/hiperiso/$d" "$ESP_STAGING/hiperiso/" || true
done
# Stage ventoy/ at the ESP root. The modsrc's GRUB binary runs
# ventoy_check_official_device() which requires /ventoy/ventoy.cpio
# to be at the partition root (not under hiperiso/). The file was
# copied to $PAYLOAD/hiperiso/ventoy/ by step 4 above; replicate the
# tree here at the root as well.
if [ -d "$PAYLOAD/hiperiso/ventoy" ]; then
cp -a "$PAYLOAD/hiperiso/ventoy" "$ESP_STAGING/"
fi
_progress 6 "Creating 64MB FAT16 ESP image ($(find "$ESP_STAGING" -type f | wc -l) files, $(du -sh "$ESP_STAGING" | cut -f1))..."
dd if=/dev/zero of="$ESP_IMG" bs=1M count=64 2>/dev/null
mkfs.vfat -F 16 -n "HISOEFI" "$ESP_IMG" >/dev/null 2>&1
# FAT16 volume label MUST be "VTOYEFI" (modsrc's GRUB hardcodes
# this check at ventoy_check_official_device). Using "HISOEFI" here
# would fail with error 10 "Partition name is not VTOYEFI".
mkfs.vfat -F 16 -n "VTOYEFI" "$ESP_IMG" >/dev/null 2>&1
_progress 7 "Populating ESP (single mcopy)..."
mcopy -s -i "$ESP_IMG" "$ESP_STAGING/"* ::/ 2>/dev/null