Last active
August 27, 2020 22:25
-
-
Save Rio6/b15223a259c770cedcf041eb8d579f32 to your computer and use it in GitHub Desktop.
Some qemu scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/sh | |
IFACE=enp59s0f1 | |
test $UID -ne 0 && echo Need root && exit 1 | |
modprobe tun | |
s6-rc -v2 -d change dhcpcd | |
wait $(pgrep -x dhcpcd) | |
ip tuntap add dev tap0 mode tap | |
ip link add br0 type bridge | |
ip link set $IFACE down | |
ip link set $IFACE master br0 | |
ip link set tap0 master br0 | |
ip link set br0 up | |
ip link set $IFACE up | |
ip link set tap0 up | |
dhcpcd br0 | |
vde_switch -t tap0 -s /tmp/tap0 -m 775 -g rio | |
pkill -x dhcpcd | |
ip link set $IFACE down | |
ip link set tap0 down | |
ip link set br0 down | |
ip link del br0 | |
ip tuntap del tap0 mode tap | |
ip link set $IFACE up | |
s6-rc -v2 -u change dhcpcd | |
# Run vm with -net nic,macaddr=$MAC -net vde,sock=/tmp/tap0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if (($# < 1)); then | |
echo $0 name | |
exit | |
fi | |
if [ -e $1 ]; then | |
echo exists | |
exit | |
fi | |
mkdir "$1" | |
PORT=$(for i in {1080..1100}; do if ! grep PORT=$i */start.sh &> /dev/null; then echo $i; break; fi; done) | |
echo " | |
#!/bin/sh | |
cd \$(dirname $0) | |
PORT=$PORT | |
echo \$PORT | |
qemu-system-x86_64 -enable-kvm -m 2048 -drive "file=$1.img,if=virtio" -vga qxl -soundhw all -net nic,model=virtio,macaddr=\$(../macaddr.sh $1) -net vde,sock=/tmp/tap0/ -monitor stdio -spice port=\$PORT,disable-ticketing -device virtio-serial-pci -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 -chardev spicevmc,id=spicechannel0,name=vdagent \$@ | |
" > "$1/start.sh" | |
chmod +x "$1/start.sh" | |
qemu-img create -f qcow2 "$1/$1.img" 10G | |
echo Done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ -z $1 ]; then | |
echo "$0 <name>" 1>&2 | |
exit 1 | |
fi | |
S=$(md5sum <<< $1 | awk '{print toupper($0)}') | |
echo "52:54:00:${S:0:2}:${S:2:2}:${S:4:2}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
modprobe nbd | |
qemu-nbd -c /dev/nbd0 $1 | |
read -p Waiting... | |
qemu-nbd -d /dev/nbd0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/sh | |
test $UID -ne 0 && echo Need root && exit 1 | |
modprobe tun | |
ip tuntap add dev tap0 mode tap | |
sleep 0.5 | |
ip addr add 10.120.0.1/24 dev tap0 | |
ip link set tap0 up | |
iptables -t nat -A POSTROUTING -s 10.120.0.0/24 -j MASQUERADE | |
#iptables -I INPUT 1 -i tap0 -j ACCEPT | |
dnsmasq -p 0 -F 10.120.0.10,10.120.0.50,12h -O 6,1.1.1.1,1.0.0.1 -i tap0 -z | |
vde_switch -t tap0 -s /tmp/tap0 -m 775 -g rio | |
killall dnsmasq | |
#iptables -D INPUT -i tap0 -j ACCEPT | |
iptables -t nat -D POSTROUTING -s 10.120.0.0/24 -j MASQUERADE | |
ip tuntap del dev tap0 mode tap | |
# Run vm with -net nic,macaddr=$MAC -net vde,sock=/tmp/tap0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ -z $1 ]; then | |
echo "$0 <name>" 1>&2 | |
exit 1 | |
fi | |
cd $(dirname $0) | |
name=$1 | |
shift | |
qemu-system-x86_64 -enable-kvm -m 2048 -hda $name -net nic,macaddr=$(../macaddr.sh $name) -net vde,sock=/tmp/tap0/ -monitor stdio $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment