1 ###############################################################################
3 # IPFire.org - A linux based firewall #
4 # Copyright (C) 2007-2012 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 ###############################################################################
34 ###############################################################################
44 ###############################################################################
45 # Installation Details
46 ###############################################################################
47 IMGinst := /install/images/$(SNAME)-$(VERSION).1gb-ext4.$(MACHINE)-full-core$(CORE).img
48 IMGinsts := /install/images/$(SNAME)-$(VERSION).1gb-ext4-scon.$(MACHINE)-full-core$(CORE).img
49 MNThdd := /install/harddisk
50 IMGpart := /install/images/part_area
51 IMGboot := /install/images/bootfs
52 IMGroot := /install/images/rootfs
55 ifeq "$(MACHINE_TYPE)" "arm"
67 # /boot: 64MB - OFFSET
69 S_BOOT := $(shell echo $$(( 131072 - $(S_OFFSET) )))
72 $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
73 rm -rf $(MNThdd) $(IMGinst) $(IMGpart) $(IMGboot) $(IMGroot) && mkdir -p $(MNThdd)
75 # Create first 32 sectors of image
76 dd if=/dev/zero of=$(IMGpart) bs=512 count=$(S_OFFSET)
78 # Create images for filesystems
79 dd if=/dev/zero of=$(IMGboot) bs=512 count=$(S_BOOT)
80 dd if=/dev/zero of=$(IMGroot) bs=512 count=$(S_ROOT)
83 ifeq "$(PART_TYPE)" "c"
86 mkfs.ext2 -F $(IMGboot)
88 mkfs.ext4 -O ^has_journal,extent -F $(IMGroot)
90 # Most systems that use Flashimages has no RTC at boot
91 # so the interval check should disables
92 tune2fs -i0 $(IMGroot)
95 mount -o loop $(IMGroot) $(MNThdd)
98 mkdir $(MNThdd)/var/log
99 mount -o loop $(IMGboot) $(MNThdd)/boot
101 # Install MLO and uboot first
102 ifeq "$(MACHINE_TYPE)" "arm"
103 cp -v /boot/MLO $(MNThdd)/boot/
104 cp -v /boot/u-boot.img $(MNThdd)/boot/
105 cp -v /boot/zImage-ipfire-multi $(MNThdd)/boot/
107 umount $(MNThdd)/boot
108 mount -o loop $(IMGboot) $(MNThdd)/boot
112 tar -C $(MNThdd)/ -xvaf /install/cdrom/$(SNAME)-$(VERSION).tlz
113 echo "LANGUAGE=en" >> $(MNThdd)/var/ipfire/main/settings
114 echo "HOSTNAME=$(SNAME)" >> $(MNThdd)/var/ipfire/main/settings
115 echo "THEME=ipfire" >> $(MNThdd)/var/ipfire/main/settings
116 -touch $(MNThdd)/lib/modules/$(KVER)-ipfire/modules.dep
118 mount --bind /proc $(MNThdd)/proc
119 mount --bind /dev $(MNThdd)/dev
120 mount --bind /sys $(MNThdd)/sys
121 chroot $(MNThdd) /usr/bin/perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
122 sed -i -e "s|DEVICE1|UUID=$$(blkid -sUUID $(IMGboot) | cut -d'"' -f2)|g" $(MNThdd)/etc/fstab
123 ifeq "$(PART_TYPE)" "c"
124 # ARM flash images have a VFAT partition for /boot.
125 sed -i -e "s|ext2|vfat|" $(MNThdd)/etc/fstab
127 sed -i -e "s|DEVICE2|#DEVICE2|g" $(MNThdd)/etc/fstab
128 sed -i -e "s|DEVICE3|UUID=$$(blkid -sUUID $(IMGroot) | cut -d'"' -f2)|g" $(MNThdd)/etc/fstab
129 sed -i -e "s|DEVICE4|#DEVICE4|g" $(MNThdd)/etc/fstab
130 sed -i -e "s|FSTYPE|ext4|g" $(MNThdd)/etc/fstab
132 ifneq "$(MACHINE_TYPE)" "arm"
133 sed -i -e "s|MOUNT|ro|g" $(MNThdd)/boot/grub/grub.conf
134 sed -i -e "s|KVER|$(KVER)|g" $(MNThdd)/boot/grub/grub.conf
135 sed -i -e "s|ROOT|UUID=$$(blkid -sUUID $(IMGroot) | cut -d'"' -f2)|g" $(MNThdd)/boot/grub/grub.conf
136 ln -s grub.conf $(MNThdd)/boot/grub/menu.lst
138 # Copy grub files manually
139 cp -f $(MNThdd)/usr/lib/grub/i386-pc/* $(MNThdd)/boot/grub/
142 # Setup symlink for partresize at first boot...
143 ln -sf ../init.d/partresize $(MNThdd)/etc/rc.d/rcsysinit.d/S25partresize
144 # Setup symlink for fsresize at second boot...
145 ln -sf ../init.d/fsresize $(MNThdd)/etc/rc.d/rcsysinit.d/S42fsresize
148 umount $(MNThdd)/proc
151 umount $(MNThdd)/boot
154 # zerofree the ext2 images to get better compression
155 ifneq "$(PART_TYPE)" "c"
157 -fsck.ext2 -f -y $(IMGboot)
158 fsck.ext2 -f -y $(IMGboot)
161 -fsck.ext4 -f -y $(IMGroot)
162 fsck.ext4 -f -y $(IMGroot)
165 cat $(IMGpart) $(IMGboot) $(IMGroot) > $(IMGinst)
167 # Write Partition table
168 echo -e "$(S_OFFSET),$(S_BOOT),$(PART_TYPE),*\n,0,0\n$$(( $(S_BOOT) + $(S_OFFSET) )),$(S_ROOT),L\n,0,0\n" \
169 | sfdisk -D -uS -H 64 -S 32 $(IMGinst)
171 ifneq "$(MACHINE_TYPE)" "arm"
173 echo "device (hd0) $(IMGinst)" > /tmp/grubinst.tmp
174 echo "root (hd0,0)" >> /tmp/grubinst.tmp
175 echo "setup (hd0)" >> /tmp/grubinst.tmp
176 echo "quit" >> /tmp/grubinst.tmp
177 grub < /tmp/grubinst.tmp
178 rm -f /tmp/grubinst.tmp
184 # Now Build serialcon Version
186 mount -o loop $(IMGroot) $(MNThdd)
187 mount -o loop $(IMGboot) $(MNThdd)/boot
189 ifneq "$(MACHINE_TYPE)" "arm"
190 sed -i -e "s|splashimage|#splashimage|g" $(MNThdd)/boot/grub/grub.conf
191 sed -i -e "s|#serial|serial|g" $(MNThdd)/boot/grub/grub.conf
192 sed -i -e "s|#terminal|terminal|g" $(MNThdd)/boot/grub/grub.conf
193 sed -i -e "s| panic=10 | console=ttyS0,115200n8 panic=10 |g" $(MNThdd)/boot/grub/grub.conf
195 sed -i -e "s| console=tty1 | console=ttyAMA0,115200n8 |g" $(MNThdd)/boot/cmdline.txt
196 sed -i -e "s| console=tty1 | console=ttyO2,115200n8 |g" $(MNThdd)/boot/boot.script
197 cd $(MNThdd)/boot && ./convert_bootscript
200 sed -i -e "s|1:2345:respawn:|#1:2345:respawn:|g" $(MNThdd)/etc/inittab
201 sed -i -e "s|2:2345:respawn:|#2:2345:respawn:|g" $(MNThdd)/etc/inittab
202 sed -i -e "s|3:2345:respawn:|#3:2345:respawn:|g" $(MNThdd)/etc/inittab
203 sed -i -e "s|4:2345:respawn:|#4:2345:respawn:|g" $(MNThdd)/etc/inittab
204 sed -i -e "s|5:2345:respawn:|#5:2345:respawn:|g" $(MNThdd)/etc/inittab
205 sed -i -e "s|6:2345:respawn:|#6:2345:respawn:|g" $(MNThdd)/etc/inittab
206 sed -i -e "s|#7:2345:respawn:|7:2345:respawn:|g" $(MNThdd)/etc/inittab
208 umount $(MNThdd)/boot
211 # zerofree the ext3 images to get better compression
212 ifneq "$(PART_TYPE)" "c"
214 -fsck.ext2 -f -y $(IMGboot)
215 fsck.ext2 -f -y $(IMGboot)
218 -fsck.ext4 -f -y $(IMGroot)
219 fsck.ext4 -f -y $(IMGroot)
222 cat $(IMGpart) $(IMGboot) $(IMGroot) > $(IMGinsts)
223 rm -vf $(IMGpart) $(IMGboot) $(IMGroot)
225 # Write Partition table
226 echo -e "$(S_OFFSET),$(S_BOOT),$(PART_TYPE),*\n,0,0\n$$(( $(S_BOOT) + $(S_OFFSET) )),$(S_ROOT),L\n,0,0\n" \
227 | sfdisk -D -uS -H 64 -S 32 $(IMGinsts)
229 ifneq "$(MACHINE_TYPE)" "arm"
231 echo "device (hd0) $(IMGinsts)" > /tmp/grubinst.tmp
232 echo "root (hd0,0)" >> /tmp/grubinst.tmp
233 echo "setup (hd0)" >> /tmp/grubinst.tmp
234 echo "quit" >> /tmp/grubinst.tmp
235 grub < /tmp/grubinst.tmp
236 rm -f /tmp/grubinst.tmp
242 rm -rf $(MNThdd) $(IMGpart) $(IMGboot) $(IMGroot)