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