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 DEVICE = $(shell losetup -f)
33 PART_BOOT = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p1
34 PART_ROOT = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p3
37 IMAGE_FILE = /install/images/$(SNAME)-$(VERSION).2gb-ext4-scon.$(BUILD_ARCH)-full-core$(CORE).img.gz
39 IMAGE_FILE = /install/images/$(SNAME)-$(VERSION).2gb-ext4.$(BUILD_ARCH)-full-core$(CORE).img.gz
42 FSTAB_FMT = UUID=%s %-8s %-4s %-10s %d %d\n
44 ###############################################################################
46 ###############################################################################
56 ###############################################################################
57 # Installation Details
58 ###############################################################################
59 MNThdd := /install/harddisk
60 IMG := /install/images/image.img
63 ifeq "$(BUILD_PLATFORM)" "arm"
77 # /boot: 100MB - OFFSET
79 S_BOOT := $(shell echo $$(( 204800 - $(S_OFFSET) )))
84 $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
85 # Stop if $(MNThdd) is still mounted
86 mountpoint $(MNThdd) && exit 1 || exit 0
88 rm -rf $(IMG) $(MNThdd) && mkdir -p $(MNThdd)
90 # Allocate image on disk
91 dd if=/dev/zero of=$(IMG) bs=512 count=$$(( $(S_OFFSET) + $(S_BOOT) + $(S_ROOT) ))
92 losetup $(DEVICE) $(IMG)
94 # Write Partition table
95 echo -e "$(S_OFFSET),$(S_BOOT),$(PART_TYPE),*\n,0,0\n$$(( $(S_BOOT) + $(S_OFFSET) )),$(S_ROOT),L\n" \
96 | sfdisk -uS $(DEVICE)
97 -echo -e "d\n2\nw\n\q\n" | fdisk $(DEVICE)
99 kpartx -v -a $(DEVICE)
102 ifeq "$(PART_TYPE)" "c"
103 mkfs.vfat $(PART_BOOT)
105 mkfs.ext2 -F $(PART_BOOT)
107 mkfs.ext4 -O ^has_journal,extent -F $(PART_ROOT)
109 # Most systems that use Flashimages has no RTC at boot
110 # so the interval check should disables
111 tune2fs -i0 $(PART_ROOT)
113 # Mount root partition
114 mount $(PART_ROOT) $(MNThdd)
116 # Mount boot partition
117 mkdir -pv $(MNThdd)/boot
118 mount $(PART_BOOT) $(MNThdd)/boot
120 # Install Pandaboard MLO and uboot first
121 ifeq "$(BUILD_PLATFORM)" "arm"
122 cp -v /boot/MLO $(MNThdd)/boot/
123 cp -v /boot/u-boot.img $(MNThdd)/boot/
125 umount $(MNThdd)/boot
126 mount $(PART_BOOT) $(MNThdd)/boot
130 ifneq "$(BUILD_PLATFORM)" "arm"
131 tar -x --xz -C $(MNThdd)/ -f /install/cdrom/distro.img
133 tar -x -C $(MNThdd)/ -f /install/cdrom/distro.img
135 echo "LANGUAGE=en" >> $(MNThdd)/var/ipfire/main/settings
136 echo "HOSTNAME=$(SNAME)" >> $(MNThdd)/var/ipfire/main/settings
137 echo "THEME=ipfire" >> $(MNThdd)/var/ipfire/main/settings
140 # Disable console on tty2-6
141 sed -i -e "s|2:2345:respawn:|#2:2345:respawn:|g" $(MNThdd)/etc/inittab
142 sed -i -e "s|3:2345:respawn:|#3:2345:respawn:|g" $(MNThdd)/etc/inittab
143 sed -i -e "s|4:2345:respawn:|#4:2345:respawn:|g" $(MNThdd)/etc/inittab
144 sed -i -e "s|5:2345:respawn:|#5:2345:respawn:|g" $(MNThdd)/etc/inittab
145 sed -i -e "s|6:2345:respawn:|#6:2345:respawn:|g" $(MNThdd)/etc/inittab
147 ifeq "$(BUILD_PLATFORM)" "arm"
148 sed -i -e "s|SERIAL-CONSOLE=OFF|SERIAL-CONSOLE=ON|g" $(MNThdd)/boot/uEnv.txt
149 sed -i -e "s|xxxDTBSUNXIxxx|sun8i-h2-plus-ipfire-nano.dtb|" $(MNThdd)/boot/uEnv.txt
152 ifeq "$(BUILD_PLATFORM)" "arm"
153 sed -i -e "s|xxxDTBSUNXIxxx|sun7i-a20-bananapi.dtb|" $(MNThdd)/boot/uEnv.txt
157 -touch $(MNThdd)/lib/modules/$(KVER)-ipfire/modules.dep
159 mount --bind /proc $(MNThdd)/proc
160 mount --bind /dev $(MNThdd)/dev
161 mount --bind /sys $(MNThdd)/sys
163 chroot $(MNThdd) /usr/bin/perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
166 printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_BOOT))" "/boot" \
167 "auto" "defaults" 1 2 > $(MNThdd)/etc/fstab
168 printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_ROOT))" "/" \
169 "auto" "defaults" 1 1 >> $(MNThdd)/etc/fstab
171 ifeq "$(BOOTLOADER)" "grub"
173 # Enable serial console on GRUB
174 echo "GRUB_TERMINAL=\"serial\"" >> $(MNThdd)/etc/default/grub
175 echo "GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=115200\"" >> $(MNThdd)/etc/default/grub
177 sed -i -e "s|panic=10|& console=ttyS0,115200n8|g" $(MNThdd)/etc/default/grub
180 # Create configuration
181 mkdir -pv $(MNThdd)/boot/grub
182 chroot $(MNThdd) grub-mkconfig -o /boot/grub/grub.cfg
184 # Insert the UUID because grub-mkconfig often fails to
185 # detect that correctly
186 sed -i $(MNThdd)/boot/grub/grub.cfg \
187 -e "s/root=[A-Za-z0-9\/=-]*/root=UUID=$$(blkid -o value -s UUID $(PART_ROOT))/g"
190 grub-install --force --recheck --no-floppy --target=i386-pc \
191 --root-directory=$(MNThdd) $(DEVICE)
194 # Set ramdisk mode to automatic
195 echo RAMDISK_MODE=2 > $(MNThdd)/etc/sysconfig/ramdisk
197 # Automatically resize the root partition to its maximum size at first boot
198 touch $(MNThdd)/.partresize
201 umount $(MNThdd)/proc
204 umount $(MNThdd)/boot
207 # zerofree the ext2 images to get better compression
208 ifneq "$(PART_TYPE)" "c"
209 zerofree $(PART_BOOT)
210 -fsck.ext2 -f -y $(PART_BOOT)
211 fsck.ext2 -f -y $(PART_BOOT)
213 zerofree $(PART_ROOT)
214 -fsck.ext4 -f -y $(PART_ROOT)
215 fsck.ext4 -f -y $(PART_ROOT)
217 sleep 10 #Ubuntu compiling: allow time to automount/dismount
218 kpartx -d -v $(DEVICE)
221 # Add padding at the end of the image (to fix alignment issues if the image is
222 # not copied to a block device)
223 dd if=/dev/zero bs=1M count=$(PADDING) >> $(IMG)
225 ifeq "$(BUILD_PLATFORM)" "arm"
227 # Install u-boot for Orangepi Zero/Nanopi DUO into image 8KB
228 dd if=/usr/share/u-boot/orangepi_zero/u-boot-sunxi-with-spl.bin of=$(IMG) bs=1K seek=8 conv=notrunc
230 # Install u-boot for LeMaker Banana Pi into image 8KB
231 dd if=/usr/share/u-boot/banana_pi/u-boot-sunxi-with-spl.bin of=$(IMG) bs=1K seek=8 conv=notrunc
236 pigz -f9 < $(IMG) > $(IMAGE_FILE)
237 rm -rf $(IMG) $(MNThdd)