xentaur

annotate build-xenomips-image @ 65:cf823d27b029

Nattaur changes
author nata@nattaur
date Mon Oct 12 00:12:11 2009 +0300 (2009-10-12)
parents 6471afbee150
children
rev   line source
igor@0 1 #!/bin/sh
igor@0 2
nata@65 3 DYNAMIPS_BUILD=yes
igor@49 4 XENOMIPS_FS_BUILD=yes
igor@49 5 CONFIG_FS_BUILD=yes
igor@45 6 IOS_FS_BUILD=yes
igor@0 7
igor@49 8 process_args()
igor@49 9 {
igor@49 10 true
igor@49 11 }
igor@49 12
igor@7 13 XENOMIPS_DIR="files/"
nata@65 14 XENOMIPS_IMAGES_DIR="/xentaur/images/"
nata@65 15 IOS_DIR="/xentaur/ios/"
igor@15 16 SSH_OPEN_KEY=files/id_dsa.pub
igor@7 17
igor@0 18 #Xenomips FS
igor@0 19 XENOMIPS_FS_SIZE=2048k # size in 1k blocks
igor@7 20 XENOMIPS_FS_NAME=${XENOMIPS_IMAGES_DIR}/xenomips1.img
igor@0 21
igor@0 22 # Config FS
igor@7 23 CONFIG_FS_SIZE=1000k
igor@18 24 CONFIG_FS_NAME=${XENOMIPS_IMAGES_DIR}/xenomips-configXXX.img # XXX will be automagically substitued with
igor@43 25 CONFIG_FS_NUMBER=10 # the number of the Xenomips instance
igor@0 26
igor@0 27 # IOS FS
igor@0 28 IOS_FS_SIZE=2048k
igor@7 29 IOS_FS_NAME=${XENOMIPS_IMAGES_DIR}/xenomips-ios1.img
igor@0 30
nata@65 31 DEBIAN_MIRROR=http://127.0.0.1:9999/debian
nata@65 32 DISTRO=lenny
nata@65 33 PACKAGES="udev openssh-server libc6-xen libelf1 libpcap0.8 screen nfs-common quagga tcpdump telnet ntpdate hping3 ntp nmap netcat socat"
igor@0 34 DYNAMIPS_SOURCES=http://www.ipflow.utc.fr/dynamips/dynamips-0.2.7.tar.gz
igor@0 35 DYNAMIPS_BUILD_DIR=dynamips/
igor@61 36 PIXEMU_SOURCES=http://xgu.ru/download/pemu_public2007-07-02.tar.bz2
igor@61 37 PIXEMU_BUILD_DIR=dynamips/
nata@65 38 KERNEL_VERSION="2.6.26-2-xen-686 2.6.18-6-xen-686" #`uname -r`
igor@0 39
igor@0 40 WORK_DIR=${XENOMIPS_FS_NAME%%.img}
igor@7 41 WORK_DIR2=/tmp/xenomips-build
igor@0 42
igor@17 43 myecho()
igor@17 44 {
igor@17 45 echo '**************************'
igor@17 46 echo "$@"
igor@17 47 echo '**************************'
igor@17 48 }
igor@17 49
igor@0 50 build_and_install_dynamips()
igor@0 51 {
igor@0 52 OLD_PWD="`pwd`"
igor@20 53 DESTDIR=${WORK_DIR}/usr
igor@0 54
igor@0 55 if echo $DYNAMIPS_BUILD | grep -qi ^y
igor@0 56 then
igor@0 57 rm -rf ${DYNAMIPS_BUILD_DIR}/
igor@0 58 mkdir -p ${DYNAMIPS_BUILD_DIR}/
igor@0 59 cd ${DYNAMIPS_BUILD_DIR}/
igor@0 60 wget $DYNAMIPS_SOURCES
igor@0 61 tar xfz dynamips*tar*
igor@0 62 cd dynamips*/
igor@0 63 perl -p -i -e s@^PCAP_LIB=.*@PCAP_LIB=-lpcap@ Makefile
igor@0 64 make
igor@0 65 else
igor@0 66 cd ${DYNAMIPS_BUILD_DIR}/dynamips*/
igor@0 67 fi
igor@20 68 make install DESTDIR=${DESTDIR}
igor@0 69 cd ${OLD_PWD}
igor@0 70 }
igor@0 71
igor@61 72 build_and_install_pixemu()
igor@61 73 {
igor@61 74 DESTDIR=${WORK_DIR}/usr/local/pixemu
igor@61 75 mkdir -p $DESTDIR
igor@61 76 cp /home/igor/pemu/pemu/* $DESTDIR
igor@61 77 }
igor@61 78
igor@61 79
igor@43 80 if [ $(id -u) != 0 ]
igor@43 81 then
igor@43 82 echo You are not root.
igor@43 83 echo Please, log in as root or run the script with sudo
igor@43 84 ecit 1
igor@43 85 fi
igor@43 86
igor@43 87
igor@43 88 if echo $XENOMIPS_FS_BUILD | grep -qi ^y
igor@43 89 then
igor@43 90 myecho Preparing the Xenomips filesystem
igor@43 91 dd if=/dev/zero of=${XENOMIPS_FS_NAME} seek=${XENOMIPS_FS_SIZE} bs=1024 count=1
igor@43 92 mkfs.ext3 -F ${XENOMIPS_FS_NAME}
igor@43 93 mkdir -p ${WORK_DIR}
igor@43 94 mount -o loop ${XENOMIPS_FS_NAME} ${WORK_DIR}
igor@43 95 debootstrap ${DISTRO} ${WORK_DIR} ${DEBIAN_MIRROR}
igor@43 96 cat <<SCRIPT | chroot ${WORK_DIR} sh -s
igor@0 97 unset LANG
igor@0 98 apt-get -y --force-yes install ${PACKAGES}
igor@0 99 /etc/init.d/ssh stop
igor@0 100 cat <<FSTAB > /etc/fstab
igor@11 101 proc /proc proc defaults 0 0
igor@11 102 tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0
igor@11 103
igor@0 104 /dev/hda1 / ext3 ro 0 0
igor@0 105 /dev/hda2 /xenomips/ios ext3 ro 0 0
igor@0 106 /dev/hda3 /xenomips/config ext3 rw 0 0
igor@0 107 FSTAB
igor@0 108 mkdir -p /data/Cisco_IOS /xenomips
igor@0 109
igor@40 110 cat <<EOF > /etc/sysctl.conf
igor@40 111 net/ipv4/ip_forward=1
igor@40 112 EOF
igor@40 113
igor@0 114 cat <<'INTERFACES' > /etc/network/interfaces
igor@0 115 auto lo eth0
igor@0 116
igor@0 117 iface lo inet loopback
igor@0 118 up for i in \`ifconfig -a | grep 'eth.*Link encap' | awk '{print \$1}'\`; do ifconfig \$i up ; done || true
igor@0 119
igor@13 120 #iface eth0 inet dhcp
igor@0 121 INTERFACES
igor@0 122
nata@65 123 cat <<EOF >> /etc/inittab
nata@65 124 1h:2345:respawn:/sbin/getty 38400 hvc0
nata@65 125 EOF
nata@65 126
nata@65 127 cat <<EOF >> /etc/modules
nata@65 128 iptable_nat
nata@65 129 EOF
nata@65 130
igor@49 131 #echo /usr/local/bin/xenomips.sh > /etc/rc.local
igor@0 132 cd /etc/rcS.d; ln -s ../init.d/xenomips-init S35xenomips-init
igor@0 133 rm /etc/rc2.d/S*quagga
igor@49 134 cd /etc/rc2.d; ln -s ../init.d/xenomips S99xenomips
igor@49 135 cd /etc/rc3.d; ln -s ../init.d/xenomips S99xenomips
igor@49 136 cd /etc/rc4.d; ln -s ../init.d/xenomips S99xenomips
igor@49 137 cd /etc/rc5.d; ln -s ../init.d/xenomips S99xenomips
igor@49 138 cd /etc/rc0.d; ln -s ../init.d/xenomips K01xenomips
igor@49 139 cd /etc/rc1.d; ln -s ../init.d/xenomips K01xenomips
igor@49 140 cd /etc/rc6.d; ln -s ../init.d/xenomips K01xenomips
igor@0 141
igor@7 142 #perl -i -p -e s@C_PATH=/etc/quagga@C_PATH=/xenomips/etc/quagga@ /etc/init.d/quagga
igor@7 143 mv /etc/quagga /etc/quagga.ORIG
igor@7 144 ln -s /xenomips/config/etc/quagga /etc/quagga
igor@0 145
igor@61 146 mkdir -p /xenomips/{ios,config} /var/lib/xenomips /root/.ssh
igor@0 147
igor@7 148 cat <<PROFILE >> /root/.profile
igor@7 149 TERM=linux
igor@0 150 screen -ls | grep -q Attached && screen -x || screen -ls | grep -q Detached && screen -r
igor@7 151 PROFILE
igor@0 152 SCRIPT
igor@0 153
igor@43 154 for kernel_version in ${KERNEL_VERSION} 2.6.18-without-PAE-4-xen-686
igor@43 155 do
nata@65 156 cp -R /lib/modules/${kernel_version} ${WORK_DIR}/lib/modules
igor@43 157 done
igor@0 158
igor@43 159 cp ${XENOMIPS_DIR}/xenomips-init ${WORK_DIR}/etc/init.d/
igor@49 160 cp ${XENOMIPS_DIR}/xenomips.sh ${WORK_DIR}/etc/init.d/xenomips
igor@49 161 sudo chmod +x ${WORK_DIR}/etc/init.d/xenomips ${WORK_DIR}/etc/init.d/xenomips-init
igor@0 162
igor@43 163 cat ${SSH_OPEN_KEY} > ${WORK_DIR}/root/.ssh/authorized_keys
igor@43 164 chmod 600 ${WORK_DIR}/root/.ssh/authorized_keys
igor@0 165
igor@43 166 build_and_install_dynamips
nata@65 167 #build_and_install_pixemu
igor@61 168 kill $(lsof +D ${WORK_DIR} | awk '{print $2}' | grep -v PID)
igor@61 169 pkill ntpd
igor@43 170 umount ${WORK_DIR}
igor@43 171 fi
igor@0 172
igor@0 173
igor@0 174 if echo $CONFIG_FS_BUILD | grep -qi ^y
igor@0 175 then
igor@43 176 mkdir -p ${WORK_DIR}
igor@43 177 mount -o loop ${XENOMIPS_FS_NAME} ${WORK_DIR}
igor@43 178 mkdir -p ${WORK_DIR2}
igor@43 179 cp -a ${WORK_DIR}/etc/quagga.ORIG ${WORK_DIR2}/quagga
igor@43 180 perl -i -p -e 's/=no/=yes/' ${WORK_DIR2}/quagga/daemons
igor@43 181 touch ${WORK_DIR2}/quagga/{zebra,bgpd,ospfd,ripd,ripngd,ospf6d,isisd}.conf
igor@61 182 cp -a ${WORK_DIR}/usr/local/pixemu ${WORK_DIR2}/pixemu
igor@43 183 umount ${WORK_DIR}
igor@43 184
igor@18 185 myecho Preparing the Xenomips config filesystem
igor@41 186 dd if=/dev/zero of=${CONFIG_FS_NAME} bs=1k count=1 seek=${CONFIG_FS_SIZE}
igor@0 187 mkfs.ext3 -F ${CONFIG_FS_NAME}
igor@14 188
igor@14 189 mount -o loop ${CONFIG_FS_NAME} ${WORK_DIR}
igor@61 190 mkdir -p ${WORK_DIR}/{dynamips,etc}
igor@14 191 mv ${WORK_DIR2}/quagga ${WORK_DIR}/etc
igor@61 192 mv ${WORK_DIR2}/pixemu ${WORK_DIR}/
igor@61 193 dd if=/dev/zero of=${WORK_DIR}/pixemu/FLASH bs=1k count=16k
igor@14 194 umount ${WORK_DIR}
igor@14 195
igor@18 196 myecho Creating $CONFIG_FS_NUMBER copies of the Xenomips config filesystem
igor@61 197 for i in `seq 0 $CONFIG_FS_NUMBER`
igor@18 198 do
igor@18 199 cp ${CONFIG_FS_NAME} `echo ${CONFIG_FS_NAME} | sed s/XXX/$i/`
igor@18 200 done
igor@0 201 fi
igor@0 202
igor@0 203
igor@0 204 if echo $IOS_FS_BUILD | grep -qi ^y
igor@0 205 then
igor@18 206 myecho Preparing the filesystem with the IOSes
igor@18 207 dd if=/dev/zero of=${IOS_FS_NAME} bs=1k count=1 seek=${CONFIG_FS_SIZE}
igor@0 208 mkfs.ext3 -F ${IOS_FS_NAME}
igor@0 209 mount -o loop ${IOS_FS_NAME} ${WORK_DIR}
igor@0 210 cp ${IOS_DIR}/* ${WORK_DIR}
igor@0 211 umount ${WORK_DIR}
igor@0 212 fi
igor@0 213