diff options
Diffstat (limited to '')
| -rwxr-xr-x | tools/boot-image.sh | 62 |
1 files changed, 0 insertions, 62 deletions
diff --git a/tools/boot-image.sh b/tools/boot-image.sh deleted file mode 100755 index 2592afa..0000000 --- a/tools/boot-image.sh +++ /dev/null | |||
| @@ -1,62 +0,0 @@ | |||
| 1 | #!/usr/bin/env bash | ||
| 2 | # ============================================================================= | ||
| 3 | # tools/boot-image.sh — Create a bootable disk image from the ESP directory | ||
| 4 | # | ||
| 5 | # Produces a raw disk image (bootable via UEFI) for dd-ing to a USB stick | ||
| 6 | # or attaching to QEMU as a hard disk. | ||
| 7 | # | ||
| 8 | # Usage: | ||
| 9 | # ./tools/boot-image.sh [output.img] | ||
| 10 | # | ||
| 11 | # Default output: raisernics.img | ||
| 12 | # ============================================================================= | ||
| 13 | set -euo pipefail | ||
| 14 | |||
| 15 | SCRIPT_DIR="$(cd "$(dirname "$0")/.." && pwd)" | ||
| 16 | cd "$SCRIPT_DIR" | ||
| 17 | |||
| 18 | OUTPUT="${1:-raisernics.img}" | ||
| 19 | ESP_DIR="${ESP_DIR:-esp}" | ||
| 20 | MBR_SZ=1 # 1 MB reserved at start for GPT/pmbr | ||
| 21 | SECTOR_SZ=512 | ||
| 22 | |||
| 23 | # Rebuild ESP if stale | ||
| 24 | make all | ||
| 25 | |||
| 26 | if [ ! -d "$ESP_DIR" ]; then | ||
| 27 | echo "ERROR: ESP directory '$ESP_DIR' not found. Run 'make all' first." | ||
| 28 | exit 1 | ||
| 29 | fi | ||
| 30 | |||
| 31 | # Calculate required size: ESP contents + MBR gap + some slack | ||
| 32 | ESP_SIZE_MB=$(du -sm "$ESP_DIR" 2>/dev/null | cut -f1 || echo 1) | ||
| 33 | TOTAL_MB=$((ESP_SIZE_MB + MBR_SZ + 1)) # +1 MB slack | ||
| 34 | |||
| 35 | echo "Creating ${TOTAL_MB} MB disk image: ${OUTPUT}" | ||
| 36 | |||
| 37 | # Create empty image with MBR gap | ||
| 38 | dd if=/dev/zero of="$OUTPUT" bs=1M count="$TOTAL_MB" status=none 2>/dev/null | ||
| 39 | |||
| 40 | # Partition table: single GPT partition, type EFI System (C12A7328-F81F-11D2-BA4B-00A0C93EC93B) | ||
| 41 | sgdisk --clear \ | ||
| 42 | --new=1:${MBR_SZ}M:0 \ | ||
| 43 | --typecode=1:C12A7328-F81F-11D2-BA4B-00A0C93EC93B \ | ||
| 44 | --change-name=1:"raisernics" \ | ||
| 45 | "$OUTPUT" >/dev/null | ||
| 46 | |||
| 47 | # Find partition offset | ||
| 48 | PART_START=$(sgdisk --info=1 "$OUTPUT" 2>/dev/null | grep "Partition start sector" | awk '{print $NF}') | ||
| 49 | if [ -z "$PART_START" ]; then | ||
| 50 | PART_START=$((MBR_SZ * 1024 * 1024 / SECTOR_SZ)) | ||
| 51 | fi | ||
| 52 | |||
| 53 | # Format as FAT32 | ||
| 54 | mformat -i "$OUTPUT"@$((PART_START * SECTOR_SZ)) -h 32 -s 32 -t "$((TOTAL_MB * 2))" >/dev/null 2>&1 || true | ||
| 55 | |||
| 56 | # Copy the ESP contents onto the partition | ||
| 57 | mcopy -i "$OUTPUT"@$((PART_START * SECTOR_SZ)) -s "$ESP_DIR"/* ::/ 2>/dev/null | ||
| 58 | |||
| 59 | echo " -> ${OUTPUT} ($(ls -lh "$OUTPUT" | awk '{print $5}'))" | ||
| 60 | echo "" | ||
| 61 | echo "To write to USB: sudo dd if=${OUTPUT} of=/dev/sdX bs=4M status=progress" | ||
| 62 | echo "To test with QEMU: qemu-system-x86_64 -bios <OVMF> -drive file=${OUTPUT},format=raw" | ||
