]>
Commit | Line | Data |
---|---|---|
52ca8220 AF |
1 | ############################################################################### |
2 | # # | |
3 | # IPFire.org - A linux based firewall # | |
919eb671 | 4 | # Copyright (C) 2007-2012 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 | |
34 | PART_ROOT = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p2 | |
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 | |
72cdb517 | 78 | # / : 700MB |
8a5ef45f | 79 | S_BOOT := $(shell echo $$(( 131072 - $(S_OFFSET) ))) |
72cdb517 | 80 | S_ROOT := 1433600 |
52ca8220 AF |
81 | |
82 | $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) | |
c42cbc86 MT |
83 | # Stop if $(MNThdd) is still mounted |
84 | mountpoint $(MNThdd) && exit 1 || exit 0 | |
85 | ||
86 | rm -rf $(IMG) $(MNThdd) && mkdir -p $(MNThdd) | |
87 | ||
88 | # Allocate image on disk | |
89 | dd if=/dev/zero of=$(IMG) bs=512 count=$$(( $(S_OFFSET) + $(S_BOOT) + $(S_ROOT) )) | |
90 | losetup $(DEVICE) $(IMG) | |
52ca8220 | 91 | |
c42cbc86 MT |
92 | # Write Partition table |
93 | echo -e "$(S_OFFSET),$(S_BOOT),$(PART_TYPE),*\n$$(( $(S_BOOT) + $(S_OFFSET) )),$(S_ROOT),L\n" \ | |
94 | | sfdisk -D -uS -H 64 -S 32 $(DEVICE) | |
52ca8220 | 95 | |
c42cbc86 | 96 | kpartx -v -a $(DEVICE) |
52ca8220 AF |
97 | |
98 | # Format them | |
8a5ef45f | 99 | ifeq "$(PART_TYPE)" "c" |
c42cbc86 | 100 | mkfs.vfat $(PART_BOOT) |
185f92e1 | 101 | else |
c42cbc86 | 102 | mkfs.ext2 -F $(PART_BOOT) |
185f92e1 | 103 | endif |
c42cbc86 | 104 | mkfs.ext4 -O ^has_journal,extent -F $(PART_ROOT) |
52ca8220 | 105 | |
e9b5c815 AF |
106 | # Most systems that use Flashimages has no RTC at boot |
107 | # so the interval check should disables | |
c42cbc86 MT |
108 | tune2fs -i0 $(PART_ROOT) |
109 | ||
110 | # Mount root partition | |
111 | mount $(PART_ROOT) $(MNThdd) | |
e9b5c815 | 112 | |
c42cbc86 MT |
113 | # Mount boot partition |
114 | mkdir -pv $(MNThdd)/boot | |
115 | mount $(PART_BOOT) $(MNThdd)/boot | |
52ca8220 | 116 | |
9831c245 AF |
117 | # Install MLO and uboot first |
118 | ifeq "$(MACHINE_TYPE)" "arm" | |
119 | cp -v /boot/MLO $(MNThdd)/boot/ | |
7284262a | 120 | cp -v /boot/u-boot.img $(MNThdd)/boot/ |
906d293b | 121 | cp -v /boot/zImage-ipfire-multi $(MNThdd)/boot/ |
9831c245 AF |
122 | sync |
123 | umount $(MNThdd)/boot | |
c42cbc86 | 124 | mount $(PART_BOOT) $(MNThdd)/boot |
9831c245 AF |
125 | endif |
126 | ||
52ca8220 | 127 | # Install IPFire |
c42cbc86 MT |
128 | tar -x --lzma -C $(MNThdd)/ -f /install/cdrom/distro.img |
129 | ||
6fafd272 AF |
130 | echo "LANGUAGE=en" >> $(MNThdd)/var/ipfire/main/settings |
131 | echo "HOSTNAME=$(SNAME)" >> $(MNThdd)/var/ipfire/main/settings | |
132 | echo "THEME=ipfire" >> $(MNThdd)/var/ipfire/main/settings | |
c42cbc86 MT |
133 | |
134 | ifeq "$(SCON)" "1" | |
135 | # Enable serial console | |
136 | sed -i -e "s|1:2345:respawn:|#1:2345:respawn:|g" $(MNThdd)/etc/inittab | |
137 | sed -i -e "s|2:2345:respawn:|#2:2345:respawn:|g" $(MNThdd)/etc/inittab | |
138 | sed -i -e "s|3:2345:respawn:|#3:2345:respawn:|g" $(MNThdd)/etc/inittab | |
139 | sed -i -e "s|4:2345:respawn:|#4:2345:respawn:|g" $(MNThdd)/etc/inittab | |
140 | sed -i -e "s|5:2345:respawn:|#5:2345:respawn:|g" $(MNThdd)/etc/inittab | |
141 | sed -i -e "s|6:2345:respawn:|#6:2345:respawn:|g" $(MNThdd)/etc/inittab | |
142 | sed -i -e "s|#7:2345:respawn:|7:2345:respawn:|g" $(MNThdd)/etc/inittab | |
143 | ||
144 | ifeq "$(MACHINE_TYPE)" "arm" | |
145 | sed -i -e "s| console=tty1 | console=ttyAMA0,115200n8 |g" $(MNThdd)/boot/cmdline.txt | |
146 | sed -i -e "s| console=tty1 | console=ttyO2,115200n8 |g" $(MNThdd)/boot/boot.script | |
147 | cd $(MNThdd)/boot && ./convert_bootscript | |
148 | endif | |
149 | endif | |
150 | ||
185f92e1 | 151 | -touch $(MNThdd)/lib/modules/$(KVER)-ipfire/modules.dep |
52ca8220 AF |
152 | mkdir $(MNThdd)/proc |
153 | mount --bind /proc $(MNThdd)/proc | |
154 | mount --bind /dev $(MNThdd)/dev | |
155 | mount --bind /sys $(MNThdd)/sys | |
c42cbc86 | 156 | |
52ca8220 | 157 | chroot $(MNThdd) /usr/bin/perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang" |
c42cbc86 MT |
158 | |
159 | # Create /etc/fstab | |
160 | printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_BOOT))" "/boot" \ | |
161 | "auto" "defaults" 1 2 > $(MNThdd)/etc/fstab | |
162 | printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_ROOT))" "/" \ | |
163 | "auto" "defaults" 1 1 >> $(MNThdd)/etc/fstab | |
edc2be70 | 164 | |
a6d0d790 AF |
165 | # Setup symlink for partresize at first boot... |
166 | ln -sf ../init.d/partresize $(MNThdd)/etc/rc.d/rcsysinit.d/S25partresize | |
167 | # Setup symlink for fsresize at second boot... | |
3e011c27 | 168 | ln -sf ../init.d/fsresize $(MNThdd)/etc/rc.d/rcsysinit.d/S42fsresize |
a6d0d790 | 169 | |
c42cbc86 MT |
170 | ifeq "$(BOOTLOADER)" "grub" |
171 | ifeq "$(SCON)" "1" | |
172 | # Enable serial console on GRUB | |
173 | echo "GRUB_TERMINAL=\"serial console\"" >> $(MNThdd)/etc/default/grub | |
174 | echo "GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=115200\"" >> $(MNThdd)/etc/default/grub | |
52ca8220 | 175 | |
c42cbc86 | 176 | sed -i -e "s|panic=10|& console=ttyS0,115200n8|g" $(MNThdd)/etc/default/grub |
185f92e1 | 177 | endif |
dfc4bc56 | 178 | |
c42cbc86 MT |
179 | # Create configuration |
180 | mkdir -pv $(MNThdd)/boot/grub | |
181 | chroot $(MNThdd) grub-mkconfig -o /boot/grub/grub.cfg | |
9831c245 | 182 | |
c42cbc86 MT |
183 | # Insert the UUID because grub-mkconfig fails to detect that correctly |
184 | sed -i $(MNThdd)/boot/grub/grub.cfg \ | |
185 | -e "s/root=[a-z0-9\/]*/root=UUID=$$(blkid -o value -s UUID $(PART_ROOT))/g" | |
52ca8220 | 186 | |
c42cbc86 MT |
187 | # Install GRUB |
188 | grub-install --force --recheck --no-floppy \ | |
189 | --root-directory=$(MNThdd) $(DEVICE) | |
185f92e1 | 190 | endif |
52ca8220 | 191 | |
c42cbc86 MT |
192 | # Unmount |
193 | umount $(MNThdd)/proc | |
194 | umount $(MNThdd)/sys | |
195 | umount $(MNThdd)/dev | |
52ca8220 AF |
196 | umount $(MNThdd)/boot |
197 | umount $(MNThdd) | |
198 | ||
c42cbc86 | 199 | # zerofree the ext2 images to get better compression |
8a5ef45f | 200 | ifneq "$(PART_TYPE)" "c" |
c42cbc86 MT |
201 | zerofree $(PART_BOOT) |
202 | -fsck.ext2 -f -y $(PART_BOOT) | |
203 | fsck.ext2 -f -y $(PART_BOOT) | |
185f92e1 | 204 | endif |
c42cbc86 MT |
205 | zerofree $(PART_ROOT) |
206 | -fsck.ext4 -f -y $(PART_ROOT) | |
207 | fsck.ext4 -f -y $(PART_ROOT) | |
dfc4bc56 | 208 | |
c42cbc86 MT |
209 | kpartx -d -v $(DEVICE) |
210 | losetup -d $(DEVICE) | |
52ca8220 AF |
211 | |
212 | # Compress Image | |
c42cbc86 MT |
213 | pigz -f9 < $(IMG) > $(IMAGE_FILE) |
214 | rm -rf $(IMG) $(MNThdd) |