]> git.ipfire.org Git - ipfire-2.x.git/blob - lfs/cdrom
grub: fix mkimage on riscv64 and fix cdrom
[ipfire-2.x.git] / lfs / cdrom
1 ###############################################################################
2 # #
3 # IPFire.org - A linux based firewall #
4 # Copyright (C) 2007-2021 IPFire Team <info@ipfire.org> #
5 # #
6 # This program is free software: you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation, either version 3 of the License, or #
9 # (at your option) any later version. #
10 # #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
15 # #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
18 # #
19 ###############################################################################
20
21 ###############################################################################
22 # Definitions
23 ###############################################################################
24
25 include Config
26
27 VER = ipfire
28
29 THISAPP = cdrom
30 TARGET = $(DIR_INFO)/$(THISAPP)
31
32 # Fail when there is an error in the tar pipe
33 SHELL=/bin/bash -o pipefail
34
35 HAS_MEMTEST = 0
36 HAS_IPXE = 0
37 HAS_ISOLINUX = 0
38
39 ifeq "$(BUILD_PLATFORM)" "x86"
40 HAS_MEMTEST = 1
41 HAS_IPXE = 1
42 HAS_ISOLINUX = 1
43 endif
44
45 ISO_ARGS = -J -r -v \
46 -A "$(NAME) $(VERSION) $(BUILD_ARCH)" \
47 -V "$(NAME) $(VERSION) $(BUILD_ARCH)"
48
49 ISOHYBRID_ARGS =
50
51 ifeq "$(HAS_ISOLINUX)" "1"
52 ISO_ARGS += \
53 -no-emul-boot \
54 -boot-load-size 4 \
55 -boot-info-table \
56 -b boot/isolinux/isolinux.bin \
57 -c boot/isolinux/boot.catalog
58 endif
59
60 ifeq "$(EFI)" "1"
61 ISO_ARGS += \
62 -eltorito-alt-boot \
63 -e boot/isolinux/efiboot.img \
64 -no-emul-boot
65
66 ISOHYBRID_ARGS += --uefi
67 endif
68
69 GRUB_EFI_MODULES = \
70 all_video \
71 at_keyboard \
72 boot \
73 bitmap_scale \
74 cat \
75 chain \
76 configfile \
77 disk \
78 echo \
79 efi_gop \
80 efi_uga \
81 ext2 \
82 extcmd \
83 fat \
84 file \
85 font \
86 fxterm_menu \
87 gfxterm \
88 gfxmenu \
89 gfxterm_background \
90 gzio \
91 halt \
92 help \
93 iso9660 \
94 jpeg \
95 loadbios \
96 loadenv \
97 loopback \
98 linux \
99 ls \
100 memdisk \
101 minicmd \
102 nativedisk \
103 normal \
104 ntfs \
105 part_gpt \
106 part_msdos \
107 png \
108 probe \
109 reboot \
110 regexp \
111 search \
112 search_fs_file \
113 search_fs_uuid \
114 search_label \
115 tar \
116 test \
117 tga \
118 true \
119 usb_keyboard
120
121 ISO_FILE = /install/images/$(SNAME)-$(VERSION)-core$(CORE)-$(BUILD_ARCH).iso
122
123 ###############################################################################
124 # Top-level Rules
125 ###############################################################################
126
127 install : $(TARGET)
128
129 check :
130
131 download :
132
133 b2 :
134
135 ###############################################################################
136 # Installation Details
137 ###############################################################################
138
139 $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
140 # Update /etc/system-release, because the string might have changed
141 # since stage2 has been executed..
142 echo "$(SYSTEM_RELEASE)" > /etc/system-release
143
144 # Create a directory to authorise the CDROM in
145 rm -rf $(DIR_TMP)/cdrom && mkdir -p $(DIR_TMP)/cdrom
146
147 # Clear mtab (prevents .journal problems)
148 rm -vf /etc/mtab
149 ln -s /proc/self/mounts /etc/mtab
150
151 # Create filelist for packaging.
152 BUILDTARGET="$(BUILDTARGET)" BUILD_ARCH="$(BUILD_ARCH)" KVER="$(KVER)" \
153 $(DIR_SRC)/src/scripts/archive.files \
154 $(DIR_SRC)/config/rootfiles/common \
155 > $(DIR_TMP)/ROOTFILES
156
157 # Compress root filesystem
158 # Reason for this tar+untar+tar is removing of entries listed two or more in src/ROOTFILES
159 rm -rf $(DIR_TMP)/root && mkdir -p $(DIR_TMP)/root
160 tar $(TAR_OPTIONS) -c --exclude='#*' --exclude='proc/*' --exclude='dev/pts/*' --exclude='tmp/*' \
161 --exclude='__pycache__' \
162 -C / --files-from=$(DIR_TMP)/ROOTFILES | tar $(TAR_OPTIONS) -x -C $(DIR_TMP)/root
163 rm -f $(DIR_TMP)/ROOTFILES
164 mkdir $(DIR_TMP)/root/sys
165 cd $(DIR_TMP)/root && tar $(TAR_OPTIONS) -cf - * | zstd $(ZSTD_OPTIONS) > $(DIR_TMP)/cdrom/distro.img
166 rm -rf $(DIR_TMP)/root
167
168 # Other files
169 touch $(DIR_TMP)/cdrom/$(SNAME)-$(VERSION)-core$(CORE).media
170 sed 's/VERSION/$(VERSION)/' $(DIR_SRC)/config/cdrom/README.txt > $(DIR_TMP)/cdrom/README.txt
171 cp $(DIR_SRC)/doc/COPYING $(DIR_TMP)/cdrom/
172
173 # Install documentation
174 -mkdir -pv $(DIR_TMP)/cdrom/doc
175 cp $(DIR_SRC)/doc/{ChangeLog,packages-list.txt} $(DIR_TMP)/cdrom/doc
176
177 mkdir -p $(DIR_TMP)/cdrom/boot/isolinux
178
179 cp /boot/vmlinuz-$(KVER)-ipfire $(DIR_TMP)/cdrom/boot/isolinux/vmlinuz
180 dracut --force -a "installer" --strip $(DIR_TMP)/cdrom/boot/isolinux/instroot $(KVER)-ipfire
181
182 ifeq "$(HAS_ISOLINUX)" "1"
183 dd if=/dev/zero bs=1k count=2 > $(DIR_TMP)/cdrom/boot/isolinux/boot.catalog
184 cp $(DIR_SRC)/config/syslinux/boot.png $(DIR_TMP)/cdrom/boot/isolinux/boot.png
185 cp /usr/share/syslinux/isolinux.bin $(DIR_TMP)/cdrom/boot/isolinux/isolinux.bin
186 cp /usr/share/hwdata/pci.ids $(DIR_TMP)/cdrom/boot/isolinux/pci.ids
187 cp -vf /usr/share/syslinux/*.c32 $(DIR_TMP)/cdrom/boot/isolinux/
188 sed -e "s/VERSION/$(VERSION) - Core $(CORE)/g" \
189 $(DIR_SRC)/config/syslinux/syslinux.cfg \
190 > $(DIR_TMP)/cdrom/boot/isolinux/isolinux.cfg
191 endif
192
193 ifeq "$(HAS_MEMTEST)" "1"
194 # Install memtest
195 cp /usr/lib/memtest86+/memtest.efi $(DIR_TMP)/cdrom/boot/isolinux/memtest
196 endif
197
198 ifeq "$(HAS_IPXE)" "1"
199 cp /usr/share/ipfire-netboot/ipxe.lkrn $(DIR_TMP)/cdrom/boot/isolinux/netboot
200 endif
201
202 ifeq "$(EFI)" "1"
203 # Generate embedded GRUB configuration
204 sed -e "s/NAME/$(NAME)/g" -e "s/VERSION/$(VERSION)/g" -e "s/ARCH/$(BUILD_ARCH)/g" \
205 $(DIR_SRC)/config/cdrom/grub-efi.cfg > /tmp/grub-efi.cfg
206
207 # Build a GRUB EFI image
208 mkdir -pv $(DIR_TMP)/cdrom/EFI/BOOT
209 grub-mkimage \
210 --format=$(GRUB_ARCH)-efi \
211 --output=$(DIR_TMP)/cdrom/EFI/BOOT/boot$(EFI_ARCH).efi \
212 --config=$(DIR_TMP)/grub-efi.cfg \
213 --compression=xz \
214 --prefix=/EFI/BOOT \
215 $$(for mod in $(GRUB_EFI_MODULES); do [ -f "/usr/lib/grub/$(GRUB_ARCH)-efi/$${mod}.mod" ] && echo "$${mod}"; done)
216
217 # Install GRUB configuration
218 mkdir -pv $(DIR_TMP)/cdrom/EFI/BOOT
219 sed -e "s/NAME/$(NAME)/g" -e "s/VERSION/$(VERSION)/g" -e "s/ARCH/$(BUILD_ARCH)/g" \
220 < $(DIR_SRC)/config/cdrom/grub.cfg > $(DIR_TMP)/cdrom/EFI/BOOT/grub.cfg
221
222 # Create the EFI Eltorito image
223 dd if=/dev/zero of=$(DIR_TMP)/cdrom/boot/isolinux/efiboot.img bs=1k count=2880
224 mkdosfs -F 12 -n "IPFIRE_EFI" $(DIR_TMP)/cdrom/boot/isolinux/efiboot.img
225
226 # Mount the EFI image
227 mkdir -pv $(DIR_TMP)/efiboot.img
228 mount -o loop $(DIR_TMP)/cdrom/boot/isolinux/efiboot.img $(DIR_TMP)/efiboot.img
229
230 # Copy the bootloader into the image
231 mkdir -p $(DIR_TMP)/efiboot.img/EFI/BOOT
232 cp -a $(DIR_TMP)/cdrom/EFI/BOOT/boot$(EFI_ARCH).efi \
233 $(DIR_TMP)/efiboot.img/EFI/BOOT/boot$(EFI_ARCH).efi
234
235 # Cleanup
236 umount $(DIR_TMP)/efiboot.img
237 rm -rf $(DIR_TMP)/efiboot.img $(DIR_TMP)/grub-efi.cfg
238 endif
239
240 cd $(DIR_TMP)/cdrom && find -type f ! -name md5sum.txt | grep -v "./boot" | \
241 xargs md5sum > md5sum.txt
242
243 mkdir -p /install/images
244 cd $(DIR_TMP)/cdrom && mkisofs $(ISO_ARGS) -o $(ISO_FILE) .
245
246 ifeq "$(HAS_ISOLINUX)" "1"
247 isohybrid $(ISOHYBRID_ARGS) $(ISO_FILE)
248 endif