]> git.ipfire.org Git - ipfire-2.x.git/blob - config/xen-image/xen-image-maker.sh
a16305313d7c46f74a5ed2aa45b81263317c7247
[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 SIZEboot=64
33 SIZEswap=512
34 SIZEroot=1024
35 SIZEvar=1024
36 # ct'server does not support ext4 so change this to ext3.
37 FSTYPE=ext4
38
39 ##############################################################################
40
41 SOURCEISO=$SNAME-$VERSION.i586-full-core$CORE.iso
42 HTTPDIR=http://download.ipfire.org/releases/ipfire-2.x/$VERSION-core$CORE
43
44 TMPDIR=./ipfire-tmp
45 ISODIR=$TMPDIR/iso
46 MNThdd=$TMPDIR/harddisk
47
48 IMGboot=./$SNAME-boot.img
49 IMGswap=./$SNAME-swap.img
50 IMGroot=./$SNAME-root.img
51 IMGvar=./$SNAME-var.img
52
53 KERNEL=linux-$KERN_TYPE-$KVER-$KERN_PACK.ipfire
54
55 rm -rf $TMPDIR && mkdir -p $MNThdd && mkdir -p $ISODIR
56 echo --------------------------------------------------------
57 echo - Download $SOURCEISO ...
58 echo --------------------------------------------------------
59 wget $HTTPDIR/$SOURCEISO -O $TMPDIR/$SOURCEISO
60 mount -o loop $TMPDIR/$SOURCEISO $ISODIR
61
62 echo --------------------------------------------------------
63 echo - Download $KERNEL ...
64 echo --------------------------------------------------------
65 wget $KRNDOWN/$KERNEL -O $TMPDIR/$KERNEL.gpg
66 gpg -d $TMPDIR/$KERNEL.gpg > $TMPDIR/$KERNEL
67
68 echo --------------------------------------------------------
69 echo - Create Images ...
70 echo --------------------------------------------------------
71
72 #Create bootimage
73 dd bs=1M if=/dev/zero of=$IMGboot count=$SIZEboot
74 mkfs.ext2 -F $IMGboot
75
76 #Create swapimage
77 dd bs=1M if=/dev/zero of=$IMGswap count=$SIZEswap
78 mkswap $IMGswap
79
80 #Create rootimage
81 dd bs=1M if=/dev/zero of=$IMGroot count=$SIZEroot
82 mkfs.$FSTYPE -F $IMGroot
83
84 #Create varimage
85 dd bs=1M if=/dev/zero of=$IMGvar count=$SIZEvar
86 mkfs.$FSTYPE -F $IMGvar
87
88 echo --------------------------------------------------------
89 echo - Intall IPFire to the Images ...
90 echo --------------------------------------------------------
91
92 # Mount Images
93 mount -o loop $IMGroot $MNThdd
94 mkdir $MNThdd/boot
95 mkdir $MNThdd/var
96 mkdir $MNThdd/var/log
97 mount -o loop $IMGboot $MNThdd/boot
98 mount -o loop $IMGvar $MNThdd/var
99
100 # Install IPFire without kernel modules
101 tar -C $MNThdd/ -xvf $ISODIR/$SNAME-$VERSION.tlz --lzma \
102 --exclude=lib/modules* --exclude=boot* --numeric-owner
103
104 #Install Kernel
105 tar -C $MNThdd/opt/pakfire/tmp -xvf $TMPDIR/$KERNEL --numeric-owner
106 chroot $MNThdd /opt/pakfire/tmp/install.sh
107 rm -rf $MNThdd/opt/pakfire/tmp/*
108
109 #Create grub menuentry for pygrub
110 mkdir $MNThdd/boot/grub
111 echo "timeout 10" > $MNThdd/boot/grub/grub.conf
112 echo "default 0" >> $MNThdd/boot/grub/grub.conf
113 echo "title IPFire ($KERN_TYPE-kernel)" >> $MNThdd/boot/grub/grub.conf
114 echo " kernel /vmlinuz-$KVER-ipfire-$KERN_TYPE root=/dev/xvda3 rootdelay=10 panic=10 console=$CONSOLE ro" \
115 >> $MNThdd/boot/grub/grub.conf
116 echo " initrd /ipfirerd-$KVER-$KERN_TYPE.img" >> $MNThdd/boot/grub/grub.conf
117 echo "# savedefault 0" >> $MNThdd/boot/grub/grub.conf
118
119 ln -s grub.conf $MNThdd/boot/grub/menu.lst
120
121 #create the meta-info of linux-kernel package
122 echo "" > $MNThdd/opt/pakfire/db/meta/linux-$KERN_TYPE
123 echo "Name: linux-$KERN_TYPE" >> $MNThdd/opt/pakfire/db/meta/linux-$KERN_TYPE
124 echo "ProgVersion: $KVER" >> $MNThdd/opt/pakfire/db/meta/linux-$KERN_TYPE
125 echo "Release: $KERN_PACK" >> $MNThdd/opt/pakfire/db/meta/linux-$KERN_TYPE
126 echo "" >> $MNThdd/opt/pakfire/db/meta/linux-$KERN_TYPE
127 echo "" > $MNThdd/opt/pakfire/db/installed/linux-$KERN_TYPE
128 echo "Name: linux-$KERN_TYPE" >> $MNThdd/opt/pakfire/db/installed/linux-$KERN_TYPE
129 echo "ProgVersion: $KVER" >> $MNThdd/opt/pakfire/db/installed/linux-$KERN_TYPE
130 echo "Release: $KERN_PACK" >> $MNThdd/opt/pakfire/db/installed/linux-$KERN_TYPE
131 echo "" >> $MNThdd/opt/pakfire/db/installed/linux-$KERN_TYPE
132
133 #Set default configuration
134 echo "LANGUAGE=en" >> $MNThdd/var/ipfire/main/settings
135 echo "HOSTNAME=$SNAME" >> $MNThdd/var/ipfire/main/settings
136 echo "THEME=ipfire" >> $MNThdd/var/ipfire/main/settings
137 touch $MNThdd/lib/modules/$KVER-ipfire-$KERN_TYPE/modules.dep
138 mkdir $MNThdd/proc
139 mount --bind /proc $MNThdd/proc
140 mount --bind /dev $MNThdd/dev
141 mount --bind /sys $MNThdd/sys
142 chroot $MNThdd /usr/bin/perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
143 sed -i -e "s|DEVICE1|/dev/xvda1|g" $MNThdd/etc/fstab
144 sed -i -e "s|DEVICE2|/dev/xvda2|g" $MNThdd/etc/fstab
145 sed -i -e "s|DEVICE3|/dev/xvda3|g" $MNThdd/etc/fstab
146 sed -i -e "s|DEVICE4|/dev/xvda4|g" $MNThdd/etc/fstab
147
148 sed -i -e "s|FSTYPE|$FSTYPE|g" $MNThdd/etc/fstab
149
150 #Remove root / fstab check
151 rm -rf $MNThdd/etc/rc.d/rcsysinit.d/S19checkfstab
152 #Remove console init
153 rm -rf $MNThdd/etc/rc.d/rcsysinit.d/S70console
154
155 #Add console to securetty
156 echo $CONSOLE >> $MNThdd/etc/securetty
157
158 #Add getty for console
159 echo "#Enable login for XEN" >> $MNThdd/etc/inittab
160 echo "8:2345:respawn:/sbin/agetty $CONSOLE 9600 --noclear" >> $MNThdd/etc/inittab
161
162 #Disable some initskripts
163 echo "#!/bin/sh" > $MNThdd/etc/rc.d/init.d/setclock
164 echo "#!/bin/sh" > $MNThdd/etc/rc.d/init.d/keymap
165
166 #Remove autoload of acpi modules
167 sed -i -e "s|^ac|#ac|g" $MNThdd/etc/sysconfig/modules
168 sed -i -e "s|^battery|#battery|g" $MNThdd/etc/sysconfig/modules
169 sed -i -e "s|^button|#button|g" $MNThdd/etc/sysconfig/modules
170 sed -i -e "s|^fan|#fan|g" $MNThdd/etc/sysconfig/modules
171 sed -i -e "s|^processor|#processor|g" $MNThdd/etc/sysconfig/modules
172 sed -i -e "s|^thermal|#thermal|g" $MNThdd/etc/sysconfig/modules
173 sed -i -e "s|^video|#video|g" $MNThdd/etc/sysconfig/modules
174
175 # Unmount
176 umount $MNThdd/proc
177 umount $MNThdd/dev
178 umount $MNThdd/sys
179 umount $MNThdd/var
180 umount $MNThdd/boot
181 umount $MNThdd
182
183 umount $ISODIR
184 rm -rf ./ipfire-tmp
185 echo --------------------------------------------------------
186 echo - Done.
187 echo --------------------------------------------------------