]>
Commit | Line | Data |
---|---|---|
1 | ############################################################################### | |
2 | # # | |
3 | # IPFire.org - A linux based firewall # | |
4 | # Copyright (C) 2007-2022 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 = flash-image | |
30 | TARGET = $(DIR_INFO)/$(THISAPP) | |
31 | ||
32 | DEVICE = $(shell losetup -f) | |
33 | PART_BOOT = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p1 | |
34 | ifeq "$(EFI)" "1" | |
35 | PART_EFI = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p2 | |
36 | endif | |
37 | PART_ROOT = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p3 | |
38 | ||
39 | IMAGE_FILE = /install/images/$(SNAME)-$(VERSION)-core$(CORE)-$(BUILD_ARCH).img.xz | |
40 | ||
41 | FSTAB_FMT = UUID=%s %-8s %-4s %-10s %d %d\n | |
42 | ||
43 | ############################################################################### | |
44 | # Top-level Rules | |
45 | ############################################################################### | |
46 | ||
47 | install : $(TARGET) | |
48 | ||
49 | check : | |
50 | ||
51 | download : | |
52 | ||
53 | b2 : | |
54 | ||
55 | ############################################################################### | |
56 | # Installation Details | |
57 | ############################################################################### | |
58 | MNThdd := $(DIR_TMP)/harddisk | |
59 | IMG := $(DIR_TMP)/image.img | |
60 | ||
61 | # All sizes in blocks | |
62 | ifeq "$(BUILD_PLATFORM)" "arm" | |
63 | BOOTLOADER = | |
64 | S_OFFSET = 8192 | |
65 | ||
66 | # FAT32 | |
67 | PART_TYPE = c | |
68 | ifeq "$(BUILD_ARCH)" "aarch64" | |
69 | BOOTLOADER = grub | |
70 | S_OFFSET = 32768 | |
71 | endif | |
72 | else | |
73 | BOOTLOADER = grub | |
74 | S_OFFSET = 8192 | |
75 | ||
76 | # Linux | |
77 | PART_TYPE = L | |
78 | endif | |
79 | ||
80 | # /boot: 512 MB - OFFSET | |
81 | # / : 1800 MB | |
82 | S_BOOT := $(shell echo $$(( 1048576 - $(S_OFFSET) ))) | |
83 | S_ROOT := 3773292 | |
84 | ||
85 | ifeq "$(EFI)" "1" | |
86 | S_EFI = 65536 # 32 MB | |
87 | else | |
88 | S_EFI = 0 | |
89 | endif | |
90 | ||
91 | PADDING = 100 # MB | |
92 | ||
93 | ifeq "$(EFI)" "1" | |
94 | SFDISK = $(SFDISK_BOOT)$(SFDISK_EFI)$(SFDISK_ROOT) | |
95 | else | |
96 | SFDISK = $(SFDISK_BOOT),0,0\n$(SFDISK_ROOT) | |
97 | endif | |
98 | ||
99 | SFDISK_BOOT = $(S_OFFSET),$(S_BOOT),$(PART_TYPE),*\n | |
100 | SFDISK_EFI = $(shell echo $$(( $(S_OFFSET) + $(S_BOOT) ))),$(S_EFI),U\n | |
101 | SFDISK_ROOT = $(shell echo $$(( $(S_OFFSET) + $(S_BOOT) + $(S_EFI) ))),$(S_ROOT),L\n | |
102 | ||
103 | $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) | |
104 | # Stop if $(MNThdd) is still mounted | |
105 | mountpoint $(MNThdd) && exit 1 || exit 0 | |
106 | ||
107 | rm -rf $(IMG) $(MNThdd) && mkdir -p $(MNThdd) | |
108 | ||
109 | # Allocate image on disk | |
110 | dd if=/dev/zero of=$(IMG) bs=512 count=$$(( $(S_OFFSET) + $(S_BOOT) + $(S_EFI) + $(S_ROOT) )) | |
111 | losetup $(DEVICE) $(IMG) | |
112 | ||
113 | # Write Partition table | |
114 | echo -e "$(SFDISK)" | sfdisk -uS $(DEVICE) | |
115 | ||
116 | kpartx -v -a $(DEVICE) | |
117 | ||
118 | # Format them | |
119 | ifeq "$(PART_TYPE)" "c" | |
120 | mkfs.vfat $(PART_BOOT) | |
121 | else | |
122 | mkfs.ext2 -F $(PART_BOOT) | |
123 | endif | |
124 | ifeq "$(EFI)" "1" | |
125 | mkfs.vfat $(PART_EFI) | |
126 | endif | |
127 | mkfs.ext4 -O ^has_journal,extent -F $(PART_ROOT) | |
128 | ||
129 | # Most systems that use Flashimages has no RTC at boot | |
130 | # so the interval check should disables | |
131 | tune2fs -i0 $(PART_ROOT) | |
132 | ||
133 | # Mount root partition | |
134 | mount $(PART_ROOT) $(MNThdd) | |
135 | ||
136 | # Mount boot partition | |
137 | mkdir -pv $(MNThdd)/boot | |
138 | mount $(PART_BOOT) $(MNThdd)/boot | |
139 | ||
140 | ifeq "$(EFI)" "1" | |
141 | mkdir -pv $(MNThdd)/boot/efi | |
142 | mount $(PART_EFI) $(MNThdd)/boot/efi | |
143 | endif | |
144 | ||
145 | # Install IPFire | |
146 | ifneq "$(BUILD_PLATFORM)" "arm" | |
147 | tar $(TAR_OPTIONS) -x --zstd -C $(MNThdd)/ -f $(DIR_TMP)/cdrom/distro.img | |
148 | else | |
149 | tar $(TAR_OPTIONS) -x -C $(MNThdd)/ -f $(DIR_TMP)/cdrom/distro.img | |
150 | endif | |
151 | -touch $(MNThdd)/lib/modules/$(KVER)-ipfire/modules.dep | |
152 | mkdir $(MNThdd)/proc | |
153 | mount --bind /proc $(MNThdd)/proc | |
154 | mount --bind /dev $(MNThdd)/dev | |
155 | mount --bind /sys $(MNThdd)/sys | |
156 | ||
157 | chroot $(MNThdd) /usr/bin/perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang" | |
158 | ||
159 | # Create /etc/fstab | |
160 | printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_BOOT))" "/boot" \ | |
161 | "auto" "defaults,nodev,noexec,nosuid" 1 2 > $(MNThdd)/etc/fstab | |
162 | ifeq "$(EFI)" "1" | |
163 | printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_EFI))" "/boot/efi" \ | |
164 | "auto" "defaults" 1 2 >> $(MNThdd)/etc/fstab | |
165 | endif | |
166 | printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_ROOT))" "/" \ | |
167 | "auto" "defaults" 1 1 >> $(MNThdd)/etc/fstab | |
168 | ||
169 | ifeq "$(BOOTLOADER)" "grub" | |
170 | # backup defaults file | |
171 | cp $(MNThdd)/etc/default/grub $(MNThdd)/etc/default/grub.backup | |
172 | ||
173 | # Enable also serial console on GRUB | |
174 | echo "GRUB_TERMINAL=\"serial console\"" >> $(MNThdd)/etc/default/grub | |
175 | echo "GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=115200\"" >> $(MNThdd)/etc/default/grub | |
176 | ||
177 | # Add additional entry for Serial console | |
178 | cp $(DIR_SRC)/config/flash-images/grub/11_linux_scon \ | |
179 | $(MNThdd)/etc/grub.d/ | |
180 | ||
181 | # Create configuration | |
182 | mkdir -pv $(MNThdd)/boot/grub | |
183 | GRUB_FIRST_BOOT=true KERNEL_RELEASE="$(KVER)-ipfire" chroot $(MNThdd) \ | |
184 | grub-mkconfig -o /boot/grub/grub.cfg | |
185 | ||
186 | # Boot the first kernel by default | |
187 | chroot $(MNThdd) grub-set-default 0 | |
188 | ||
189 | # Insert the UUID because grub-mkconfig often fails to | |
190 | # detect that correctly | |
191 | sed -i $(MNThdd)/boot/grub/grub.cfg \ | |
192 | -e "s/root=[A-Za-z0-9\/=-]*/root=UUID=$$(blkid -o value -s UUID $(PART_ROOT))/g" | |
193 | ||
194 | ifeq "$(BUILD_PLATFORM)" "x86" | |
195 | # Install GRUB | |
196 | grub-install --force --recheck --no-floppy --target=i386-pc \ | |
197 | --root-directory=$(MNThdd) $(DEVICE) | |
198 | endif | |
199 | ||
200 | ifeq "$(EFI)" "1" | |
201 | # Install GRUB for EFI | |
202 | grub-install --target=$(GRUB_ARCH)-efi --removable --no-nvram \ | |
203 | --boot-directory=$(MNThdd)/boot --efi-directory=$(MNThdd)/boot/efi | |
204 | endif | |
205 | ||
206 | # restore orginal defaults | |
207 | mv -f $(MNThdd)/etc/default/grub.backup $(MNThdd)/etc/default/grub | |
208 | rm -f $(MNThdd)/etc/grub.d/11_linux_scon | |
209 | endif | |
210 | ||
211 | ifeq "$(BUILD_PLATFORM)" "arm" | |
212 | # Insert the UUID to uENV.txt | |
213 | sed -i $(MNThdd)/boot/uENV.txt \ | |
214 | -e "s/^root_dev=.*/root_dev=UUID=$$(blkid -o value -s UUID $(PART_ROOT))/g" | |
215 | endif | |
216 | ||
217 | # Set ramdisk mode to automatic | |
218 | echo RAMDISK_MODE=2 > $(MNThdd)/etc/sysconfig/ramdisk | |
219 | ||
220 | # Automatically resize the root partition to its maximum size at first boot | |
221 | touch $(MNThdd)/.partresize | |
222 | ||
223 | # Unmount | |
224 | umount $(MNThdd)/proc | |
225 | umount $(MNThdd)/sys | |
226 | umount $(MNThdd)/dev | |
227 | ifeq "$(EFI)" "1" | |
228 | umount $(MNThdd)/boot/efi | |
229 | endif | |
230 | umount $(MNThdd)/boot | |
231 | umount $(MNThdd) | |
232 | ||
233 | # zerofree the ext2 images to get better compression | |
234 | ifneq "$(PART_TYPE)" "c" | |
235 | zerofree $(PART_BOOT) | |
236 | -fsck.ext2 -f -y $(PART_BOOT) | |
237 | fsck.ext2 -f -y $(PART_BOOT) | |
238 | endif | |
239 | zerofree $(PART_ROOT) | |
240 | -fsck.ext4 -f -y $(PART_ROOT) | |
241 | fsck.ext4 -f -y $(PART_ROOT) | |
242 | ||
243 | sleep 10 #Ubuntu compiling: allow time to automount/dismount | |
244 | kpartx -d -v $(DEVICE) | |
245 | losetup -d $(DEVICE) | |
246 | ||
247 | # Add padding at the end of the image (to fix alignment issues if the image is | |
248 | # not copied to a block device) | |
249 | dd if=/dev/zero bs=1M count=$(PADDING) >> $(IMG) | |
250 | ||
251 | ifeq "$(BUILD_ARCH)" "aarch64" | |
252 | # Install u-boot for NanoPi R2S into image 8KB | |
253 | dd if=/usr/share/u-boot/nanopi_r2s/u-boot-rockchip.bin of=$(IMG) bs=1K seek=32 conv=notrunc | |
254 | endif | |
255 | ||
256 | # Compress Image | |
257 | xz $(XZ_OPT) < $(IMG) > $(IMAGE_FILE) | |
258 | rm -rf $(IMG) $(MNThdd) $(DIR_TMP)/cdrom |