]> git.ipfire.org Git - ipfire-2.x.git/blob - lfs/flash-images
Enable EFI on x86_64
[ipfire-2.x.git] / lfs / flash-images
1 ###############################################################################
2 # #
3 # IPFire.org - A linux based firewall #
4 # Copyright (C) 2007-2018 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 ifeq "$(MACHINE)" "x86_64"
33 EFI = 1
34 endif
35
36 ifeq "$(MACHINE)" "i586"
37 EFI = 1
38 endif
39
40 DEVICE = $(shell losetup -f)
41 PART_BOOT = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p1
42 ifeq "$(EFI)" "1"
43 PART_EFI = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p2
44 endif
45 PART_ROOT = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p3
46
47 IMAGE_FILE = /install/images/$(SNAME)-$(VERSION).2gb-ext4.$(BUILD_ARCH)-full-core$(CORE).img.xz
48
49 FSTAB_FMT = UUID=%s %-8s %-4s %-10s %d %d\n
50
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 ###############################################################################
66 MNThdd := /install/harddisk
67 IMG := /install/images/image.img
68
69 # All sizes in blocks
70 ifeq "$(BUILD_PLATFORM)" "arm"
71 BOOTLOADER =
72 S_OFFSET = 8192
73
74 # FAT32
75 PART_TYPE = c
76 else
77 BOOTLOADER = grub
78 S_OFFSET = 8192
79
80 # Logical
81 PART_TYPE = L
82 endif
83
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
93 # /boot: 128MB - OFFSET
94 # / : 1200 MB
95 S_BOOT := $(shell echo $$(( 262144 - $(S_OFFSET) )))
96 S_ROOT := 2477600
97
98 ifeq "$(MACHINE)" "x86_64"
99 EFI_ARCH = x64
100 endif
101
102 ifeq "$(MACHINE)" "i586"
103 EFI_ARCH = ia32
104 endif
105
106 PADDING = 100 # MB
107
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
119 $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
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
126 dd if=/dev/zero of=$(IMG) bs=512 count=$$(( $(S_OFFSET) + $(S_BOOT) + $(S_EFI) + $(S_ROOT) ))
127 losetup $(DEVICE) $(IMG)
128
129 # Write Partition table
130 echo -e "$(SFDISK)" | sfdisk -uS $(DEVICE)
131
132 # Remove 2nd empty partition
133 ifneq "$(EFI)" "1"
134 -echo -e "d\n2\nw\n\q\n" | fdisk $(DEVICE)
135 endif
136
137 kpartx -v -a $(DEVICE)
138
139 # Format them
140 ifeq "$(PART_TYPE)" "c"
141 mkfs.vfat $(PART_BOOT)
142 else
143 mkfs.ext2 -F $(PART_BOOT)
144 endif
145 ifeq "$(EFI)" "1"
146 mkfs.vfat $(PART_EFI)
147 endif
148 mkfs.ext4 -O ^has_journal,extent -F $(PART_ROOT)
149
150 # Most systems that use Flashimages has no RTC at boot
151 # so the interval check should disables
152 tune2fs -i0 $(PART_ROOT)
153
154 # Mount root partition
155 mount $(PART_ROOT) $(MNThdd)
156
157 # Mount boot partition
158 mkdir -pv $(MNThdd)/boot
159 mount $(PART_BOOT) $(MNThdd)/boot
160
161 ifeq "$(EFI)" "1"
162 mkdir -pv $(MNThdd)/boot/efi
163 mount $(PART_EFI) $(MNThdd)/boot/efi
164 endif
165
166 # Install Pandaboard MLO and uboot first
167 ifeq "$(BUILD_ARCH)" "armv5tel"
168 cp -v /boot/MLO $(MNThdd)/boot/
169 cp -v /boot/u-boot.img $(MNThdd)/boot/
170 sync
171 umount $(MNThdd)/boot
172 mount $(PART_BOOT) $(MNThdd)/boot
173 endif
174
175 # Install IPFire
176 ifneq "$(BUILD_PLATFORM)" "arm"
177 tar -x --xz -C $(MNThdd)/ -f /install/cdrom/distro.img
178 else
179 tar -x -C $(MNThdd)/ -f /install/cdrom/distro.img
180 endif
181 -touch $(MNThdd)/lib/modules/$(KVER)-ipfire/modules.dep
182 mkdir $(MNThdd)/proc
183 mount --bind /proc $(MNThdd)/proc
184 mount --bind /dev $(MNThdd)/dev
185 mount --bind /sys $(MNThdd)/sys
186
187 chroot $(MNThdd) /usr/bin/perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
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
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
196 printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_ROOT))" "/" \
197 "auto" "defaults" 1 1 >> $(MNThdd)/etc/fstab
198
199 ifeq "$(BOOTLOADER)" "grub"
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
205 echo "GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=115200\"" >> $(MNThdd)/etc/default/grub
206
207 # Add additional entry for Serial console
208 cp $(DIR_SRC)/config/flash-images/grub/11_linux_scon \
209 $(MNThdd)/etc/grub.d/
210
211 # Create configuration
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
216
217 # Boot the first kernel by default
218 chroot $(MNThdd) grub-set-default 0
219
220 # Insert the UUID because grub-mkconfig often fails to
221 # detect that correctly
222 sed -i $(addprefix $(MNThdd),$(GRUB_CFGS)) \
223 sed -i $(MNThdd)/boot/grub/grub.cfg \
224 -e "s/root=[A-Za-z0-9\/=-]*/root=UUID=$$(blkid -o value -s UUID $(PART_ROOT))/g"
225
226 # Install GRUB
227 grub-install --force --recheck --no-floppy --target=i386-pc \
228 --root-directory=$(MNThdd) $(DEVICE)
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
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 \
237 $(MNThdd)/boot/efi/EFI/boot/boot$(EFI_ARCH).efi
238 endif
239 endif
240
241 # Set ramdisk mode to automatic
242 echo RAMDISK_MODE=2 > $(MNThdd)/etc/sysconfig/ramdisk
243
244 # Automatically resize the root partition to its maximum size at first boot
245 touch $(MNThdd)/.partresize
246
247 # Unmount
248 umount $(MNThdd)/proc
249 umount $(MNThdd)/sys
250 umount $(MNThdd)/dev
251 ifeq "$(EFI)" "1"
252 umount $(MNThdd)/boot/efi
253 endif
254 umount $(MNThdd)/boot
255 umount $(MNThdd)
256
257 # zerofree the ext2 images to get better compression
258 ifneq "$(PART_TYPE)" "c"
259 zerofree $(PART_BOOT)
260 -fsck.ext2 -f -y $(PART_BOOT)
261 fsck.ext2 -f -y $(PART_BOOT)
262 endif
263 zerofree $(PART_ROOT)
264 -fsck.ext4 -f -y $(PART_ROOT)
265 fsck.ext4 -f -y $(PART_ROOT)
266
267 sleep 10 #Ubuntu compiling: allow time to automount/dismount
268 kpartx -d -v $(DEVICE)
269 losetup -d $(DEVICE)
270
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
275 ifeq "$(BUILD_ARCH)" "armv5tel"
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
278 endif
279
280 # Compress Image
281 xz $(XZ_OPT) < $(IMG) > $(IMAGE_FILE)
282 rm -rf $(IMG) $(MNThdd)