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