Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Scripts to setup OpenBSD flashrd images and start qemu instances for each of them.
# Andrew Fresh <andrew AT> -
# This uses qemu, so pkg_add qemu
# Download and extract flashrd, either from github or here:
# Grab a flashrd image from here:
# and set the name:
# Set a path where you have space and permissions to copy the images
#test_path=`mktemp -d`
[ -z "$test_path" ] && echo 'You must set test_path' && exit
# And create some directories with configs in $test_path/configs
# Such as
# echo >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 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
echo "$hostname [$onetime] [$img]"
cd $hostdir && tar czvf $onetime ./
cd $flashrd_root
cp $flashimg $img
sudo ./cfgflashrd -i $img -o $onetime -hostname $hostname
# start_rtr needs to be someplace we can find it,
# flashrd_root seems a good place
cd $flashrd_root
./ $test_path
# Andrew Fresh <andrew AT> -
# 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=${test_path%/} # for the pgrep
export ETHER=vether0
ulimit -d 8388608
sudo ifconfig $ETHER up
sudo ifconfig bridge0 add $ETHER
#sudo ifconfig vlan10 vlandev $ETHER
for img in ${test_path}/*.img; do
_mac=$(($_mac + 1 ))
pgrep -f qemu.*$img && continue # don't start if already running
qemu-system-x86_64 $img -m 512M -net nic,model=i82551,${_macaddr} -net tap &
_pids="$_pids $!"
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