Created
October 18, 2018 14:12
-
-
Save alanorth/f7bdca2efac0eef670f43f6b09ba199a to your computer and use it in GitHub Desktop.
Script to launch QEMU in user mode
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
#!/usr/bin/env bash | |
# | |
# See: https://drewdevault.com/2018/09/10/Getting-started-with-qemu.html | |
# See: https://wiki.archlinux.org/index.php/QEMU | |
# | |
# Host preparation (as root): | |
# | |
# ip link add br0 type bridge | |
# ip addr add 172.20.0.1/16 dev br0 | |
# ip link set br0 up | |
# ip tuntap add dev tap0 mode tap user aorth | |
# ip link set tap0 up promisc on | |
# brctl addif br0 tap0 | |
# | |
NAME=web01 | |
ISO=/home/aorth/Downloads/ubuntu-18.04.1-live-server-amd64.iso | |
HD1=/home/aorth/src/web01.qcow2 | |
# See: https://blogs.igalia.com/berto/2015/12/17/improving-disk-io-performance-in-qemu-2-5-with-the-qcow2-l2-cache/ | |
HD1_L2CACHE_SIZE=2621440 | |
MEM=4096 | |
TAP_DEVICE=tap0 | |
SPICE_PORT=5930 | |
function install() { | |
qemu-system-x86_64 \ | |
-daemonize \ | |
-enable-kvm \ | |
-cpu host \ | |
-m ${MEM} \ | |
-nic user,model=virtio \ | |
-nic tap,ifname=${TAP_DEVICE},script=no,downscript=no,model=virtio \ | |
-drive file=${HD1},l2-cache-size=${HD1_L2CACHE_SIZE},media=disk,if=virtio \ | |
-cdrom ${ISO} \ | |
-boot order=d \ | |
-vga qxl \ | |
-spice port=${SPICE_PORT},disable-ticketing | |
} | |
function run() { | |
qemu-system-x86_64 \ | |
-daemonize \ | |
-enable-kvm \ | |
-cpu host \ | |
-m ${MEM} \ | |
-nic user,model=virtio \ | |
-nic tap,ifname=${TAP_DEVICE},script=no,downscript=no,model=virtio \ | |
-drive file=${HD1},l2-cache-size=${HD1_L2CACHE_SIZE},media=disk,if=virtio \ | |
-boot order=c \ | |
-vga qxl \ | |
-spice port=${SPICE_PORT},disable-ticketing | |
} | |
# install if -i is passed, otherwise just run | |
if [[ $# -eq 1 && $1 == "-i" ]]; then | |
echo -n "Installing ${NAME}..." | |
install | |
else | |
echo -n "Running ${NAME}..." | |
run | |
fi | |
echo " connect via SPICE:" | |
echo | |
echo -e "\tspicy -h 127.0.0.1 -p ${SPICE_PORT}" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment