1 ###############################################################################
3 # IPFire.org - A linux based firewall #
4 # Copyright (C) 2007-2018 IPFire Team <info@ipfire.org> #
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. #
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. #
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/>. #
19 ###############################################################################
21 ###############################################################################
23 ###############################################################################
30 TARGET = $(DIR_INFO)/$(THISAPP)
32 ifeq "$(MACHINE)" "x86_64"
36 ifeq "$(MACHINE)" "i586"
40 DEVICE = $(shell losetup -f)
41 PART_BOOT = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p1
43 PART_EFI = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p2
45 PART_ROOT = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p3
47 IMAGE_FILE = /install/images/$(SNAME)-$(VERSION).2gb-ext4.$(BUILD_ARCH)-full-core$(CORE).img.xz
49 FSTAB_FMT = UUID=%s %-8s %-4s %-10s %d %d\n
51 ###############################################################################
53 ###############################################################################
63 ###############################################################################
64 # Installation Details
65 ###############################################################################
66 MNThdd := /install/harddisk
67 IMG := /install/images/image.img
70 ifeq "$(BUILD_PLATFORM)" "arm"
84 GRUB_CFGS = /boot/grub/grub.cfg
88 GRUB_CFGS += /boot/efi/EFI/ipfire/grub-efi/grub.cfg
93 # /boot: 128MB - OFFSET
95 S_BOOT := $(shell echo $$(( 262144 - $(S_OFFSET) )))
98 ifeq "$(MACHINE)" "x86_64"
102 ifeq "$(MACHINE)" "i586"
109 SFDISK_EFI = $(S_OFFSET),$(S_EFI),c,*\n
110 SFDISK = $(SFDISK_BOOT)$(SFDISK_EFI)$(SFDISK_ROOT)
113 SFDISK = $(SFDISK_BOOT)$(SFDISK_SWAP)$(SFDISK_ROOT)
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
119 $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
120 # Stop if $(MNThdd) is still mounted
121 mountpoint $(MNThdd) && exit 1 || exit 0
123 rm -rf $(IMG) $(MNThdd) && mkdir -p $(MNThdd)
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)
129 # Write Partition table
130 echo -e "$(SFDISK)" | sfdisk -uS $(DEVICE)
132 # Remove 2nd empty partition
134 -echo -e "d\n2\nw\n\q\n" | fdisk $(DEVICE)
137 kpartx -v -a $(DEVICE)
140 ifeq "$(PART_TYPE)" "c"
141 mkfs.vfat $(PART_BOOT)
143 mkfs.ext2 -F $(PART_BOOT)
146 mkfs.vfat $(PART_EFI)
148 mkfs.ext4 -O ^has_journal,extent -F $(PART_ROOT)
150 # Most systems that use Flashimages has no RTC at boot
151 # so the interval check should disables
152 tune2fs -i0 $(PART_ROOT)
154 # Mount root partition
155 mount $(PART_ROOT) $(MNThdd)
157 # Mount boot partition
158 mkdir -pv $(MNThdd)/boot
159 mount $(PART_BOOT) $(MNThdd)/boot
162 mkdir -pv $(MNThdd)/boot/efi
163 mount $(PART_EFI) $(MNThdd)/boot/efi
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/
171 umount $(MNThdd)/boot
172 mount $(PART_BOOT) $(MNThdd)/boot
176 ifneq "$(BUILD_PLATFORM)" "arm"
177 tar -x --xz -C $(MNThdd)/ -f /install/cdrom/distro.img
179 tar -x -C $(MNThdd)/ -f /install/cdrom/distro.img
181 -touch $(MNThdd)/lib/modules/$(KVER)-ipfire/modules.dep
183 mount --bind /proc $(MNThdd)/proc
184 mount --bind /dev $(MNThdd)/dev
185 mount --bind /sys $(MNThdd)/sys
187 chroot $(MNThdd) /usr/bin/perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
190 printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_BOOT))" "/boot" \
191 "auto" "defaults" 1 2 > $(MNThdd)/etc/fstab
193 printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_EFI))" "/boot/efi" \
194 "auto" "defaults" 1 2 >> $(MNThdd)/etc/fstab
196 printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_ROOT))" "/" \
197 "auto" "defaults" 1 1 >> $(MNThdd)/etc/fstab
199 ifeq "$(BOOTLOADER)" "grub"
200 # backup defaults file
201 cp $(MNThdd)/etc/default/grub $(MNThdd)/etc/default/grub.backup
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
207 # Add additional entry for Serial console
208 cp $(DIR_SRC)/config/flash-images/grub/11_linux_scon \
209 $(MNThdd)/etc/grub.d/
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; \
217 # Boot the first kernel by default
218 chroot $(MNThdd) grub-set-default 0
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"
227 grub-install --force --recheck --no-floppy --target=i386-pc \
228 --root-directory=$(MNThdd) $(DEVICE)
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
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
241 # Set ramdisk mode to automatic
242 echo RAMDISK_MODE=2 > $(MNThdd)/etc/sysconfig/ramdisk
244 # Automatically resize the root partition to its maximum size at first boot
245 touch $(MNThdd)/.partresize
248 umount $(MNThdd)/proc
252 umount $(MNThdd)/boot/efi
254 umount $(MNThdd)/boot
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)
263 zerofree $(PART_ROOT)
264 -fsck.ext4 -f -y $(PART_ROOT)
265 fsck.ext4 -f -y $(PART_ROOT)
267 sleep 10 #Ubuntu compiling: allow time to automount/dismount
268 kpartx -d -v $(DEVICE)
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)
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
281 xz $(XZ_OPT) < $(IMG) > $(IMAGE_FILE)
282 rm -rf $(IMG) $(MNThdd)