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