xentaur
view build-xenomips-image @ 42:e006fac33f05
dynamips platform
author | igor |
---|---|
date | Wed Oct 24 13:27:53 2007 +0300 (2007-10-24) |
parents | 8c00f233a1d4 |
children | 61476759b5f1 |
line source
1 #!/bin/sh
3 DYNAMIPS_BUILD=no
4 XENOMIPS_FS_BUILD=yes
5 CONFIG_FS_BUILD=yes
6 IOS_FS_BUILD=yes
8 XENOMIPS_DIR="files/"
9 XENOMIPS_IMAGES_DIR="/xen/images/"
10 IOS_DIR="ios/"
11 SSH_OPEN_KEY=files/id_dsa.pub
13 #Xenomips FS
14 XENOMIPS_FS_SIZE=2048k # size in 1k blocks
15 XENOMIPS_FS_NAME=${XENOMIPS_IMAGES_DIR}/xenomips1.img
17 # Config FS
18 CONFIG_FS_SIZE=1000k
19 CONFIG_FS_NAME=${XENOMIPS_IMAGES_DIR}/xenomips-configXXX.img # XXX will be automagically substitued with
20 CONFIG_FS_NUMBER=5 # the number of the Xenomips instance
22 # IOS FS
23 IOS_FS_SIZE=2048k
24 IOS_FS_NAME=${XENOMIPS_IMAGES_DIR}/xenomips-ios1.img
26 DEBIAN_MIRROR=ftp://debian.org.ua/debian
27 DISTRO=etch
28 PACKAGES="openssh-server libc6-xen libelf1 libpcap0.8 screen nfs-common quagga tcpdump telnet ntpdate hping3 openntpd"
29 DYNAMIPS_SOURCES=http://www.ipflow.utc.fr/dynamips/dynamips-0.2.7.tar.gz
30 DYNAMIPS_BUILD_DIR=dynamips/
31 KERNEL_VERSION=`uname -r`
34 WORK_DIR=${XENOMIPS_FS_NAME%%.img}
35 WORK_DIR2=/tmp/xenomips-build
37 myecho()
38 {
39 echo '**************************'
40 echo "$@"
41 echo '**************************'
42 }
44 build_and_install_dynamips()
45 {
46 OLD_PWD="`pwd`"
47 DESTDIR=${WORK_DIR}/usr
49 if echo $DYNAMIPS_BUILD | grep -qi ^y
50 then
51 rm -rf ${DYNAMIPS_BUILD_DIR}/
52 mkdir -p ${DYNAMIPS_BUILD_DIR}/
53 cd ${DYNAMIPS_BUILD_DIR}/
54 wget $DYNAMIPS_SOURCES
55 tar xfz dynamips*tar*
56 cd dynamips*/
57 perl -p -i -e s@^PCAP_LIB=.*@PCAP_LIB=-lpcap@ Makefile
58 make
59 else
60 cd ${DYNAMIPS_BUILD_DIR}/dynamips*/
61 fi
62 make install DESTDIR=${DESTDIR}
63 cd ${OLD_PWD}
64 }
66 myecho Preparing the Xenomips filesystem
67 dd if=/dev/zero of=${XENOMIPS_FS_NAME} seek=${XENOMIPS_FS_SIZE} bs=1024 count=1
68 mkfs.ext3 -F ${XENOMIPS_FS_NAME}
69 mkdir -p ${WORK_DIR} ${WORK_DIR2}
70 mount -o loop ${XENOMIPS_FS_NAME} ${WORK_DIR}
71 debootstrap ${DISTRO} ${WORK_DIR} ${DEBIAN_MIRROR}
72 cat <<SCRIPT | chroot ${WORK_DIR} sh -s
73 unset LANG
74 apt-get -y --force-yes install ${PACKAGES}
75 /etc/init.d/ssh stop
76 cat <<FSTAB > /etc/fstab
77 proc /proc proc defaults 0 0
78 tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0
80 /dev/hda1 / ext3 ro 0 0
81 /dev/hda2 /xenomips/ios ext3 ro 0 0
82 /dev/hda3 /xenomips/config ext3 rw 0 0
83 FSTAB
84 mkdir -p /data/Cisco_IOS /xenomips
86 cat <<EOF > /etc/sysctl.conf
87 net/ipv4/ip_forward=1
88 EOF
90 cat <<'INTERFACES' > /etc/network/interfaces
91 auto lo eth0
93 iface lo inet loopback
94 up for i in \`ifconfig -a | grep 'eth.*Link encap' | awk '{print \$1}'\`; do ifconfig \$i up ; done || true
96 #iface eth0 inet dhcp
97 INTERFACES
99 echo /usr/local/bin/xenomips.sh > /etc/rc.local
100 cd /etc/rcS.d; ln -s ../init.d/xenomips-init S35xenomips-init
101 rm /etc/rc2.d/S*quagga
103 #perl -i -p -e s@C_PATH=/etc/quagga@C_PATH=/xenomips/etc/quagga@ /etc/init.d/quagga
104 mv /etc/quagga /etc/quagga.ORIG
105 ln -s /xenomips/config/etc/quagga /etc/quagga
107 mkdir -p /xenomips/{ios,config,dynamips} /var/lib/xenomips /root/.ssh
109 cat <<PROFILE >> /root/.profile
110 TERM=linux
111 screen -ls | grep -q Attached && screen -x || screen -ls | grep -q Detached && screen -r
112 PROFILE
113 SCRIPT
115 for kernel_version in ${KERNEL_VERSION} 2.6.18-without-PAE-4-xen-686
116 do
117 cp -R /lib/modules/${KERNEL_VERSION} ${WORK_DIR}/lib/modules
118 done
120 cp ${XENOMIPS_DIR}/xenomips-init ${WORK_DIR}/etc/init.d/
121 cp ${XENOMIPS_DIR}/xenomips.sh ${WORK_DIR}/usr/local/bin
122 sudo chmod +x ${WORK_DIR}/usr/local/bin/xenomips.sh ${WORK_DIR}/etc/init.d/xenomips-init
124 cat ${SSH_OPEN_KEY} > ${WORK_DIR}/root/.ssh/authorized_keys
125 chmod 600 ${WORK_DIR}/root/.ssh/authorized_keys
127 build_and_install_dynamips
129 mv ${WORK_DIR}/etc/quagga.ORIG ${WORK_DIR2}/quagga
130 perl -i -p -e 's/=no/=yes/' ${WORK_DIR2}/quagga/daemons
131 touch ${WORK_DIR2}/quagga/{zebra,bgpd,ospfd,ripd,ripngd,ospf6d,isisd}.conf
132 umount ${WORK_DIR}
134 if echo $CONFIG_FS_BUILD | grep -qi ^y
135 then
136 myecho Preparing the Xenomips config filesystem
137 dd if=/dev/zero of=${CONFIG_FS_NAME} bs=1k count=1 seek=${CONFIG_FS_SIZE}
138 mkfs.ext3 -F ${CONFIG_FS_NAME}
140 mount -o loop ${CONFIG_FS_NAME} ${WORK_DIR}
141 mkdir -p ${WORK_DIR}/etc
142 mv ${WORK_DIR2}/quagga ${WORK_DIR}/etc
143 umount ${WORK_DIR}
145 myecho Creating $CONFIG_FS_NUMBER copies of the Xenomips config filesystem
146 for i in `seq 1 $CONFIG_FS_NUMBER`
147 do
148 cp ${CONFIG_FS_NAME} `echo ${CONFIG_FS_NAME} | sed s/XXX/$i/`
149 done
150 fi
153 if echo $IOS_FS_BUILD | grep -qi ^y
154 then
155 myecho Preparing the filesystem with the IOSes
156 dd if=/dev/zero of=${IOS_FS_NAME} bs=1k count=1 seek=${CONFIG_FS_SIZE}
157 mkfs.ext3 -F ${IOS_FS_NAME}
158 mount -o loop ${IOS_FS_NAME} ${WORK_DIR}
159 cp ${IOS_DIR}/* ${WORK_DIR}
160 umount ${WORK_DIR}
161 fi