]>
Commit | Line | Data |
---|---|---|
52ca8220 AF |
1 | ############################################################################### |
2 | # # | |
3 | # IPFire.org - A linux based firewall # | |
efd02229 | 4 | # Copyright (C) 2007-2016 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 | ||
25 | include Config | |
26 | ||
27 | VER = ipfire | |
28 | ||
29 | THISAPP = flash-image | |
30 | TARGET = $(DIR_INFO)/$(THISAPP) | |
31 | ||
c42cbc86 MT |
32 | DEVICE = $(shell losetup -f) |
33 | PART_BOOT = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p1 | |
05656571 | 34 | PART_ROOT = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p3 |
c42cbc86 MT |
35 | |
36 | ifeq "$(SCON)" "1" | |
37 | IMAGE_FILE = /install/images/$(SNAME)-$(VERSION).1gb-ext4-scon.$(MACHINE)-full-core$(CORE).img.gz | |
38 | else | |
39 | IMAGE_FILE = /install/images/$(SNAME)-$(VERSION).1gb-ext4.$(MACHINE)-full-core$(CORE).img.gz | |
40 | endif | |
41 | ||
42 | FSTAB_FMT = UUID=%s %-8s %-4s %-10s %d %d\n | |
43 | ||
52ca8220 AF |
44 | ############################################################################### |
45 | # Top-level Rules | |
46 | ############################################################################### | |
47 | ||
48 | install : $(TARGET) | |
49 | ||
50 | check : | |
51 | ||
52 | download : | |
53 | ||
54 | md5 : | |
55 | ||
56 | ############################################################################### | |
57 | # Installation Details | |
58 | ############################################################################### | |
52ca8220 | 59 | MNThdd := /install/harddisk |
c42cbc86 | 60 | IMG := /install/images/image.img |
8a5ef45f SS |
61 | |
62 | # All sizes in blocks | |
63 | ifeq "$(MACHINE_TYPE)" "arm" | |
c42cbc86 | 64 | BOOTLOADER = |
8a5ef45f SS |
65 | S_OFFSET = 8192 |
66 | ||
67 | # FAT32 | |
68 | PART_TYPE = c | |
69 | else | |
c42cbc86 MT |
70 | BOOTLOADER = grub |
71 | S_OFFSET = 8192 | |
8a5ef45f SS |
72 | |
73 | # Logical | |
74 | PART_TYPE = L | |
75 | endif | |
76 | ||
77 | # /boot: 64MB - OFFSET | |
864a8eff | 78 | # / : 750MB |
8a5ef45f | 79 | S_BOOT := $(shell echo $$(( 131072 - $(S_OFFSET) ))) |
864a8eff | 80 | S_ROOT := 1536000 |
52ca8220 | 81 | |
7051d2af MT |
82 | PADDING = 100 # MB |
83 | ||
52ca8220 | 84 | $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) |
c42cbc86 MT |
85 | # Stop if $(MNThdd) is still mounted |
86 | mountpoint $(MNThdd) && exit 1 || exit 0 | |
87 | ||
88 | rm -rf $(IMG) $(MNThdd) && mkdir -p $(MNThdd) | |
89 | ||
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) | |
52ca8220 | 93 | |
c42cbc86 | 94 | # Write Partition table |
05656571 | 95 | echo -e "$(S_OFFSET),$(S_BOOT),$(PART_TYPE),*\n,0,0\n$$(( $(S_BOOT) + $(S_OFFSET) )),$(S_ROOT),L\n" \ |
c42cbc86 | 96 | | sfdisk -D -uS -H 64 -S 32 $(DEVICE) |
52ca8220 | 97 | |
c42cbc86 | 98 | kpartx -v -a $(DEVICE) |
52ca8220 AF |
99 | |
100 | # Format them | |
8a5ef45f | 101 | ifeq "$(PART_TYPE)" "c" |
c42cbc86 | 102 | mkfs.vfat $(PART_BOOT) |
185f92e1 | 103 | else |
c42cbc86 | 104 | mkfs.ext2 -F $(PART_BOOT) |
185f92e1 | 105 | endif |
c42cbc86 | 106 | mkfs.ext4 -O ^has_journal,extent -F $(PART_ROOT) |
52ca8220 | 107 | |
e9b5c815 AF |
108 | # Most systems that use Flashimages has no RTC at boot |
109 | # so the interval check should disables | |
c42cbc86 MT |
110 | tune2fs -i0 $(PART_ROOT) |
111 | ||
112 | # Mount root partition | |
113 | mount $(PART_ROOT) $(MNThdd) | |
e9b5c815 | 114 | |
c42cbc86 MT |
115 | # Mount boot partition |
116 | mkdir -pv $(MNThdd)/boot | |
117 | mount $(PART_BOOT) $(MNThdd)/boot | |
52ca8220 | 118 | |
56e211f6 | 119 | # Install Pandaboard MLO and uboot first |
9831c245 AF |
120 | ifeq "$(MACHINE_TYPE)" "arm" |
121 | cp -v /boot/MLO $(MNThdd)/boot/ | |
7284262a | 122 | cp -v /boot/u-boot.img $(MNThdd)/boot/ |
906d293b | 123 | cp -v /boot/zImage-ipfire-multi $(MNThdd)/boot/ |
4f472f86 AF |
124 | cp -v /boot/uInit-ipfire-multi $(MNThdd)/boot/ |
125 | cp -v /boot/uImage-ipfire-kirkwood $(MNThdd)/boot/ | |
126 | cp -v /boot/uInit-ipfire-kirkwood $(MNThdd)/boot/ | |
127 | cp -v /boot/uEnv.txt $(MNThdd)/boot/ | |
15094e71 AF |
128 | # work around a u-boot bug not find the folders sometimes |
129 | mkdir -pv $(MNThdd)/boot/dtb-$(KVER)-ipfire-multi | |
130 | mkdir -pv $(MNThdd)/boot/dtb-$(KVER)-ipfire-kirkwood | |
4f472f86 | 131 | |
9831c245 AF |
132 | sync |
133 | umount $(MNThdd)/boot | |
c42cbc86 | 134 | mount $(PART_BOOT) $(MNThdd)/boot |
9831c245 AF |
135 | endif |
136 | ||
52ca8220 | 137 | # Install IPFire |
9b35b114 | 138 | ifneq "$(MACHINE_TYPE)" "arm" |
c42cbc86 | 139 | tar -x --lzma -C $(MNThdd)/ -f /install/cdrom/distro.img |
9b35b114 AF |
140 | else |
141 | tar -x -C $(MNThdd)/ -f /install/cdrom/distro.img | |
142 | endif | |
6fafd272 AF |
143 | echo "LANGUAGE=en" >> $(MNThdd)/var/ipfire/main/settings |
144 | echo "HOSTNAME=$(SNAME)" >> $(MNThdd)/var/ipfire/main/settings | |
145 | echo "THEME=ipfire" >> $(MNThdd)/var/ipfire/main/settings | |
c42cbc86 MT |
146 | |
147 | ifeq "$(SCON)" "1" | |
148 | # Enable serial console | |
149 | sed -i -e "s|1:2345:respawn:|#1:2345:respawn:|g" $(MNThdd)/etc/inittab | |
150 | sed -i -e "s|2:2345:respawn:|#2:2345:respawn:|g" $(MNThdd)/etc/inittab | |
151 | sed -i -e "s|3:2345:respawn:|#3:2345:respawn:|g" $(MNThdd)/etc/inittab | |
152 | sed -i -e "s|4:2345:respawn:|#4:2345:respawn:|g" $(MNThdd)/etc/inittab | |
153 | sed -i -e "s|5:2345:respawn:|#5:2345:respawn:|g" $(MNThdd)/etc/inittab | |
154 | sed -i -e "s|6:2345:respawn:|#6:2345:respawn:|g" $(MNThdd)/etc/inittab | |
155 | sed -i -e "s|#7:2345:respawn:|7:2345:respawn:|g" $(MNThdd)/etc/inittab | |
156 | ||
157 | ifeq "$(MACHINE_TYPE)" "arm" | |
158 | sed -i -e "s| console=tty1 | console=ttyAMA0,115200n8 |g" $(MNThdd)/boot/cmdline.txt | |
56e211f6 | 159 | sed -i -e "s| console=tty1 | console=ttyO2,115200n8 |g" $(MNThdd)/boot/uEnv.txt |
c42cbc86 MT |
160 | endif |
161 | endif | |
162 | ||
185f92e1 | 163 | -touch $(MNThdd)/lib/modules/$(KVER)-ipfire/modules.dep |
52ca8220 AF |
164 | mkdir $(MNThdd)/proc |
165 | mount --bind /proc $(MNThdd)/proc | |
166 | mount --bind /dev $(MNThdd)/dev | |
167 | mount --bind /sys $(MNThdd)/sys | |
c42cbc86 | 168 | |
52ca8220 | 169 | chroot $(MNThdd) /usr/bin/perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang" |
c42cbc86 MT |
170 | |
171 | # Create /etc/fstab | |
172 | printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_BOOT))" "/boot" \ | |
173 | "auto" "defaults" 1 2 > $(MNThdd)/etc/fstab | |
174 | printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_ROOT))" "/" \ | |
175 | "auto" "defaults" 1 1 >> $(MNThdd)/etc/fstab | |
edc2be70 | 176 | |
c42cbc86 MT |
177 | ifeq "$(BOOTLOADER)" "grub" |
178 | ifeq "$(SCON)" "1" | |
179 | # Enable serial console on GRUB | |
7f6e0425 | 180 | echo "GRUB_TERMINAL=\"serial\"" >> $(MNThdd)/etc/default/grub |
c42cbc86 | 181 | echo "GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=115200\"" >> $(MNThdd)/etc/default/grub |
52ca8220 | 182 | |
c42cbc86 | 183 | sed -i -e "s|panic=10|& console=ttyS0,115200n8|g" $(MNThdd)/etc/default/grub |
185f92e1 | 184 | endif |
dfc4bc56 | 185 | |
c42cbc86 MT |
186 | # Create configuration |
187 | mkdir -pv $(MNThdd)/boot/grub | |
188 | chroot $(MNThdd) grub-mkconfig -o /boot/grub/grub.cfg | |
9831c245 | 189 | |
38956241 AF |
190 | # Insert the UUID because grub-mkconfig often fails to |
191 | # detect that correctly | |
c42cbc86 | 192 | sed -i $(MNThdd)/boot/grub/grub.cfg \ |
efd02229 | 193 | -e "s/root=[A-Za-z0-9\/=-]*/root=UUID=$$(blkid -o value -s UUID $(PART_ROOT))/g" |
52ca8220 | 194 | |
c42cbc86 MT |
195 | # Install GRUB |
196 | grub-install --force --recheck --no-floppy \ | |
197 | --root-directory=$(MNThdd) $(DEVICE) | |
185f92e1 | 198 | endif |
52ca8220 | 199 | |
920f1950 AF |
200 | # Set ramdisk mode to automatic |
201 | echo RAMDISK_MODE=2 > $(MNThdd)/etc/sysconfig/ramdisk | |
202 | ||
a2454679 MT |
203 | # Automatically resize the root partition to its maximum size at first boot |
204 | touch $(MNThdd)/.partresize | |
205 | ||
c42cbc86 MT |
206 | # Unmount |
207 | umount $(MNThdd)/proc | |
208 | umount $(MNThdd)/sys | |
209 | umount $(MNThdd)/dev | |
52ca8220 AF |
210 | umount $(MNThdd)/boot |
211 | umount $(MNThdd) | |
212 | ||
c42cbc86 | 213 | # zerofree the ext2 images to get better compression |
8a5ef45f | 214 | ifneq "$(PART_TYPE)" "c" |
c42cbc86 MT |
215 | zerofree $(PART_BOOT) |
216 | -fsck.ext2 -f -y $(PART_BOOT) | |
217 | fsck.ext2 -f -y $(PART_BOOT) | |
185f92e1 | 218 | endif |
c42cbc86 MT |
219 | zerofree $(PART_ROOT) |
220 | -fsck.ext4 -f -y $(PART_ROOT) | |
221 | fsck.ext4 -f -y $(PART_ROOT) | |
dfc4bc56 | 222 | |
e0b9a600 | 223 | sleep 10 #Ubuntu compiling: allow time to automount/dismount |
c42cbc86 MT |
224 | kpartx -d -v $(DEVICE) |
225 | losetup -d $(DEVICE) | |
52ca8220 | 226 | |
7051d2af MT |
227 | # Add padding at the end of the image (to fix alignment issues if the image is |
228 | # not copied to a block device) | |
229 | dd if=/dev/zero bs=1M count=$(PADDING) >> $(IMG) | |
230 | ||
56e211f6 AF |
231 | ifeq "$(MACHINE_TYPE)" "arm" |
232 | # Install u-boot for LeMaker Banana Pi into image 8KB | |
233 | dd if=/usr/share/u-boot/banana_pi/u-boot-sunxi-with-spl.bin of=$(IMG) bs=1K seek=8 conv=notrunc | |
234 | endif | |
235 | ||
52ca8220 | 236 | # Compress Image |
c42cbc86 MT |
237 | pigz -f9 < $(IMG) > $(IMAGE_FILE) |
238 | rm -rf $(IMG) $(MNThdd) |