Files
hiperiso/scripts/build_grub2_212.sh
T
vasilito 1931a250b3 GRUB 2.12 port — Ventoy compat layer, EFI kernel, install/update targets
Build system:
- Switch from GRUB 2.04 → 2.12 with Ventoy module via build_grub2_212.sh
- New patch_ventoy_212.py: compat typedefs, mem: protocol, VTOY_CMD_CHECK bypass
- Fix EFI libstub compile with GCC 16 (cflags -std=gnu11 on X86_64)
- Disable busybox CONFIG_TC (broken with modern kernel headers)
- New Makefile targets: install, update, rebuild (single-command USB deploy)

GRUB 2.12 compat fixes:
- Add grub_mem_fs with fs_read/fs_close to kern/file.c (mem: protocol)
- Bypass ventoy_check_official_device (hiperiso lacks ventoy.cpio on ESP)
- Disable VTOY_CMD_CHECK anti-tamper (ESP size != 33554432)

Kernel (hiperiso_defconfig):
- Enable CONFIG_EFI, CONFIG_EFI_STUB, CONFIG_FB_EFI (fixes black screen boot)
- Add CONFIG_FONT_SUPPORT, CONFIG_FONT_8x16

grub.cfg:
- Theme path: try themes/hiperiso/ then themes/ventoy/ (path mismatch fix)
- Kernel cmdline: add console=tty0 console=ttyS0 ignore_loglevel earlyprintk=efi
- Restore ventoy_* function names (matching modsrc binary)
2026-07-03 10:42:35 +03:00

119 lines
4.8 KiB
Bash
Executable File

