]>
Commit | Line | Data |
---|---|---|
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 | PART_ROOT = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p3 | |
35 | ||
36 | IMAGE_FILE = /install/images/$(SNAME)-$(VERSION).2gb-ext4.$(BUILD_ARCH)-full-core$(CORE).img.xz | |
37 | ||
38 | FSTAB_FMT = UUID=%s %-8s %-4s %-10s %d %d\n | |
39 | ||
40 | ############################################################################### | |
41 | # Top-level Rules | |
42 | ############################################################################### | |
43 | ||
44 | install : $(TARGET) | |
45 | ||
46 | check : | |
47 | ||
48 | download : | |
49 | ||
50 | md5 : | |
51 | ||
52 | ############################################################################### | |
53 | # Installation Details | |
54 | ############################################################################### | |
55 | MNThdd := /install/harddisk | |
56 | IMG := /install/images/image.img | |
57 | ||
58 | # All sizes in blocks | |
59 | ifeq "$(BUILD_PLATFORM)" "arm" | |
60 | BOOTLOADER = | |
61 | S_OFFSET = 8192 | |
62 | ||
63 | # FAT32 | |
64 | PART_TYPE = c | |
65 | else | |
66 | BOOTLOADER = grub | |
67 | S_OFFSET = 8192 | |
68 | ||
69 | # Logical | |
70 | PART_TYPE = L | |
71 | endif | |
72 | ||
73 | # /boot: 100MB - OFFSET | |
74 | # / : 1200 MB | |
75 | S_BOOT := $(shell echo $$(( 204800 - $(S_OFFSET) ))) | |
76 | S_ROOT := 2477600 | |
77 | ||
78 | PADDING = 100 # MB | |
79 | ||
80 | $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) | |
81 | # Stop if $(MNThdd) is still mounted | |
82 | mountpoint $(MNThdd) && exit 1 || exit 0 | |
83 | ||
84 | rm -rf $(IMG) $(MNThdd) && mkdir -p $(MNThdd) | |
85 | ||
86 | # Allocate image on disk | |
87 | dd if=/dev/zero of=$(IMG) bs=512 count=$$(( $(S_OFFSET) + $(S_BOOT) + $(S_ROOT) )) | |
88 | losetup $(DEVICE) $(IMG) | |
89 | ||
90 | # Write Partition table | |
91 | echo -e "$(S_OFFSET),$(S_BOOT),$(PART_TYPE),*\n,0,0\n$$(( $(S_BOOT) + $(S_OFFSET) )),$(S_ROOT),L\n" \ | |
92 | | sfdisk -uS $(DEVICE) | |
93 | -echo -e "d\n2\nw\n\q\n" | fdisk $(DEVICE) | |
94 | ||
95 | kpartx -v -a $(DEVICE) | |
96 | ||
97 | # Format them | |
98 | ifeq "$(PART_TYPE)" "c" | |
99 | mkfs.vfat $(PART_BOOT) | |
100 | else | |
101 | mkfs.ext2 -F $(PART_BOOT) | |
102 | endif | |
103 | mkfs.ext4 -O ^has_journal,extent -F $(PART_ROOT) | |
104 | ||
105 | # Most systems that use Flashimages has no RTC at boot | |
106 | # so the interval check should disables | |
107 | tune2fs -i0 $(PART_ROOT) | |
108 | ||
109 | # Mount root partition | |
110 | mount $(PART_ROOT) $(MNThdd) | |
111 | ||
112 | # Mount boot partition | |
113 | mkdir -pv $(MNThdd)/boot | |
114 | mount $(PART_BOOT) $(MNThdd)/boot | |
115 | ||
116 | # Install Pandaboard MLO and uboot first | |
117 | ifeq "$(BUILD_PLATFORM)" "arm" | |
118 | cp -v /boot/MLO $(MNThdd)/boot/ | |
119 | cp -v /boot/u-boot.img $(MNThdd)/boot/ | |
120 | sync | |
121 | umount $(MNThdd)/boot | |
122 | mount $(PART_BOOT) $(MNThdd)/boot | |
123 | endif | |
124 | ||
125 | # Install IPFire | |
126 | ifneq "$(BUILD_PLATFORM)" "arm" | |
127 | tar -x --xz -C $(MNThdd)/ -f /install/cdrom/distro.img | |
128 | else | |
129 | tar -x -C $(MNThdd)/ -f /install/cdrom/distro.img | |
130 | endif | |
131 | echo "LANGUAGE=en" >> $(MNThdd)/var/ipfire/main/settings | |
132 | echo "HOSTNAME=$(SNAME)" >> $(MNThdd)/var/ipfire/main/settings | |
133 | echo "THEME=ipfire" >> $(MNThdd)/var/ipfire/main/settings | |
134 | ||
135 | -touch $(MNThdd)/lib/modules/$(KVER)-ipfire/modules.dep | |
136 | mkdir $(MNThdd)/proc | |
137 | mount --bind /proc $(MNThdd)/proc | |
138 | mount --bind /dev $(MNThdd)/dev | |
139 | mount --bind /sys $(MNThdd)/sys | |
140 | ||
141 | chroot $(MNThdd) /usr/bin/perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang" | |
142 | ||
143 | # Create /etc/fstab | |
144 | printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_BOOT))" "/boot" \ | |
145 | "auto" "defaults" 1 2 > $(MNThdd)/etc/fstab | |
146 | printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_ROOT))" "/" \ | |
147 | "auto" "defaults" 1 1 >> $(MNThdd)/etc/fstab | |
148 | ||
149 | ifeq "$(BOOTLOADER)" "grub" | |
150 | # backup defaults file | |
151 | cp $(MNThdd)/etc/default/grub $(MNThdd)/etc/default/grub.backup | |
152 | ||
153 | # Enable also serial console on GRUB | |
154 | echo "GRUB_TERMINAL=\"serial console\"" >> $(MNThdd)/etc/default/grub | |
155 | echo "GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=115200\"" >> $(MNThdd)/etc/default/grub | |
156 | echo "GRUB_TIMEOUT=-1" >> $(MNThdd)/etc/default/grub | |
157 | ||
158 | # Add additional entry for Serial console | |
159 | cp $(DIR_SRC)/config/flash-images/grub/11_linux_scon \ | |
160 | $(MNThdd)/etc/grub.d/ | |
161 | ||
162 | # Create configuration | |
163 | mkdir -pv $(MNThdd)/boot/grub | |
164 | chroot $(MNThdd) grub-mkconfig -o /boot/grub/grub.cfg | |
165 | ||
166 | # Insert the UUID because grub-mkconfig often fails to | |
167 | # detect that correctly | |
168 | sed -i $(MNThdd)/boot/grub/grub.cfg \ | |
169 | -e "s/root=[A-Za-z0-9\/=-]*/root=UUID=$$(blkid -o value -s UUID $(PART_ROOT))/g" | |
170 | ||
171 | # Install GRUB | |
172 | grub-install --force --recheck --no-floppy --target=i386-pc \ | |
173 | --root-directory=$(MNThdd) $(DEVICE) | |
174 | ||
175 | # restore orginal defaults | |
176 | mv -f $(MNThdd)/etc/default/grub.backup $(MNThdd)/etc/default/grub | |
177 | rm -f $(MNThdd)/etc/grub.d/11_linux_scon | |
178 | endif | |
179 | ||
180 | # Set ramdisk mode to automatic | |
181 | echo RAMDISK_MODE=2 > $(MNThdd)/etc/sysconfig/ramdisk | |
182 | ||
183 | # Automatically resize the root partition to its maximum size at first boot | |
184 | touch $(MNThdd)/.partresize | |
185 | ||
186 | # Unmount | |
187 | umount $(MNThdd)/proc | |
188 | umount $(MNThdd)/sys | |
189 | umount $(MNThdd)/dev | |
190 | umount $(MNThdd)/boot | |
191 | umount $(MNThdd) | |
192 | ||
193 | # zerofree the ext2 images to get better compression | |
194 | ifneq "$(PART_TYPE)" "c" | |
195 | zerofree $(PART_BOOT) | |
196 | -fsck.ext2 -f -y $(PART_BOOT) | |
197 | fsck.ext2 -f -y $(PART_BOOT) | |
198 | endif | |
199 | zerofree $(PART_ROOT) | |
200 | -fsck.ext4 -f -y $(PART_ROOT) | |
201 | fsck.ext4 -f -y $(PART_ROOT) | |
202 | ||
203 | sleep 10 #Ubuntu compiling: allow time to automount/dismount | |
204 | kpartx -d -v $(DEVICE) | |
205 | losetup -d $(DEVICE) | |
206 | ||
207 | # Add padding at the end of the image (to fix alignment issues if the image is | |
208 | # not copied to a block device) | |
209 | dd if=/dev/zero bs=1M count=$(PADDING) >> $(IMG) | |
210 | ||
211 | ifeq "$(BUILD_PLATFORM)" "arm" | |
212 | # Install u-boot for Orangepi Zero/Nanopi DUO into image 8KB | |
213 | dd if=/usr/share/u-boot/orangepi_zero/u-boot-sunxi-with-spl.bin of=$(IMG) bs=1K seek=8 conv=notrunc | |
214 | endif | |
215 | ||
216 | # Compress Image | |
217 | xz $(XZ_OPT) < $(IMG) > $(IMAGE_FILE) | |
218 | rm -rf $(IMG) $(MNThdd) |