build-img.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/bash
  2. # Build a qcow2 image for loading in qemu
  3. # Syslinux should already be installed on the system since it's a
  4. # dependency of guestfish. We want to use the system syslinux binaries
  5. # which match the extlinux command below.
  6. SRC_SYSLINUX=/usr/lib/syslinux/bios
  7. SRC_MBR=/usr/lib/syslinux/bios/mbr.bin
  8. SRC_CFG=$HARVEY/util/img/syslinux-bios/syslinux/syslinux-usb.cfg
  9. SRC_KERNEL=$HARVEY/sys/src/9/amd64/harvey.32bit
  10. FORMAT=qcow2
  11. if [ "$1" = "-f" ]; then
  12. FORMAT=$2
  13. fi
  14. if [ "$FORMAT" = "" ]; then
  15. echo "usage: $0 [-f format]" 1>&2
  16. exit 2
  17. fi
  18. DEST=$HARVEY/harvey.$FORMAT
  19. echo "Creating harvey image $DEST"
  20. rm -f $DEST
  21. guestfish <<EOF
  22. disk-create $DEST $FORMAT 3G
  23. add-drive $DEST
  24. launch
  25. part-init /dev/sda mbr
  26. part-add /dev/sda p 2048 104447
  27. part-add /dev/sda p 104448 6291455
  28. part-set-mbr-id /dev/sda 2 57
  29. mke2fs /dev/sda1
  30. part-set-bootable /dev/sda 1 true
  31. mount /dev/sda1 /
  32. extlinux /
  33. copy-in $SRC_SYSLINUX /
  34. rename /bios /syslinux
  35. copy-in $SRC_CFG /syslinux
  36. rename /syslinux/syslinux-usb.cfg /syslinux/syslinux.cfg
  37. copy-in $SRC_KERNEL /
  38. rename /harvey.32bit /harvey
  39. copy-in $SRC_MBR /
  40. copy-file-to-device /mbr.bin /dev/sda size:440
  41. rm /mbr.bin
  42. EOF
  43. echo "Done"