]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - config/xen-image/xen-image-maker.sh
xen-image: enlarge partitions and remove extra /var partition
[people/pmueller/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-2018 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=128
33 SIZEswap=512
34 SIZEroot=3072
35 FSTYPE=ext3
36
37 ##############################################################################
38
39 SOURCEISO=$SNAME-$VERSION.i586-full-core$CORE.iso
40 HTTPDIR=https://downloads.ipfire.org/releases/ipfire-2.x/$VERSION-core$CORE
41
42 TMPDIR=./ipfire-tmp
43 ISODIR=$TMPDIR/iso
44 MNThdd=$TMPDIR/harddisk
45
46 IMGboot=./$SNAME-boot.img
47 IMGswap=./$SNAME-swap.img
48 IMGroot=./$SNAME-root.img
49
50 KERNEL=linux-$KERN_TYPE-$KVER-$KERN_PACK.ipfire
51
52 if [ "$XEN_IMG_TYPE" == "xva" ]; then
53 # download xva.py if it not exist.
54 if [ ! -e xva.py ]; then
55 wget https://source.ipfire.org/source-2.x/xva.py
56 fi
57 # XenCenter use other devicenames and
58 # xvdd seems to be reserved (converter bug?).
59 P1=xvda
60 P2=xvdb
61 P3=xvdc
62 else
63 # old style xen image partition names
64 P1=xvda1
65 P2=xvda2
66 P3=xvda3
67 fi
68
69 rm -rf $TMPDIR && mkdir -p $MNThdd && mkdir -p $ISODIR
70 echo --------------------------------------------------------
71 echo - Download $SOURCEISO ...
72 echo --------------------------------------------------------
73 wget $HTTPDIR/$SOURCEISO -O $TMPDIR/$SOURCEISO
74 mount -o loop $TMPDIR/$SOURCEISO $ISODIR
75
76 echo --------------------------------------------------------
77 echo - Download $KERNEL ...
78 echo --------------------------------------------------------
79 wget $KRNDOWN/$KERNEL -O $TMPDIR/$KERNEL.gpg
80 gpg -d $TMPDIR/$KERNEL.gpg > $TMPDIR/$KERNEL
81
82 echo --------------------------------------------------------
83 echo - Create Images ...
84 echo --------------------------------------------------------
85
86 #Create bootimage
87 dd bs=1M if=/dev/zero of=$IMGboot count=$SIZEboot
88 mkfs.ext2 -F $IMGboot
89
90 #Create swapimage
91 dd bs=1M if=/dev/zero of=$IMGswap count=$SIZEswap
92 mkswap $IMGswap
93
94 #Create rootimage
95 dd bs=1M if=/dev/zero of=$IMGroot count=$SIZEroot
96 mkfs.$FSTYPE -F $IMGroot
97
98 echo --------------------------------------------------------
99 echo - Install 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
109 # Install IPFire without kernel modules
110 xz -d < $ISODIR/distro.img > $TMPDIR/$SNAME-$VERSION.tar
111 tar -C $MNThdd/ -xvf $TMPDIR/$SNAME-$VERSION.tar \
112 --exclude=lib/modules* --exclude=boot* --numeric-owner
113
114 #Install Kernel
115 mkdir $MNThdd/proc
116 mkdir $MNThdd/boot/grub
117 echo "flags : pae " > $MNThdd/proc/cpuinfo # fake pae detection
118 tar -C $MNThdd/opt/pakfire/tmp -xvf $TMPDIR/$KERNEL --numeric-owner
119 chroot $MNThdd /opt/pakfire/tmp/install.sh
120 rm -rf $MNThdd/opt/pakfire/tmp/*
121 rm -rf $MNThdd/proc/cpuinfo
122
123 #Create grub menuentry for pygrub
124 echo "timeout 10" > $MNThdd/boot/grub/grub.conf
125 echo "default 0" >> $MNThdd/boot/grub/grub.conf
126 echo "title IPFire ($KERN_TYPE-kernel)" >> $MNThdd/boot/grub/grub.conf
127 echo " root (hd0)" >> $MNThdd/boot/grub/grub.conf
128 echo " kernel /vmlinuz-$KVER-ipfire-$KERN_TYPE root=/dev/$P3 rootdelay=10 panic=10 console=$CONSOLE" \
129 >> $MNThdd/boot/grub/grub.conf
130 echo " initrd /initramfs-$KVER-ipfire-$KERN_TYPE.img" >> $MNThdd/boot/grub/grub.conf
131 echo "# savedefault 0" >> $MNThdd/boot/grub/grub.conf
132
133 ln -s grub.conf $MNThdd/boot/grub/menu.lst
134
135 #create the meta-info of linux-kernel package
136 echo "" > $MNThdd/opt/pakfire/db/meta/meta-linux-$KERN_TYPE
137 echo "Name: linux-$KERN_TYPE" >> $MNThdd/opt/pakfire/db/meta/meta-linux-$KERN_TYPE
138 echo "ProgVersion: $KVER" >> $MNThdd/opt/pakfire/db/meta/meta-linux-$KERN_TYPE
139 echo "Release: $KERN_PACK" >> $MNThdd/opt/pakfire/db/meta/meta-linux-$KERN_TYPE
140 echo "" >> $MNThdd/opt/pakfire/db/meta/meta-linux-$KERN_TYPE
141 echo "" > $MNThdd/opt/pakfire/db/installed/meta-linux-$KERN_TYPE
142 echo "Name: linux-$KERN_TYPE" >> $MNThdd/opt/pakfire/db/installed/meta-linux-$KERN_TYPE
143 echo "ProgVersion: $KVER" >> $MNThdd/opt/pakfire/db/installed/meta-linux-$KERN_TYPE
144 echo "Release: $KERN_PACK" >> $MNThdd/opt/pakfire/db/installed/meta-linux-$KERN_TYPE
145 echo "" >> $MNThdd/opt/pakfire/db/installed/meta-linux-$KERN_TYPE
146
147 #Set default configuration
148 echo "LANGUAGE=en" >> $MNThdd/var/ipfire/main/settings
149 echo "HOSTNAME=$SNAME" >> $MNThdd/var/ipfire/main/settings
150 echo "THEME=ipfire" >> $MNThdd/var/ipfire/main/settings
151 touch $MNThdd/lib/modules/$KVER-ipfire-$KERN_TYPE/modules.dep
152 mount --bind /proc $MNThdd/proc
153 mount --bind /dev $MNThdd/dev
154 mount --bind /sys $MNThdd/sys
155 chroot $MNThdd /usr/bin/perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
156
157 # create fstab
158 echo "/dev/$P1 /boot auto defaults 1 3" > $MNThdd/etc/fstab
159 echo "/dev/$P2 swap swap defaults 0 0" >> $MNThdd/etc/fstab
160 echo "/dev/$P3 / auto defaults 1 1" >> $MNThdd/etc/fstab
161
162
163 #Remove root / fstab check
164 rm -rf $MNThdd/etc/rc.d/rcsysinit.d/S19checkfstab
165 #Remove console init
166 rm -rf $MNThdd/etc/rc.d/rcsysinit.d/S70console
167
168 #Add console to securetty
169 echo $CONSOLE >> $MNThdd/etc/securetty
170
171 #Add getty for console
172 echo "#Enable login for XEN" >> $MNThdd/etc/inittab
173 echo "8:2345:respawn:/sbin/agetty $CONSOLE 9600 --noclear" >> $MNThdd/etc/inittab
174
175 #Disable some initskripts
176 echo "#!/bin/sh" > $MNThdd/etc/rc.d/init.d/setclock
177 echo "#!/bin/sh" > $MNThdd/etc/rc.d/init.d/keymap
178
179 #Remove autoload of acpi modules
180 sed -i -e "s|^ac|#ac|g" $MNThdd/etc/sysconfig/modules
181 sed -i -e "s|^battery|#battery|g" $MNThdd/etc/sysconfig/modules
182 sed -i -e "s|^button|#button|g" $MNThdd/etc/sysconfig/modules
183 sed -i -e "s|^fan|#fan|g" $MNThdd/etc/sysconfig/modules
184 sed -i -e "s|^processor|#processor|g" $MNThdd/etc/sysconfig/modules
185 sed -i -e "s|^thermal|#thermal|g" $MNThdd/etc/sysconfig/modules
186 sed -i -e "s|^video|#video|g" $MNThdd/etc/sysconfig/modules
187
188 # Unmount
189 umount $MNThdd/proc
190 umount $MNThdd/dev
191 umount $MNThdd/sys
192 umount $MNThdd/boot
193 umount $MNThdd
194
195 umount $ISODIR
196 rm -rf ./ipfire-tmp
197
198 if [ "$XEN_IMG_TYPE" == "xva" ]; then
199 python xva.py --sparse -c $SNAME.cfg -f $SNAME.xva
200 rm -f $SNAME*.img
201 fi
202 echo --------------------------------------------------------
203 echo - Done.
204 echo --------------------------------------------------------