Skip to content

Instantly share code, notes, and snippets.

@afresh1
Last active December 17, 2015 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afresh1/5522905 to your computer and use it in GitHub Desktop.
Save afresh1/5522905 to your computer and use it in GitHub Desktop.
This sets up and starts a couple OpenBSD carped virtual machines using qemu and flashrd.
#!/bin/sh
# 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 to copy the images
test_path=`mktemp -d`
# And setup the path where we can find cfgflashrd
flashrd_root=$PWD
cd $test_path
### XXX NOTE XXX ###
# This is going to remove ./test in $test_path
####################
rm -r test
# This started as is a shell archive. Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file". Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
# test/
# test/rtr01
# test/rtr01/etc
# test/rtr01/etc/hostname.vlan10
# test/rtr01/etc/hostname.fxp0
# test/rtr01/etc/hostname.carp10
# test/rtr02
# test/rtr02/etc
# test/rtr02/etc/hostname.carp10
# test/rtr02/etc/hostname.fxp0
# test/rtr02/etc/hostname.vlan10
#
echo c - test/
mkdir -p test/ > /dev/null 2>&1
echo c - test/rtr01
mkdir -p test/rtr01 > /dev/null 2>&1
echo c - test/rtr01/etc
mkdir -p test/rtr01/etc > /dev/null 2>&1
echo x - test/rtr01/etc/hostname.vlan10
sed 's/^X//' >test/rtr01/etc/hostname.vlan10 << 'END-of-test/rtr01/etc/hostname.vlan10'
Xvlandev fxp0
Xinet 192.168.2.1/24
END-of-test/rtr01/etc/hostname.vlan10
echo x - test/rtr01/etc/hostname.fxp0
sed 's/^X//' >test/rtr01/etc/hostname.fxp0 << 'END-of-test/rtr01/etc/hostname.fxp0'
Xinet 10.0.1.1/24
END-of-test/rtr01/etc/hostname.fxp0
echo x - test/rtr01/etc/hostname.carp10
sed 's/^X//' >test/rtr01/etc/hostname.carp10 << 'END-of-test/rtr01/etc/hostname.carp10'
Xcarpdev vlan10
Xvhid 10
Xinet 192.168.2.100/24
END-of-test/rtr01/etc/hostname.carp10
echo c - test/rtr02
mkdir -p test/rtr02 > /dev/null 2>&1
echo c - test/rtr02/etc
mkdir -p test/rtr02/etc > /dev/null 2>&1
echo x - test/rtr02/etc/hostname.carp10
sed 's/^X//' >test/rtr02/etc/hostname.carp10 << 'END-of-test/rtr02/etc/hostname.carp10'
Xcarpdev vlan10
Xvhid 10
Xadvskew 100
Xinet 192.168.2.100/24
END-of-test/rtr02/etc/hostname.carp10
echo x - test/rtr02/etc/hostname.fxp0
sed 's/^X//' >test/rtr02/etc/hostname.fxp0 << 'END-of-test/rtr02/etc/hostname.fxp0'
Xinet 10.0.1.2/24
END-of-test/rtr02/etc/hostname.fxp0
echo x - test/rtr02/etc/hostname.vlan10
sed 's/^X//' >test/rtr02/etc/hostname.vlan10 << 'END-of-test/rtr02/etc/hostname.vlan10'
Xvlandev fxp0
Xinet 192.168.2.2/24
END-of-test/rtr02/etc/hostname.vlan10
cd test
for d in */; do cd $d && tar czvf ../${d%/}.tgz *; cd -; done
cd ..
cd $flashrd_root
export ETHER=vether0
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 f in ${test_path}/test/*.tgz; do
[ -e $f ] || break
hostname=`basename ${f%.tgz}`
img=${test_path}/${hostname}.img
echo "$hostname [$img]"
cp ${flashrd_root}/$flashimg $img
sudo ${flashrd_root}/cfgflashrd -i $img -o $f -hostname $hostname
_mac=$(($_mac + 1 ))
_macaddr=macaddr=52:54:00:12:34:5${_mac}
qemu-system-x86_64 $img -net nic,model=i82551,${_macaddr} -net tap &
_pids="$_pids $!"
done
echo "Waiting for qemu to exit [$_pids]"
wait $_pids
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