Skip to content

Instantly share code, notes, and snippets.

@lucasvr
Created March 9, 2017 05:35
Show Gist options
  • Save lucasvr/099251067dfef11ebc975e89ae01e0f8 to your computer and use it in GitHub Desktop.
Save lucasvr/099251067dfef11ebc975e89ae01e0f8 to your computer and use it in GitHub Desktop.
qemu.sh
#!/bin/bash
ISO=GoboLinux-016.01-x86_64.iso
IMG=sda.img
OUTIFACE=wlan0
NETWORK_OPTS="-net nic,macaddr=E0:06:E6:CE:FF:EE,model=virtio -net tap,ifname=tap1,script=no"
KVM_OPTS="-enable-kvm -cpu host -daemonize"
BOOT_DRIVE="$1"
if [ -z "$BOOT_DRIVE" ]
then
echo "Syntax: $0 <boot drive>"
exit 1
fi
sudo SDL_VIDEO_X11_DGAMOUSE=0 \
qemu-system-x86_64 \
-boot order=$BOOT_DRIVE \
-show-cursor \
-drive file=${IMG},media=disk,if=scsi,index=0,format=raw \
-drive file=${ISO},media=cdrom,if=scsi,index=1 \
-m 1024 \
-usb \
-usbdevice tablet \
-device usb-mouse \
-vga std \
-clock unix \
$KVM_OPTS \
$NETWORK_OPTS
sudo ifconfig tap1 10.1.1.1 netmask 255.255.255.0
sudo sysctl -w net.ipv4.ip_forward=1
sudo route add -host 10.1.1.2 dev tap1
sudo iptables -t nat -A POSTROUTING -o $OUTIFACE -j MASQUERADE
sudo iptables -I FORWARD 1 -i tap1 -j ACCEPT
sudo iptables -I FORWARD 1 -o tap1 -m state --state RELATED,ESTABLISHED -j ACCEPT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment