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
35 PART_EFI = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p2
37 PART_ROOT = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p3
39 IMAGE_FILE = /install/images/$(SNAME)-$(VERSION).2gb-ext4.$(BUILD_ARCH)-full-core$(CORE).img.xz
41 FSTAB_FMT = UUID=%s %-8s %-4s %-10s %d %d\n
43 ###############################################################################
45 ###############################################################################
55 ###############################################################################
56 # Installation Details
57 ###############################################################################
58 MNThdd := /install/harddisk
59 IMG := /install/images/image.img
62 ifeq "$(BUILD_PLATFORM)" "arm"
82 # /boot: 128MB - OFFSET
84 S_BOOT := $(shell echo $$(( 262144 - $(S_OFFSET) )))
90 SFDISK_EFI = $(S_OFFSET),$(S_EFI),U,*\n
91 SFDISK = $(SFDISK_BOOT)$(SFDISK_EFI)$(SFDISK_ROOT)
94 SFDISK = $(SFDISK_BOOT)$(SFDISK_SWAP)$(SFDISK_ROOT)
97 SFDISK_BOOT = $(shell echo $$(( $(S_OFFSET) + $(S_EFI) ))),$(S_BOOT),$(PART_TYPE)\n
98 SFDISK_ROOT = $(shell echo $$(( $(S_OFFSET) + $(S_EFI) + $(S_BOOT) ))),$(S_ROOT),L\n
100 $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
101 # Stop if $(MNThdd) is still mounted
102 mountpoint $(MNThdd) && exit 1 || exit 0
104 rm -rf $(IMG) $(MNThdd) && mkdir -p $(MNThdd)
106 # Allocate image on disk
107 dd if=/dev/zero of=$(IMG) bs=512 count=$$(( $(S_OFFSET) + $(S_BOOT) + $(S_EFI) + $(S_ROOT) ))
108 losetup $(DEVICE) $(IMG)
110 # Write Partition table
111 echo -e "$(SFDISK)" | sfdisk -uS $(DEVICE)
113 # Remove 2nd empty partition
115 -echo -e "d\n2\nw\n\q\n" | fdisk $(DEVICE)
118 kpartx -v -a $(DEVICE)
121 ifeq "$(PART_TYPE)" "c"
122 mkfs.vfat $(PART_BOOT)
124 mkfs.ext2 -F $(PART_BOOT)
127 mkfs.vfat $(PART_EFI)
129 mkfs.ext4 -O ^has_journal,extent -F $(PART_ROOT)
131 # Most systems that use Flashimages has no RTC at boot
132 # so the interval check should disables
133 tune2fs -i0 $(PART_ROOT)
135 # Mount root partition
136 mount $(PART_ROOT) $(MNThdd)
138 # Mount boot partition
139 mkdir -pv $(MNThdd)/boot
140 mount $(PART_BOOT) $(MNThdd)/boot
143 mkdir -pv $(MNThdd)/boot/efi
144 mount $(PART_EFI) $(MNThdd)/boot/efi
147 # Install Pandaboard MLO and uboot first
148 ifeq "$(BUILD_ARCH)" "armv5tel"
149 cp -v /boot/MLO $(MNThdd)/boot/
150 cp -v /boot/u-boot.img $(MNThdd)/boot/
152 umount $(MNThdd)/boot
153 mount $(PART_BOOT) $(MNThdd)/boot
157 ifneq "$(BUILD_PLATFORM)" "arm"
158 tar -x --xz -C $(MNThdd)/ -f /install/cdrom/distro.img
160 tar -x -C $(MNThdd)/ -f /install/cdrom/distro.img
162 -touch $(MNThdd)/lib/modules/$(KVER)-ipfire/modules.dep
164 mount --bind /proc $(MNThdd)/proc
165 mount --bind /dev $(MNThdd)/dev
166 mount --bind /sys $(MNThdd)/sys
168 chroot $(MNThdd) /usr/bin/perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
171 printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_BOOT))" "/boot" \
172 "auto" "defaults" 1 2 > $(MNThdd)/etc/fstab
174 printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_EFI))" "/boot/efi" \
175 "auto" "defaults" 1 2 >> $(MNThdd)/etc/fstab
177 printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_ROOT))" "/" \
178 "auto" "defaults" 1 1 >> $(MNThdd)/etc/fstab
180 ifeq "$(BOOTLOADER)" "grub"
181 # backup defaults file
182 cp $(MNThdd)/etc/default/grub $(MNThdd)/etc/default/grub.backup
184 # Enable also serial console on GRUB
185 echo "GRUB_TERMINAL=\"serial console\"" >> $(MNThdd)/etc/default/grub
186 echo "GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=115200\"" >> $(MNThdd)/etc/default/grub
188 # Add additional entry for Serial console
189 cp $(DIR_SRC)/config/flash-images/grub/11_linux_scon \
190 $(MNThdd)/etc/grub.d/
192 # Create configuration
193 mkdir -pv $(MNThdd)/boot/grub
194 chroot $(MNThdd) grub-mkconfig -o /boot/grub/grub.cfg
196 # Boot the first kernel by default
197 chroot $(MNThdd) grub-set-default 0
199 # Insert the UUID because grub-mkconfig often fails to
200 # detect that correctly
201 sed -i $(MNThdd)/boot/grub/grub.cfg \
202 -e "s/root=[A-Za-z0-9\/=-]*/root=UUID=$$(blkid -o value -s UUID $(PART_ROOT))/g"
205 grub-install --force --recheck --no-floppy --target=i386-pc \
206 --root-directory=$(MNThdd) $(DEVICE)
209 # Install GRUB for EFI
210 grub-install --target=$(BUILD_ARCH)-efi --removable --no-nvram \
211 --boot-directory=$(MNThdd)/boot --efi-directory=$(MNThdd)/boot/efi
214 # restore orginal defaults
215 mv -f $(MNThdd)/etc/default/grub.backup $(MNThdd)/etc/default/grub
216 rm -f $(MNThdd)/etc/grub.d/11_linux_scon
219 # Set ramdisk mode to automatic
220 echo RAMDISK_MODE=2 > $(MNThdd)/etc/sysconfig/ramdisk
222 # Automatically resize the root partition to its maximum size at first boot
223 touch $(MNThdd)/.partresize
226 umount $(MNThdd)/proc
230 umount $(MNThdd)/boot/efi
232 umount $(MNThdd)/boot
235 # zerofree the ext2 images to get better compression
236 ifneq "$(PART_TYPE)" "c"
237 zerofree $(PART_BOOT)
238 -fsck.ext2 -f -y $(PART_BOOT)
239 fsck.ext2 -f -y $(PART_BOOT)
241 zerofree $(PART_ROOT)
242 -fsck.ext4 -f -y $(PART_ROOT)
243 fsck.ext4 -f -y $(PART_ROOT)
245 sleep 10 #Ubuntu compiling: allow time to automount/dismount
246 kpartx -d -v $(DEVICE)
249 # Add padding at the end of the image (to fix alignment issues if the image is
250 # not copied to a block device)
251 dd if=/dev/zero bs=1M count=$(PADDING) >> $(IMG)
253 ifeq "$(BUILD_ARCH)" "armv5tel"
254 # Install u-boot for Orangepi Zero/Nanopi DUO into image 8KB
255 dd if=/usr/share/u-boot/orangepi_zero/u-boot-sunxi-with-spl.bin of=$(IMG) bs=1K seek=8 conv=notrunc
259 xz $(XZ_OPT) < $(IMG) > $(IMAGE_FILE)
260 rm -rf $(IMG) $(MNThdd)