Files
bpfire/lfs/flash-images
2014-04-30 09:21:31 +02:00

243 lines
8.4 KiB
Plaintext

###############################################################################
# #
# IPFire.org - A linux based firewall #
# Copyright (C) 2007-2012 IPFire Team <info@ipfire.org> #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
###############################################################################
###############################################################################
# Definitions
###############################################################################
include Config
VER = ipfire
THISAPP = flash-image
TARGET = $(DIR_INFO)/$(THISAPP)
###############################################################################
# Top-level Rules
###############################################################################
install : $(TARGET)
check :
download :
md5 :
###############################################################################
# Installation Details
###############################################################################
IMGinst := /install/images/$(SNAME)-$(VERSION).1gb-ext4.$(MACHINE)-full-core$(CORE).img
IMGinsts := /install/images/$(SNAME)-$(VERSION).1gb-ext4-scon.$(MACHINE)-full-core$(CORE).img
MNThdd := /install/harddisk
IMGpart := /install/images/part_area
IMGboot := /install/images/bootfs
IMGroot := /install/images/rootfs
# All sizes in blocks
ifeq "$(MACHINE_TYPE)" "arm"
S_OFFSET = 8192
# FAT32
PART_TYPE = c
else
S_OFFSET = 32
# Logical
PART_TYPE = L
endif
# /boot: 64MB - OFFSET
# / : 700MB
S_BOOT := $(shell echo $$(( 131072 - $(S_OFFSET) )))
S_ROOT := 1433600
$(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
rm -rf $(MNThdd) $(IMGinst) $(IMGpart) $(IMGboot) $(IMGroot) && mkdir -p $(MNThdd)
# Create first 32 sectors of image
dd if=/dev/zero of=$(IMGpart) bs=512 count=$(S_OFFSET)
# Create images for filesystems
dd if=/dev/zero of=$(IMGboot) bs=512 count=$(S_BOOT)
dd if=/dev/zero of=$(IMGroot) bs=512 count=$(S_ROOT)
# Format them
ifeq "$(PART_TYPE)" "c"
mkfs.vfat $(IMGboot)
else
mkfs.ext2 -F $(IMGboot)
endif
mkfs.ext4 -O ^has_journal,extent -F $(IMGroot)
# Most systems that use Flashimages has no RTC at boot
# so the interval check should disables
tune2fs -i0 $(IMGroot)
# Mount Images
mount -o loop $(IMGroot) $(MNThdd)
mkdir $(MNThdd)/boot
mkdir $(MNThdd)/var
mkdir $(MNThdd)/var/log
mount -o loop $(IMGboot) $(MNThdd)/boot
# Install MLO and uboot first
ifeq "$(MACHINE_TYPE)" "arm"
cp -v /boot/MLO $(MNThdd)/boot/
cp -v /boot/u-boot.img $(MNThdd)/boot/
cp -v /boot/zImage-ipfire-multi $(MNThdd)/boot/
sync
umount $(MNThdd)/boot
mount -o loop $(IMGboot) $(MNThdd)/boot
endif
# Install IPFire
tar -C $(MNThdd)/ -xvaf /install/cdrom/$(SNAME)-$(VERSION).tlz
echo "LANGUAGE=en" >> $(MNThdd)/var/ipfire/main/settings
echo "HOSTNAME=$(SNAME)" >> $(MNThdd)/var/ipfire/main/settings
echo "THEME=ipfire" >> $(MNThdd)/var/ipfire/main/settings
-touch $(MNThdd)/lib/modules/$(KVER)-ipfire/modules.dep
mkdir $(MNThdd)/proc
mount --bind /proc $(MNThdd)/proc
mount --bind /dev $(MNThdd)/dev
mount --bind /sys $(MNThdd)/sys
chroot $(MNThdd) /usr/bin/perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
sed -i -e "s|DEVICE1|UUID=$$(blkid -sUUID $(IMGboot) | cut -d'"' -f2)|g" $(MNThdd)/etc/fstab
ifeq "$(PART_TYPE)" "c"
# ARM flash images have a VFAT partition for /boot.
sed -i -e "s|ext2|vfat|" $(MNThdd)/etc/fstab
endif
sed -i -e "s|DEVICE2|#DEVICE2|g" $(MNThdd)/etc/fstab
sed -i -e "s|DEVICE3|UUID=$$(blkid -sUUID $(IMGroot) | cut -d'"' -f2)|g" $(MNThdd)/etc/fstab
sed -i -e "s|DEVICE4|#DEVICE4|g" $(MNThdd)/etc/fstab
sed -i -e "s|FSTYPE|ext4|g" $(MNThdd)/etc/fstab
ifneq "$(MACHINE_TYPE)" "arm"
sed -i -e "s|MOUNT|ro|g" $(MNThdd)/boot/grub/grub.conf
sed -i -e "s|KVER|$(KVER)|g" $(MNThdd)/boot/grub/grub.conf
sed -i -e "s|ROOT|UUID=$$(blkid -sUUID $(IMGroot) | cut -d'"' -f2)|g" $(MNThdd)/boot/grub/grub.conf
ln -s grub.conf $(MNThdd)/boot/grub/menu.lst
# Copy grub files manually
cp -f $(MNThdd)/usr/lib/grub/i386-pc/* $(MNThdd)/boot/grub/
endif
# Setup symlink for partresize at first boot...
ln -sf ../init.d/partresize $(MNThdd)/etc/rc.d/rcsysinit.d/S25partresize
# Setup symlink for fsresize at second boot...
ln -sf ../init.d/fsresize $(MNThdd)/etc/rc.d/rcsysinit.d/S42fsresize
# Unmount
umount $(MNThdd)/proc
umount $(MNThdd)/dev
umount $(MNThdd)/sys
umount $(MNThdd)/boot
umount $(MNThdd)
# zerofree the ext2 images to get better compression
ifneq "$(PART_TYPE)" "c"
zerofree $(IMGboot)
-fsck.ext2 -f -y $(IMGboot)
fsck.ext2 -f -y $(IMGboot)
endif
zerofree $(IMGroot)
-fsck.ext4 -f -y $(IMGroot)
fsck.ext4 -f -y $(IMGroot)
# Cat to an image
cat $(IMGpart) $(IMGboot) $(IMGroot) > $(IMGinst)
# Write Partition table
echo -e "$(S_OFFSET),$(S_BOOT),$(PART_TYPE),*\n,0,0\n$$(( $(S_BOOT) + $(S_OFFSET) )),$(S_ROOT),L\n,0,0\n" \
| sfdisk -D -uS -H 64 -S 32 $(IMGinst)
ifneq "$(MACHINE_TYPE)" "arm"
# Install grub
echo "device (hd0) $(IMGinst)" > /tmp/grubinst.tmp
echo "root (hd0,0)" >> /tmp/grubinst.tmp
echo "setup (hd0)" >> /tmp/grubinst.tmp
echo "quit" >> /tmp/grubinst.tmp
grub < /tmp/grubinst.tmp
rm -f /tmp/grubinst.tmp
endif
# Compress Image
gzip -f9 $(IMGinst)
# Now Build serialcon Version
# Mount Images
mount -o loop $(IMGroot) $(MNThdd)
mount -o loop $(IMGboot) $(MNThdd)/boot
ifneq "$(MACHINE_TYPE)" "arm"
sed -i -e "s|splashimage|#splashimage|g" $(MNThdd)/boot/grub/grub.conf
sed -i -e "s|#serial|serial|g" $(MNThdd)/boot/grub/grub.conf
sed -i -e "s|#terminal|terminal|g" $(MNThdd)/boot/grub/grub.conf
sed -i -e "s| panic=10 | console=ttyS0,115200n8 panic=10 |g" $(MNThdd)/boot/grub/grub.conf
else
sed -i -e "s| console=tty1 | console=ttyAMA0,115200n8 |g" $(MNThdd)/boot/cmdline.txt
sed -i -e "s| console=tty1 | console=ttyO2,115200n8 |g" $(MNThdd)/boot/boot.script
cd $(MNThdd)/boot && ./convert_bootscript
endif
sed -i -e "s|1:2345:respawn:|#1:2345:respawn:|g" $(MNThdd)/etc/inittab
sed -i -e "s|2:2345:respawn:|#2:2345:respawn:|g" $(MNThdd)/etc/inittab
sed -i -e "s|3:2345:respawn:|#3:2345:respawn:|g" $(MNThdd)/etc/inittab
sed -i -e "s|4:2345:respawn:|#4:2345:respawn:|g" $(MNThdd)/etc/inittab
sed -i -e "s|5:2345:respawn:|#5:2345:respawn:|g" $(MNThdd)/etc/inittab
sed -i -e "s|6:2345:respawn:|#6:2345:respawn:|g" $(MNThdd)/etc/inittab
sed -i -e "s|#7:2345:respawn:|7:2345:respawn:|g" $(MNThdd)/etc/inittab
umount $(MNThdd)/boot
umount $(MNThdd)
# zerofree the ext3 images to get better compression
ifneq "$(PART_TYPE)" "c"
zerofree $(IMGboot)
-fsck.ext2 -f -y $(IMGboot)
fsck.ext2 -f -y $(IMGboot)
endif
zerofree $(IMGroot)
-fsck.ext4 -f -y $(IMGroot)
fsck.ext4 -f -y $(IMGroot)
# Cat to an image
cat $(IMGpart) $(IMGboot) $(IMGroot) > $(IMGinsts)
rm -vf $(IMGpart) $(IMGboot) $(IMGroot)
# Write Partition table
echo -e "$(S_OFFSET),$(S_BOOT),$(PART_TYPE),*\n,0,0\n$$(( $(S_BOOT) + $(S_OFFSET) )),$(S_ROOT),L\n,0,0\n" \
| sfdisk -D -uS -H 64 -S 32 $(IMGinsts)
ifneq "$(MACHINE_TYPE)" "arm"
# Install grub
echo "device (hd0) $(IMGinsts)" > /tmp/grubinst.tmp
echo "root (hd0,0)" >> /tmp/grubinst.tmp
echo "setup (hd0)" >> /tmp/grubinst.tmp
echo "quit" >> /tmp/grubinst.tmp
grub < /tmp/grubinst.tmp
rm -f /tmp/grubinst.tmp
endif
# Compress Image
gzip -f9 $(IMGinsts)
rm -rf $(MNThdd) $(IMGpart) $(IMGboot) $(IMGroot)