build_img.sh 834 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env bash
  2. # This script builds a bootable image. It bundles the test binary into a GRUB
  3. # installation. The GRUB installation is configured to chainload the binary
  4. # via Multiboot2.
  5. # http://redsymbol.net/articles/unofficial-bash-strict-mode/
  6. set -euo pipefail
  7. IFS=$'\n\t'
  8. DIR=$(dirname "$(realpath "$0")")
  9. cd "$DIR" || exit
  10. MULTIBOOT2_PAYLOAD_DIR="../../bins"
  11. MULTIBOOT2_PAYLOAD_PATH="$MULTIBOOT2_PAYLOAD_DIR/target/x86-unknown-none/release/multiboot2_payload"
  12. echo "Verifying that the binary is a multiboot2 binary..."
  13. grub-file --is-x86-multiboot2 "$MULTIBOOT2_PAYLOAD_PATH"
  14. # Delete previous state.
  15. rm -rf .vol
  16. mkdir -p .vol/boot/grub
  17. cp grub.cfg .vol/boot/grub
  18. cp "$MULTIBOOT2_PAYLOAD_PATH" .vol
  19. # Create a GRUB image with the files in ".vol" being embedded.
  20. grub-mkrescue -o "grub_boot.img" ".vol" 2>/dev/null