]>
Commit | Line | Data |
---|---|---|
52ca8220 AF |
1 | ############################################################################### |
2 | # # | |
3 | # IPFire.org - A linux based firewall # | |
ea9d53c8 | 4 | # Copyright (C) 2007-2018 IPFire Team <info@ipfire.org> # |
52ca8220 AF |
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 | ||
7fbbd2ae MT |
32 | ifeq "$(MACHINE)" "x86_64" |
33 | EFI = 1 | |
34 | endif | |
35 | ||
784cd5cb MT |
36 | ifeq "$(MACHINE)" "i586" |
37 | EFI = 1 | |
38 | endif | |
39 | ||
c42cbc86 MT |
40 | DEVICE = $(shell losetup -f) |
41 | PART_BOOT = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p1 | |
784cd5cb MT |
42 | ifeq "$(EFI)" "1" |
43 | PART_EFI = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p2 | |
44 | endif | |
05656571 | 45 | PART_ROOT = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p3 |
c42cbc86 | 46 | |
b302b9a6 | 47 | IMAGE_FILE = /install/images/$(SNAME)-$(VERSION).2gb-ext4.$(BUILD_ARCH)-full-core$(CORE).img.xz |
c42cbc86 MT |
48 | |
49 | FSTAB_FMT = UUID=%s %-8s %-4s %-10s %d %d\n | |
50 | ||
52ca8220 AF |
51 | ############################################################################### |
52 | # Top-level Rules | |
53 | ############################################################################### | |
54 | ||
55 | install : $(TARGET) | |
56 | ||
57 | check : | |
58 | ||
59 | download : | |
60 | ||
61 | md5 : | |
62 | ||
63 | ############################################################################### | |
64 | # Installation Details | |
65 | ############################################################################### | |
52ca8220 | 66 | MNThdd := /install/harddisk |
c42cbc86 | 67 | IMG := /install/images/image.img |
8a5ef45f SS |
68 | |
69 | # All sizes in blocks | |
dc7d6b20 | 70 | ifeq "$(BUILD_PLATFORM)" "arm" |
c42cbc86 | 71 | BOOTLOADER = |
8a5ef45f SS |
72 | S_OFFSET = 8192 |
73 | ||
74 | # FAT32 | |
75 | PART_TYPE = c | |
76 | else | |
c42cbc86 MT |
77 | BOOTLOADER = grub |
78 | S_OFFSET = 8192 | |
8a5ef45f SS |
79 | |
80 | # Logical | |
81 | PART_TYPE = L | |
82 | endif | |
83 | ||
784cd5cb MT |
84 | GRUB_CFGS = /boot/grub/grub.cfg |
85 | ||
86 | ifeq "$(EFI)" "1" | |
87 | S_EFI = 204800 | |
88 | GRUB_CFGS += /boot/efi/EFI/ipfire/grub-efi/grub.cfg | |
89 | else | |
90 | S_EFI = 0 | |
91 | endif | |
92 | ||
779706b5 | 93 | # /boot: 128MB - OFFSET |
02c36af4 | 94 | # / : 1200 MB |
779706b5 | 95 | S_BOOT := $(shell echo $$(( 262144 - $(S_OFFSET) ))) |
02c36af4 | 96 | S_ROOT := 2477600 |
52ca8220 | 97 | |
7fbbd2ae MT |
98 | ifeq "$(MACHINE)" "x86_64" |
99 | EFI_ARCH = x64 | |
100 | endif | |
101 | ||
102 | ifeq "$(MACHINE)" "i586" | |
103 | EFI_ARCH = ia32 | |
104 | endif | |
105 | ||
7051d2af MT |
106 | PADDING = 100 # MB |
107 | ||
784cd5cb MT |
108 | ifeq "$(EFI)" "1" |
109 | SFDISK_EFI = $(S_OFFSET),$(S_EFI),c,*\n | |
110 | SFDISK = $(SFDISK_BOOT)$(SFDISK_EFI)$(SFDISK_ROOT) | |
111 | else | |
112 | SFDISK_SWAP = ,0,0\n | |
113 | SFDISK = $(SFDISK_BOOT)$(SFDISK_SWAP)$(SFDISK_ROOT) | |
114 | endif | |
115 | ||
116 | SFDISK_BOOT = $(shell echo $$(( $(S_OFFSET) + $(S_EFI) ))),$(S_BOOT),$(PART_TYPE)\n | |
117 | SFDISK_ROOT = $(shell echo $$(( $(S_OFFSET) + $(S_EFI) + $(S_BOOT) ))),$(S_ROOT),L\n | |
118 | ||
52ca8220 | 119 | $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) |
c42cbc86 MT |
120 | # Stop if $(MNThdd) is still mounted |
121 | mountpoint $(MNThdd) && exit 1 || exit 0 | |
122 | ||
123 | rm -rf $(IMG) $(MNThdd) && mkdir -p $(MNThdd) | |
124 | ||
125 | # Allocate image on disk | |
784cd5cb | 126 | dd if=/dev/zero of=$(IMG) bs=512 count=$$(( $(S_OFFSET) + $(S_BOOT) + $(S_EFI) + $(S_ROOT) )) |
c42cbc86 | 127 | losetup $(DEVICE) $(IMG) |
52ca8220 | 128 | |
c42cbc86 | 129 | # Write Partition table |
784cd5cb MT |
130 | echo -e "$(SFDISK)" | sfdisk -uS $(DEVICE) |
131 | ||
132 | # Remove 2nd empty partition | |
133 | ifneq "$(EFI)" "1" | |
025e1fe1 | 134 | -echo -e "d\n2\nw\n\q\n" | fdisk $(DEVICE) |
784cd5cb | 135 | endif |
52ca8220 | 136 | |
c42cbc86 | 137 | kpartx -v -a $(DEVICE) |
52ca8220 AF |
138 | |
139 | # Format them | |
8a5ef45f | 140 | ifeq "$(PART_TYPE)" "c" |
c42cbc86 | 141 | mkfs.vfat $(PART_BOOT) |
185f92e1 | 142 | else |
c42cbc86 | 143 | mkfs.ext2 -F $(PART_BOOT) |
784cd5cb MT |
144 | endif |
145 | ifeq "$(EFI)" "1" | |
146 | mkfs.vfat $(PART_EFI) | |
185f92e1 | 147 | endif |
c42cbc86 | 148 | mkfs.ext4 -O ^has_journal,extent -F $(PART_ROOT) |
52ca8220 | 149 | |
e9b5c815 AF |
150 | # Most systems that use Flashimages has no RTC at boot |
151 | # so the interval check should disables | |
c42cbc86 MT |
152 | tune2fs -i0 $(PART_ROOT) |
153 | ||
154 | # Mount root partition | |
155 | mount $(PART_ROOT) $(MNThdd) | |
e9b5c815 | 156 | |
c42cbc86 MT |
157 | # Mount boot partition |
158 | mkdir -pv $(MNThdd)/boot | |
159 | mount $(PART_BOOT) $(MNThdd)/boot | |
52ca8220 | 160 | |
784cd5cb MT |
161 | ifeq "$(EFI)" "1" |
162 | mkdir -pv $(MNThdd)/boot/efi | |
163 | mount $(PART_EFI) $(MNThdd)/boot/efi | |
164 | endif | |
165 | ||
56e211f6 | 166 | # Install Pandaboard MLO and uboot first |
a649b645 | 167 | ifeq "$(BUILD_ARCH)" "armv5tel" |
9831c245 | 168 | cp -v /boot/MLO $(MNThdd)/boot/ |
7284262a | 169 | cp -v /boot/u-boot.img $(MNThdd)/boot/ |
9831c245 AF |
170 | sync |
171 | umount $(MNThdd)/boot | |
c42cbc86 | 172 | mount $(PART_BOOT) $(MNThdd)/boot |
9831c245 AF |
173 | endif |
174 | ||
52ca8220 | 175 | # Install IPFire |
dc7d6b20 | 176 | ifneq "$(BUILD_PLATFORM)" "arm" |
c061d66f | 177 | tar -x --xz -C $(MNThdd)/ -f /install/cdrom/distro.img |
9b35b114 AF |
178 | else |
179 | tar -x -C $(MNThdd)/ -f /install/cdrom/distro.img | |
180 | endif | |
185f92e1 | 181 | -touch $(MNThdd)/lib/modules/$(KVER)-ipfire/modules.dep |
52ca8220 AF |
182 | mkdir $(MNThdd)/proc |
183 | mount --bind /proc $(MNThdd)/proc | |
184 | mount --bind /dev $(MNThdd)/dev | |
185 | mount --bind /sys $(MNThdd)/sys | |
c42cbc86 | 186 | |
52ca8220 | 187 | chroot $(MNThdd) /usr/bin/perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang" |
c42cbc86 MT |
188 | |
189 | # Create /etc/fstab | |
190 | printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_BOOT))" "/boot" \ | |
191 | "auto" "defaults" 1 2 > $(MNThdd)/etc/fstab | |
784cd5cb MT |
192 | ifeq "$(EFI)" "1" |
193 | printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_EFI))" "/boot/efi" \ | |
194 | "auto" "defaults" 1 2 >> $(MNThdd)/etc/fstab | |
195 | endif | |
c42cbc86 MT |
196 | printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_ROOT))" "/" \ |
197 | "auto" "defaults" 1 1 >> $(MNThdd)/etc/fstab | |
edc2be70 | 198 | |
c42cbc86 | 199 | ifeq "$(BOOTLOADER)" "grub" |
6b566244 AF |
200 | # backup defaults file |
201 | cp $(MNThdd)/etc/default/grub $(MNThdd)/etc/default/grub.backup | |
202 | ||
203 | # Enable also serial console on GRUB | |
204 | echo "GRUB_TERMINAL=\"serial console\"" >> $(MNThdd)/etc/default/grub | |
c42cbc86 | 205 | echo "GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=115200\"" >> $(MNThdd)/etc/default/grub |
52ca8220 | 206 | |
6b566244 AF |
207 | # Add additional entry for Serial console |
208 | cp $(DIR_SRC)/config/flash-images/grub/11_linux_scon \ | |
209 | $(MNThdd)/etc/grub.d/ | |
dfc4bc56 | 210 | |
c42cbc86 | 211 | # Create configuration |
784cd5cb MT |
212 | for i in $(GRUB_CFGS); do \ |
213 | mkdir -pv $$(dirname $(MNThdd)$(GRUB_CFG)); \ | |
214 | chroot $(MNThdd) grub-mkconfig -o $$i || exit 1; \ | |
215 | done | |
9831c245 | 216 | |
1f2a90b5 MT |
217 | # Boot the first kernel by default |
218 | chroot $(MNThdd) grub-set-default 0 | |
219 | ||
38956241 AF |
220 | # Insert the UUID because grub-mkconfig often fails to |
221 | # detect that correctly | |
784cd5cb | 222 | sed -i $(addprefix $(MNThdd),$(GRUB_CFGS)) \ |
c42cbc86 | 223 | sed -i $(MNThdd)/boot/grub/grub.cfg \ |
efd02229 | 224 | -e "s/root=[A-Za-z0-9\/=-]*/root=UUID=$$(blkid -o value -s UUID $(PART_ROOT))/g" |
52ca8220 | 225 | |
c42cbc86 | 226 | # Install GRUB |
5021ee33 | 227 | grub-install --force --recheck --no-floppy --target=i386-pc \ |
c42cbc86 | 228 | --root-directory=$(MNThdd) $(DEVICE) |
6b566244 AF |
229 | |
230 | # restore orginal defaults | |
231 | mv -f $(MNThdd)/etc/default/grub.backup $(MNThdd)/etc/default/grub | |
232 | rm -f $(MNThdd)/etc/grub.d/11_linux_scon | |
784cd5cb MT |
233 | |
234 | ifeq "$(EFI)" "1" | |
235 | mkdir -pv $(MNThdd)/boot/efi/EFI/boot | |
236 | cp -vf $(MNThdd)/boot/efi/EFI/ipfire/grub-efi/grub.efi \ | |
7fbbd2ae | 237 | $(MNThdd)/boot/efi/EFI/boot/boot$(EFI_ARCH).efi |
784cd5cb | 238 | endif |
185f92e1 | 239 | endif |
52ca8220 | 240 | |
920f1950 AF |
241 | # Set ramdisk mode to automatic |
242 | echo RAMDISK_MODE=2 > $(MNThdd)/etc/sysconfig/ramdisk | |
243 | ||
a2454679 MT |
244 | # Automatically resize the root partition to its maximum size at first boot |
245 | touch $(MNThdd)/.partresize | |
246 | ||
c42cbc86 MT |
247 | # Unmount |
248 | umount $(MNThdd)/proc | |
249 | umount $(MNThdd)/sys | |
250 | umount $(MNThdd)/dev | |
784cd5cb MT |
251 | ifeq "$(EFI)" "1" |
252 | umount $(MNThdd)/boot/efi | |
253 | endif | |
52ca8220 AF |
254 | umount $(MNThdd)/boot |
255 | umount $(MNThdd) | |
256 | ||
c42cbc86 | 257 | # zerofree the ext2 images to get better compression |
8a5ef45f | 258 | ifneq "$(PART_TYPE)" "c" |
c42cbc86 MT |
259 | zerofree $(PART_BOOT) |
260 | -fsck.ext2 -f -y $(PART_BOOT) | |
261 | fsck.ext2 -f -y $(PART_BOOT) | |
185f92e1 | 262 | endif |
c42cbc86 MT |
263 | zerofree $(PART_ROOT) |
264 | -fsck.ext4 -f -y $(PART_ROOT) | |
265 | fsck.ext4 -f -y $(PART_ROOT) | |
dfc4bc56 | 266 | |
e0b9a600 | 267 | sleep 10 #Ubuntu compiling: allow time to automount/dismount |
c42cbc86 MT |
268 | kpartx -d -v $(DEVICE) |
269 | losetup -d $(DEVICE) | |
52ca8220 | 270 | |
7051d2af MT |
271 | # Add padding at the end of the image (to fix alignment issues if the image is |
272 | # not copied to a block device) | |
273 | dd if=/dev/zero bs=1M count=$(PADDING) >> $(IMG) | |
274 | ||
a649b645 | 275 | ifeq "$(BUILD_ARCH)" "armv5tel" |
0a21d63f AF |
276 | # Install u-boot for Orangepi Zero/Nanopi DUO into image 8KB |
277 | dd if=/usr/share/u-boot/orangepi_zero/u-boot-sunxi-with-spl.bin of=$(IMG) bs=1K seek=8 conv=notrunc | |
56e211f6 AF |
278 | endif |
279 | ||
52ca8220 | 280 | # Compress Image |
b302b9a6 | 281 | xz $(XZ_OPT) < $(IMG) > $(IMAGE_FILE) |
c42cbc86 | 282 | rm -rf $(IMG) $(MNThdd) |