Scripts to setup OpenBSD flashrd images and start qemu instances for each of them.
#!/bin/sh | |
# Andrew Fresh <andrew AT afresh1.com> - https://gist.github.com/afresh1 | |
# This uses qemu, so pkg_add qemu | |
# Download and extract flashrd, either from github or here: | |
# http://www.nmedia.net/flashrd/ | |
# Grab a flashrd image from here: | |
# http://www.nmedia.net/flashrd/images/ | |
# and set the name: | |
flashimg=flashimg.amd64.pccons-20130318 | |
# Set a path where you have space and permissions to copy the images | |
#test_path=`mktemp -d` | |
#test_path=/mnt/memory/qemu | |
[ -z "$test_path" ] && echo 'You must set test_path' && exit | |
flashrd_root=$PWD | |
# And create some directories with configs in $test_path/configs | |
# Such as | |
# echo 10.100.1.1/24 >configs/router01/etc/hostname.em0 | |
# and configs/router02/etc/pf.conf, configs/router02/var/www/htdocs/index.html | |
# | |
# Newer versions of flashrd should support a flashrd.site to run post extraction | |
# scripts, so you could do more advanced configuration with that. | |
# | |
# Each directory will create a flashrd image with a hostname with that name | |
cd $test_path/configs | |
for d in */; do | |
hostname=${d%/} | |
hostdir=${PWD}/${hostname} | |
onetime=${hostdir}.tgz | |
img=${test_path}/${hostname}.img | |
echo "$hostname [$onetime] [$img]" | |
cd $hostdir && tar czvf $onetime ./ | |
cd $flashrd_root | |
cp $flashimg $img | |
sudo ./cfgflashrd -i $img -o $onetime -hostname $hostname | |
done | |
# start_rtr needs to be someplace we can find it, | |
# flashrd_root seems a good place | |
cd $flashrd_root | |
./start_images.sh $test_path |
#!/bin/sh | |
# Andrew Fresh <andrew AT afresh1.com> - https://gist.github.com/afresh1 | |
# This will start a qemu instance for each of the .img files in the directory | |
# passed on the command line (or cwd). It also sets up a vether device and | |
# in the same bridge that the qemu em0 will be attached to. | |
# | |
# It only supports a single bridge with all routers in the same bridge. | |
test_path=${1:-.} | |
test_path=${test_path%/} # for the pgrep | |
export ETHER=vether0 | |
ulimit -d 8388608 | |
sudo ifconfig $ETHER 10.0.1.99/24 up | |
sudo ifconfig bridge0 add $ETHER | |
#sudo ifconfig vlan10 vlandev $ETHER 192.168.2.99/24 | |
_mac=0 | |
_pids='' | |
for img in ${test_path}/*.img; do | |
_mac=$(($_mac + 1 )) | |
pgrep -f qemu.*$img && continue # don't start if already running | |
_macaddr=macaddr=52:54:00:12:34:5${_mac} | |
qemu-system-x86_64 $img -m 512M -net nic,model=i82551,${_macaddr} -net tap & | |
_pids="$_pids $!" | |
done | |
echo "Waiting for qemu to exit [$_pids]" | |
wait $_pids | |
# This is fairly destructive, but tries to cleanup after qemu | |
# probably overkill and doesn't work extremely well, but it | |
# generally doesn't break anything in my setup. | |
ifconfig | sed -ne 's/^\([a-z0-9]*\):.*/\1/p' | | |
grep -e tun -e bridge -e vlan -e vether | | |
xargs -I % sudo ifconfig % destroy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment