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