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