Files

68 lines
2.8 KiB
Bash

#!/bin/bash
# Rebuild the new Acronis images so that the BIOS (grub-pc) boot works:
# the modules must be present on the ISO, otherwise GRUB drops to rescue.
set -e
SRC=/path/to/pf/acronis/Acronis_Boot_Disk_2024.iso
OUT=/path/to/pf/acronis/new
W=/root/new2
rm -rf "$W"; mkdir -p "$W" "$OUT"
apt-get install -y grub-pc-bin grub-efi-amd64-bin grub-efi-ia32-bin mtools xorriso >/tmp/apt6.log 2>&1 || true
build_one() {
local name="$1" dir="$2" kernel="$3" initrds="$4"
local tree="$W/$name"
mkdir -p "$tree/$dir" "$tree/boot/grub/i386-pc"
echo "=== $name ($dir)"
7z e -y -o"$tree/$dir" "$SRC" "ACR/$dir/$kernel" $(for i in $initrds; do echo "ACR/$dir/$i"; done) >/dev/null
# BIOS menu
cat > "$tree/boot/grub/grub.cfg" <<EOF
set timeout=0
set default=0
menuentry "Acronis" {
linux /$dir/$kernel vga=791 mbrcrcs=on force_modules=usbhid lang=ru quiet
initrd $(for i in $initrds; do echo -n "/$dir/$i "; done)
}
EOF
# grub-pc modules must be on the media
cp -f /usr/lib/grub/i386-pc/*.mod /usr/lib/grub/i386-pc/*.lst "$tree/boot/grub/i386-pc/" 2>/dev/null || true
# BIOS El Torito image
grub-mkrescue -o "$W/$name.base.iso" "$tree" >/tmp/mk2_$name.log 2>&1
xorriso -osirrox on -indev "$W/$name.base.iso" \
-extract /boot/grub/i386-pc/eltorito.img "$tree/boot/grub/i386-pc/eltorito.img" >/dev/null 2>&1
# UEFI image: our x64 GRUB (standalone, embedded config) — only used if someone
# boots the ISO straight from firmware; our menu uses loopback instead.
cat > "$W/$name.efi.cfg" <<EOF
search --no-floppy --set=root --file /$dir/$kernel
linux /$dir/$kernel vga=791 mbrcrcs=on force_modules=usbhid lang=ru quiet
initrd $(for i in $initrds; do echo -n "/$dir/$i "; done)
boot
EOF
grub-mkimage -O x86_64-efi -o "$W/BOOTX64.EFI" -p /boot/grub -d /usr/lib/grub/x86_64-efi \
-c "$W/$name.efi.cfg" linux normal iso9660 search search_label search_fs_file part_msdos echo test
dd if=/dev/zero of="$tree/efi.img" bs=1k count=2048 status=none
mkfs.vfat -F 12 -n EFI "$tree/efi.img" >/dev/null
mmd -i "$tree/efi.img" ::/EFI ::/EFI/BOOT
mcopy -i "$tree/efi.img" "$W/BOOTX64.EFI" ::/EFI/BOOT/BOOTX64.EFI
mkdir -p "$tree/EFI/BOOT"
cp -f "$W/BOOTX64.EFI" "$tree/EFI/BOOT/BOOTX64.EFI"
xorriso -as mkisofs -R -J -joliet-long -V PARAVIS_ACRONIS -o "$OUT/$name.iso" \
-b boot/grub/i386-pc/eltorito.img -no-emul-boot -boot-load-size 4 -boot-info-table \
-eltorito-alt-boot -e efi.img -no-emul-boot \
"$tree" >/tmp/xor2_$name.log 2>&1
printf " -> %s: %s MB\n" "$name" "$(( $(stat -c %s "$OUT/$name.iso") / 1048576 ))"
printf " modules in ISO: "
7z l -ba "$OUT/$name.iso" 2>/dev/null | grep -c 'boot/grub/i386-pc/.*\.mod' || true
}
build_one ADD ATI2025 dat10.dat "dat11.dat dat12.dat"
build_one ABA ADDH12 dat14.dat "dat15.dat dat16.dat"
ls -l "$OUT"