]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - config/xen-image/xen-image-maker.sh
firewall: Allow blocking access to GREEN from GREEN.
[people/teissler/ipfire-2.x.git] / config / xen-image / xen-image-maker.sh
1 #/bin/bash
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2014 Arne Fitzenreiter <arne_f@ipfire.org> #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 SNAME=xxxSNAMExxx
23 VERSION=xxxVERSIONxxx
24 CORE=xxxCORExxx
25
26 KERN_TYPE=pae
27 KVER=xxxKVERxxx
28 KERN_PACK=xxxKERN_PACKxxx
29 KRNDOWN=http://mirror0.ipfire.org/pakfire2/$VERSION/paks
30 CONSOLE=hvc0
31 ###############################################################################
32 # If you really want to use outdated legacy kernel uncomment this lines. #####
33 # Not recommended!!! ##########################################################
34 ######################
35 #KERN_TYPE=xen
36 #KVER=2.6.32.61
37 #KERN_PACK=29
38 #KRNDOWN=http://mirror0.ipfire.org/pakfire2/2.15/paks
39 #CONSOLE=xvc0
40 ###############################################################################
41
42 SIZEboot=64
43 SIZEswap=512
44 SIZEroot=1024
45 SIZEvar=1024
46 # ct'server does not support ext4 so change this to ext3.
47 FSTYPE=ext4
48
49 ##############################################################################
50
51 SOURCEISO=$SNAME-$VERSION.i586-full-core$CORE.iso
52 HTTPDIR=http://download.ipfire.org/releases/ipfire-2.x/$VERSION-core$CORE
53
54 TMPDIR=./ipfire-tmp
55 ISODIR=$TMPDIR/iso
56 MNThdd=$TMPDIR/harddisk
57
58 IMGboot=./$SNAME-boot.img
59 IMGswap=./$SNAME-swap.img
60 IMGroot=./$SNAME-root.img
61 IMGvar=./$SNAME-var.img
62
63 KERNEL=linux-$KERN_TYPE-$KVER-$KERN_PACK.ipfire
64
65 rm -rf $TMPDIR && mkdir -p $MNThdd && mkdir -p $ISODIR
66 echo --------------------------------------------------------
67 echo - Download $SOURCEISO ...
68 echo --------------------------------------------------------
69 wget $HTTPDIR/$SOURCEISO -O $TMPDIR/$SOURCEISO
70 mount -o loop $TMPDIR/$SOURCEISO $ISODIR
71
72 echo --------------------------------------------------------
73 echo - Download $KERNEL ...
74 echo --------------------------------------------------------
75 wget $KRNDOWN/$KERNEL -O $TMPDIR/$KERNEL.gpg
76 gpg -d $TMPDIR/$KERNEL.gpg > $TMPDIR/$KERNEL
77
78 echo --------------------------------------------------------
79 echo - Create Images ...
80 echo --------------------------------------------------------
81
82 #Create bootimage
83 dd bs=1M if=/dev/zero of=$IMGboot count=$SIZEboot
84 mkfs.ext2 -F $IMGboot
85
86 #Create swapimage
87 dd bs=1M if=/dev/zero of=$IMGswap count=$SIZEswap
88 mkswap $IMGswap
89
90 #Create rootimage
91 dd bs=1M if=/dev/zero of=$IMGroot count=$SIZEroot
92 mkfs.$FSTYPE -F $IMGroot
93
94 #Create varimage
95 dd bs=1M if=/dev/zero of=$IMGvar count=$SIZEvar
96 mkfs.$FSTYPE -F $IMGvar
97
98 echo --------------------------------------------------------
99 echo - Intall IPFire to the Images ...
100 echo --------------------------------------------------------
101
102 # Mount Images
103 mount -o loop $IMGroot $MNThdd
104 mkdir $MNThdd/boot
105 mkdir $MNThdd/var
106 mkdir $MNThdd/var/log
107 mount -o loop $IMGboot $MNThdd/boot
108 mount -o loop $IMGvar $MNThdd/var
109
110 # Install IPFire without kernel modules
111 tar -C $MNThdd/ -xvf $ISODIR/$SNAME-$VERSION.tlz --lzma \
112 --exclude=lib/modules* --exclude=boot* --numeric-owner
113
114 #Install Kernel
115 tar -C $MNThdd/opt/pakfire/tmp -xvf $TMPDIR/$KERNEL --numeric-owner
116 chroot $MNThdd /opt/pakfire/tmp/install.sh
117 rm -rf $MNThdd/opt/pakfire/tmp/*
118
119 #Create grub menuentry for pygrub
120 mkdir $MNThdd/boot/grub
121 echo "timeout 10" > $MNThdd/boot/grub/grub.conf
122 echo "default 0" >> $MNThdd/boot/grub/grub.conf
123 echo "title IPFire ($KERN_TYPE-kernel)" >> $MNThdd/boot/grub/grub.conf
124 echo " kernel /vmlinuz-$KVER-ipfire-$KERN_TYPE root=/dev/xvda3 rootdelay=10 panic=10 console=$CONSOLE ro" \
125 >> $MNThdd/boot/grub/grub.conf
126 echo " initrd /ipfirerd-$KVER-$KERN_TYPE.img" >> $MNThdd/boot/grub/grub.conf
127 echo "# savedefault 0" >> $MNThdd/boot/grub/grub.conf
128
129 ln -s grub.conf $MNThdd/boot/grub/menu.lst
130
131 #create the meta-info of linux-kernel package
132 echo "" > $MNThdd/opt/pakfire/db/meta/linux-$KERN_TYPE
133 echo "Name: linux-$KERN_TYPE" >> $MNThdd/opt/pakfire/db/meta/linux-$KERN_TYPE
134 echo "ProgVersion: $KVER" >> $MNThdd/opt/pakfire/db/meta/linux-$KERN_TYPE
135 echo "Release: $KERN_PACK" >> $MNThdd/opt/pakfire/db/meta/linux-$KERN_TYPE
136 echo "" >> $MNThdd/opt/pakfire/db/meta/linux-$KERN_TYPE
137 echo "" > $MNThdd/opt/pakfire/db/installed/linux-$KERN_TYPE
138 echo "Name: linux-$KERN_TYPE" >> $MNThdd/opt/pakfire/db/installed/linux-$KERN_TYPE
139 echo "ProgVersion: $KVER" >> $MNThdd/opt/pakfire/db/installed/linux-$KERN_TYPE
140 echo "Release: $KERN_PACK" >> $MNThdd/opt/pakfire/db/installed/linux-$KERN_TYPE
141 echo "" >> $MNThdd/opt/pakfire/db/installed/linux-$KERN_TYPE
142
143 #Set default configuration
144 echo "LANGUAGE=en" >> $MNThdd/var/ipfire/main/settings
145 echo "HOSTNAME=$SNAME" >> $MNThdd/var/ipfire/main/settings
146 echo "THEME=ipfire" >> $MNThdd/var/ipfire/main/settings
147 touch $MNThdd/lib/modules/$KVER-ipfire-$KERN_TYPE/modules.dep
148 mkdir $MNThdd/proc
149 mount --bind /proc $MNThdd/proc
150 mount --bind /dev $MNThdd/dev
151 mount --bind /sys $MNThdd/sys
152 chroot $MNThdd /usr/bin/perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
153 sed -i -e "s|DEVICE1|/dev/xvda1|g" $MNThdd/etc/fstab
154 sed -i -e "s|DEVICE2|/dev/xvda2|g" $MNThdd/etc/fstab
155 sed -i -e "s|DEVICE3|/dev/xvda3|g" $MNThdd/etc/fstab
156 sed -i -e "s|DEVICE4|/dev/xvda4|g" $MNThdd/etc/fstab
157
158 sed -i -e "s|FSTYPE|$FSTYPE|g" $MNThdd/etc/fstab
159
160 #Remove root / fstab check
161 rm -rf $MNThdd/etc/rc.d/rcsysinit.d/S19checkfstab
162 #Remove console init
163 rm -rf $MNThdd/etc/rc.d/rcsysinit.d/S70console
164
165 #Add console to securetty
166 echo $CONSOLE >> $MNThdd/etc/securetty
167
168 #Add getty for console
169 echo "#Enable login for XEN" >> $MNThdd/etc/inittab
170 echo "8:2345:respawn:/sbin/agetty $CONSOLE 9600 --noclear" >> $MNThdd/etc/inittab
171
172 #Disable some initskripts
173 echo "#!/bin/sh" > $MNThdd/etc/rc.d/init.d/setclock
174 echo "#!/bin/sh" > $MNThdd/etc/rc.d/init.d/keymap
175
176 #Remove autoload of acpi modules
177 sed -i -e "s|^ac|#ac|g" $MNThdd/etc/sysconfig/modules
178 sed -i -e "s|^battery|#battery|g" $MNThdd/etc/sysconfig/modules
179 sed -i -e "s|^button|#button|g" $MNThdd/etc/sysconfig/modules
180 sed -i -e "s|^fan|#fan|g" $MNThdd/etc/sysconfig/modules
181 sed -i -e "s|^processor|#processor|g" $MNThdd/etc/sysconfig/modules
182 sed -i -e "s|^thermal|#thermal|g" $MNThdd/etc/sysconfig/modules
183 sed -i -e "s|^video|#video|g" $MNThdd/etc/sysconfig/modules
184
185 # Unmount
186 umount $MNThdd/proc
187 umount $MNThdd/dev
188 umount $MNThdd/sys
189 umount $MNThdd/var
190 umount $MNThdd/boot
191 umount $MNThdd
192
193 umount $ISODIR
194 rm -rf ./ipfire-tmp
195 echo --------------------------------------------------------
196 echo - Done.
197 echo --------------------------------------------------------