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