Add xen-image build
[people/pmueller/ipfire-2.x.git] / lfs / xen-image
1 ###############################################################################
2 # #
3 # IPFire.org - A linux based firewall #
4 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
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 = xen-image
30 TARGET = $(DIR_INFO)/$(THISAPP)
31
32 ###############################################################################
33 # Top-level Rules
34 ###############################################################################
35
36 install : $(TARGET)
37
38 check :
39
40 download :
41
42 md5 :
43
44 ###############################################################################
45 # Installation Details
46 ###############################################################################
47 IMGinst := /install/images/$(SNAME)-$(VERSION).xen.$(MACHINE)-$(ED)-core$(CORE).tar.bz2
48 MNThdd := /install/harddisk
49
50 IMGroot := /install/images/$(SNAME)/$(SNAME).img
51 IMGswap := /install/images/$(SNAME)/swap.img
52 SIZEroot := 1024
53 SIZEswap := 512
54
55 $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
56 rm -rf $(MNThdd) $(IMGinst) $(IMGroot) && mkdir -p $(MNThdd)
57 mkdir -p /install/images/$(SNAME)/boot
58
59 #Create swapimage
60 dd bs=1M if=/dev/zero of=$(IMGswap) count=$(SIZEswap)
61 mkswap $(IMGswap)
62
63 #Create rootimage
64 dd bs=1M if=/dev/zero of=$(IMGroot) count=$(SIZEroot)
65 mkfs.ext3 -F $(IMGroot)
66
67 # Mount Images (ext3 mount create a inaccessible ".journal"
68 mount -o loop -t ext2 $(IMGroot) $(MNThdd)
69 mkdir $(MNThdd)/boot
70 mkdir $(MNThdd)/var
71 mkdir $(MNThdd)/var/log
72
73 # Install IPFire without kernel modules
74 tar -C $(MNThdd)/ -xvjf /install/cdrom/$(SNAME)-$(VERSION).tbz2 \
75 --exclude=lib/modules* --exclude=boot*
76
77 #Install Xen Kernel
78 tar -C $(MNThdd)/opt/pakfire/tmp -xvf /install/packages/linux-xen-$(KVER)-*.ipfire
79 chroot $(MNThdd) /opt/pakfire/tmp/install.sh
80 rm -rf $(MNThdd)/opt/pakfire/tmp/*
81
82 #Set default configuration
83 echo "LANGUAGE=en" >> $(MNThdd)/var/ipfire/main/settings
84 echo "HOSTNAME=$(SNAME)" >> $(MNThdd)/var/ipfire/main/settings
85 echo "THEME=ipfire" >> $(MNThdd)/var/ipfire/main/settings
86 touch $(MNThdd)/lib/modules/$(KVER)-ipfire-xen/modules.dep
87 mv $(MNThdd)/bin/uname.bak $(MNThdd)/bin/uname
88 mkdir $(MNThdd)/proc
89 mount --bind /proc $(MNThdd)/proc
90 mount --bind /dev $(MNThdd)/dev
91 mount --bind /sys $(MNThdd)/sys
92 chroot $(MNThdd) /usr/bin/perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
93 sed -i -e "s|DEVICE1|#boot-disabled|g" $(MNThdd)/etc/fstab
94 sed -i -e "s|DEVICE2|/dev/xvdb1|g" $(MNThdd)/etc/fstab
95 sed -i -e "s|DEVICE3|/dev/xvda1|g" $(MNThdd)/etc/fstab
96 sed -i -e "s|DEVICE4|#var-disabled|g" $(MNThdd)/etc/fstab
97
98 sed -i -e "s|FSTYPE|ext3|g" $(MNThdd)/etc/fstab
99 cp -f $(MNThdd)/etc/mkinitcpio.conf $(MNThdd)/etc/mkinitcpio.conf.org
100 sed -i -e "s| autodetect | |g" $(MNThdd)/etc/mkinitcpio.conf
101
102 #Remove File System modules because they are included to kernel
103 sed -i -e "s|reiser4 reiserfs ext3| |g" $(MNThdd)/etc/mkinitcpio.conf
104
105 chroot $(MNThdd) /sbin/mkinitcpio -g /boot/ipfirerd-$(KVER)-xen.img -k $(KVER)-ipfire-xen
106 cp -f $(MNThdd)/etc/mkinitcpio.conf.org $(MNThdd)/etc/mkinitcpio.conf
107
108 # Create a script for rebuild-initrd and setup
109 echo "#!/bin/bash" > $(MNThdd)/etc/rc.d/rcsysinit.d/S75firstsetup
110 echo "/usr/local/sbin/setup /dev/null INSTALL" >> $(MNThdd)/etc/rc.d/rcsysinit.d/S75firstsetup
111 echo "rm -f /etc/rc.d/rcsysinit.d/S75firstsetup \\" >> $(MNThdd)/etc/rc.d/rcsysinit.d/S75firstsetup
112 echo "&& /sbin/reboot" >> $(MNThdd)/etc/rc.d/rcsysinit.d/S75firstsetup
113 chmod +x $(MNThdd)/etc/rc.d/rcsysinit.d/S75firstsetup
114
115 #Remove root / fstab check
116 rm -rf $(MNThdd)/etc/rc.d/rcsysinit.d/S19checkfstab
117
118 #Copy initramdisk, kernel and config
119 cp -f $(MNThdd)/boot/ipfirerd-$(KVER)-xen.img \
120 /install/images/$(SNAME)/boot
121 cp -f $(MNThdd)/boot/vmlinuz-$(KVER)-ipfire-xen \
122 /install/images/$(SNAME)/boot
123 cp $(DIR_SRC)/config/xen-image/* \
124 /install/images/$(SNAME)
125 sed -i -e "s|KVER|$(KVER)|g" /install/images/$(SNAME)/ipfire.cfg
126
127 # Unmount
128 umount $(MNThdd)/proc
129 umount $(MNThdd)/dev
130 umount $(MNThdd)/sys
131 umount $(MNThdd)
132
133 # Compress Image
134 cd /install/images/ && tar -cvjf $(IMGinst) $(SNAME)
135
136 rm -rf $(MNThdd) /install/images/$(SNAME)