Makefile 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. include Makevars
  2. .PHONY: help install-depends config download image unpack bootconfig preseed md5 iso qemu-bios qemu-uefi usb FAT clean maintainer-clean
  3. help:
  4. @echo
  5. @echo "Usage:"
  6. @echo
  7. @echo " make install-depends Install dependencies"
  8. @echo " make config Edit configuration (Makevars)"
  9. @echo " make download download *latest* Debian netinst image"
  10. @echo " make example-preseed.cfg download example-preseed.cfg from Debian"
  11. @echo " make image Build the ISO image"
  12. @echo " make qemu-bios Boot ISO image in QEMU (BIOS mode)"
  13. @echo " make qemu-uefi Boot ISO image in QEMU (UEFI boot)"
  14. @echo " make usb Write ISO to USB device"
  15. @echo " make FAT Add a FAT partition ot the USB stick"
  16. @echo " make clean Clean up temporary files and folders"
  17. @echo " make maintainer-clean Make clean and remove the output ISO"
  18. @echo
  19. @echo "See README.md for details"
  20. @echo
  21. install-depends:
  22. sudo apt-get install \
  23. libarchive-tools syslinux syslinux-utils cpio genisoimage \
  24. coreutils qemu-system qemu-system-x86 qemu-utils util-linux
  25. config:
  26. "$(if $(EDITOR),$(EDITOR),editor)" Makevars
  27. .ONESHELL:
  28. download:
  29. set -e
  30. TMPFILE=`mktemp -p ./`
  31. wget -O $$TMPFILE https://www.debian.org/CD/netinst/
  32. IMGURL=`grep -o -P -e "https://cdimage.debian.org/debian-cd/current/${ARCH}/iso-cd/debian.*?netinst.iso" $$TMPFILE | head -n1`
  33. wget -N $$IMGURL
  34. rm -f $$TMPFILE
  35. example-preseed.cfg:
  36. wget -N -O $@ https://www.debian.org/releases/stable/example-preseed.txt
  37. image: unpack bootconfig preseed md5sums iso
  38. unpack:
  39. # Unpack the image to the folder and set write permissions.
  40. rm -rf ${TMP}
  41. mkdir ${TMP}
  42. bsdtar -C ${TMP} -xf ${SOURCE}
  43. chmod -R +w ${TMP}
  44. bootconfig:
  45. # Create a minimal boot config – no menu, no prompt
  46. # isolinux (BIOS)
  47. sed -e "s/<ARCH>/${ARCHFOLDER}/g" \
  48. -e "s/<CONSOLE>/console=${CONSOLE}/g" \
  49. ${ISOLINUX_CFG_TEMPLATE} > ${TMP}/isolinux/isolinux.cfg
  50. # grub (UEFI)
  51. sed -e "s/<ARCH>/${ARCHFOLDER}/g" \
  52. -e "s/<CONSOLE>/console=${CONSOLE}/g" \
  53. ${GRUB_CFG_TEMPLATE} > ${TMP}/boot/grub/grub.cfg
  54. preseed: preseed.cfg
  55. # Write the preseed file to initrd.
  56. gunzip ${TMP}/install.${ARCHFOLDER}/initrd.gz
  57. echo preseed.cfg | cpio -H newc -o -A -F ${TMP}/install.${ARCHFOLDER}/initrd
  58. gzip ${TMP}/install.${ARCHFOLDER}/initrd
  59. md5sums:
  60. # Recreate the MD5 sums of all files.
  61. find ${TMP}/ -type f -exec md5sum {} \; > ${TMP}/md5sum.txt
  62. iso: ${TMP}
  63. # Create ISO and fix MBR for USB boot.
  64. genisoimage -V ${LABEL} \
  65. -r -J -b isolinux/isolinux.bin -c isolinux/boot.cat \
  66. -no-emul-boot -boot-load-size 4 -boot-info-table \
  67. -eltorito-alt-boot \
  68. -e ${tmp} boot/grub/efi.img \
  69. -no-emul-boot \
  70. -o ${TARGET} ${TMP}
  71. isohybrid --uefi ${TARGET}
  72. qemu-bios: image.qcow
  73. # boot image in qemu (BIOS mode)
  74. @echo
  75. @echo "Once the installer has launched networking you can log in:\n"
  76. @echo " ssh installer@localhost -p22222\n"
  77. @echo "It may take a few minutes for the installer to get to that point.\n"
  78. @echo "Alternatively connect to the serial console:\n"
  79. @echo " telnet localhost 33333\n"
  80. ${QEMU} -m 1024 \
  81. -net user,hostfwd=tcp::22222-:22 \
  82. -net nic \
  83. -hda image.qcow \
  84. -serial telnet:localhost:33333,server,nowait \
  85. -cdrom ${TARGET}
  86. qemu-uefi: image.qcow
  87. # boot image in qemu (UEFI mode)
  88. @echo
  89. @echo "Once the installer has launched networking you can log in:\n"
  90. @echo " ssh installer@localhost -p22222\n"
  91. @echo "It may take a few minutes for the installer to get to that point.\n"
  92. @echo "Alternatively connect to the serial console:\n"
  93. @echo " telnet localhost 33333\n"
  94. ${QEMU} -m 1024 \
  95. -net user,hostfwd=tcp::22222-:22 \
  96. -bios /usr/share/ovmf/OVMF.fd \
  97. -net nic \
  98. -hda image.qcow \
  99. -serial telnet:localhost:33333,server,nowait \
  100. -cdrom ${TARGET}
  101. image.qcow:
  102. # Create a virtual disk for QEMU.
  103. qemu-img create -f qcow2 $@ 10G
  104. usb:
  105. # Write the image to usb stick.
  106. @echo "This will overwrite all data on ${USBDEV}!"
  107. @read -p "Type 'yes' if you really want to do this: " proceed; \
  108. if [ $$proceed = "yes" ] ; then \
  109. echo "writing image to ${USBDEV}"; \
  110. sudo dd if=${TARGET} of=${USBDEV} bs=4k ; \
  111. sync ; \
  112. else \
  113. echo "Aborting" ; \
  114. fi
  115. FAT:
  116. # Add a FAT partition in the remaining free space (e.g. for driver files).
  117. @echo "This will overwrite ${USBDEV}!"
  118. @read -p "Type 'yes' if you really want to do this: " proceed; \
  119. if [ $$proceed = "yes" ] ; then \
  120. echo " , , 0xb" | sudo sfdisk ${USBDEV} -N 3 ;\
  121. sudo mkfs.vfat ${USBDEV}3 ;\
  122. sync ;\
  123. else \
  124. echo "Aborting" ; \
  125. fi
  126. clean:
  127. rm -rf ${TMP}
  128. rm -f image.qcow
  129. maintainer-clean: clean
  130. rm -f ${TARGET}
  131. rm -f example-preseed.cfg