#!/bin/sh
# build_grub2_212.sh — Build GRUB2 2.12 with Ventoy module for hiperiso.
#
# GRUB 2.12 has the "alloc magic is broken" heap corruption fix built-in.
# The Ventoy module is compiled against stock GRUB 2.12 using a compat layer
# (ventoy_def.h additions + ventoy_compat.c) that provides:
# - Typedefs for renamed types (grub_efi_guid_t → grub_guid_t)
# - Missing struct fields (vlnk, dirhook size, gpt_attrib)
# - Working EFI allocation functions (iso_buf, chain_buf)
# - Stubs for patched-core functions (fs chunks, blocklist, vlnk)
# - 3-arg grub_efi_get_variable wrapper (2.12 changed to 4-arg)
#
# Menu display, ISO enumeration, and linux/initrd (hypervisor mode) all work.
# ISO chainloading requires the stubbed fs/*.c functions — not yet ported.
#
# Usage: scripts/build_grub2_212.sh
# Output: grub2/bin/BOOTX64.EFI, grub2/bin/grubx64_real.efi, grub2/bin/grubx64.efi
set -eu
(set -o pipefail) 2>/dev/null && set -o pipefail
HIPERISO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
DL_DIR="$HIPERISO_ROOT/build/downloads"
MODULE_TARBALL="$HIPERISO_ROOT/vendor/grub2-modsrc.tar.xz"
BUILD_DIR="$HIPERISO_ROOT/build/grub2-212"
SRC_DIR="$BUILD_DIR/SRC/grub-2.12"
rm -rf "$BUILD_DIR"
mkdir -p "$BUILD_DIR/SRC"
if [ ! -f "$DL_DIR/grub-2.12.tar.xz" ]; then
echo ">>> Downloading GRUB 2.12..."
mkdir -p "$DL_DIR"
wget -O "$DL_DIR/grub-2.12.tar.xz" \
"https://ftp.gnu.org/gnu/grub/grub-2.12.tar.xz"
fi
echo ">>> Extracting GRUB 2.12..."
tar -xf "$DL_DIR/grub-2.12.tar.xz" -C "$BUILD_DIR/SRC/"
echo ">>> Copying Ventoy source files..."
mkdir -p "$SRC_DIR/grub-core/ventoy"
tar -xf "$MODULE_TARBALL" -C "$BUILD_DIR/SRC/"
# Copy ventoy source files from modsrc (2.04) into 2.12 tree
cp "$BUILD_DIR/SRC/grub-2.04/grub-core/ventoy/"*.c "$SRC_DIR/grub-core/ventoy/" 2>/dev/null || true
cp "$BUILD_DIR/SRC/grub-2.04/grub-core/ventoy/"*.h "$SRC_DIR/grub-core/ventoy/" 2>/dev/null || true
cp "$BUILD_DIR/SRC/grub-2.04/include/grub/ventoy.h" "$SRC_DIR/include/grub/" 2>/dev/null || true
# Apply hiperiso branding
find "$SRC_DIR/grub-core/ventoy" -type f \
\( -name '*.c' -o -name '*.h' \) -exec sed -i \
-e 's|(partition->len != 131072)|(partition->len != 65536)|g' \
-e 's|https://www\.ventoy\.net|https://redbearos.org/hiperiso|g' \
-e 's|www\.ventoy\.net|redbearos.org|g' \
-e 's|admin@ventoy\.net|adminpupkin@gmail.com|g' \
-e 's|longpanda|vasilito|g' \
-e 's|to use Ventoy|to use Hiperiso|g' \
-e 's|Ventoy grub is not launched by Ventoy shim|Hiperiso grub is not launched by Hiperiso shim|g' \
-e 's|standard Ventoy device|standard Hiperiso device|g' \
-e 's| Ventoy scanning files| Hiperiso scanning files|g' \
-e 's|Ventoy Secure Policy|Hiperiso Secure Policy|g' \
-e 's|grub_printf("ventoy not ready|grub_printf("hiperiso not ready|g' \
{} +
echo ">>> Applying Ventoy compatibility patches..."
python3 "$HIPERISO_ROOT/scripts/patch_ventoy_212.py" "$SRC_DIR"
echo ">>> Copying grub.cfg..."
cp "$HIPERISO_ROOT/src/grub2/grub/grub.cfg" "$SRC_DIR/grub-core/ventoy/grub.cfg"
echo ">>> Building GRUB 2.12..."
cd "$SRC_DIR"
./autogen.sh
./configure --with-platform=efi --target=x86_64 \
--prefix="$BUILD_DIR/INSTALL/" --disable-werror \
CFLAGS="-std=gnu99 -Wno-error" HOST_CFLAGS="-std=gnu99 -Wno-error"
touch grub-core/extra_deps.lst
make -j"$(nproc)"
INSTALL_DIR="$BUILD_DIR/INSTALL"
GRUB_LIB="$SRC_DIR/grub-core"
EFI_OUTPUT_DIR="$HIPERISO_ROOT/grub2/bin"
EFI_OUTPUT="$EFI_OUTPUT_DIR/BOOTX64.EFI"
REAL_GRUB_OUTPUT="$EFI_OUTPUT_DIR/grubx64_real.efi"
GRUB_ALIAS_OUTPUT="$EFI_OUTPUT_DIR/grubx64.efi"
mkdir -p "$EFI_OUTPUT_DIR"
echo ">>> Building BOOTX64.EFI with Ventoy module..."
NET_MODULES="efinet net tftp http"
MODULES="file blocklist ventoy test true regexp newc search \
at_keyboard usb_keyboard gcry_md5 hashsum gzio xzio lzopio \
ext2 xfs read halt sleep serial terminfo png password_pbkdf2 \
gcry_sha512 pbkdf2 part_gpt part_msdos ls tar squash4 loopback \
part_apple minicmd diskfilter linux relocator jpeg iso9660 udf \
hfsplus halt acpi mmap gfxmenu video_colors trig bitmap_scale \
gfxterm bitmap font fat exfat ntfs fshelp efifwsetup reboot echo \
configfile normal terminal gettext chain priority_queue bufio \
datetime cat extcmd crypto boot all_video efi_gop efi_uga \
video_bochs video_cirrus video video_fb gfxterm_background \
gfxterm_menu smbios zfs"
ALL_MODULES="$NET_MODULES $MODULES"
PATH="$SRC_DIR:$PATH" \
"$SRC_DIR/grub-mkimage" \
--directory "$GRUB_LIB" \
--prefix '(,2)/grub' \
--output "$EFI_OUTPUT" \
--format 'x86_64-efi' \
--compression 'auto' \
$ALL_MODULES
cp "$EFI_OUTPUT" "$REAL_GRUB_OUTPUT"
cp "$EFI_OUTPUT" "$GRUB_ALIAS_OUTPUT"
echo ">>> Built: $EFI_OUTPUT ($(du -h "$EFI_OUTPUT" | cut -f1))"
echo ">>> GRUB version: 2.12 (Ventoy compat layer)"
echo ">>> Ventoy module: $(strings "$EFI_OUTPUT" | grep -c 'ventoy_') ventoy_* symbols"