diff options
author | Lars Wirzenius <liw@liw.fi> | 2020-05-03 11:49:43 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2020-05-03 11:49:43 +0300 |
commit | f249a884b0351c5bc6ed6af9b9985fe17a022e90 (patch) | |
tree | 351ab8e887f1d15f6efec7aea803a82cb9ff40fd /vm-qemu.sh | |
parent | fe338b9dd6abdbcbe4f7dd63a702a3511edaaa57 (diff) | |
download | ick-contractor-f249a884b0351c5bc6ed6af9b9985fe17a022e90.tar.gz |
Change: add script to run manager VM directly via Qemu
Diffstat (limited to 'vm-qemu.sh')
-rwxr-xr-x | vm-qemu.sh | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/vm-qemu.sh b/vm-qemu.sh new file mode 100755 index 0000000..2b8f550 --- /dev/null +++ b/vm-qemu.sh @@ -0,0 +1,51 @@ +#!/bin/sh +# +# Create a new VM using libvirt on the local host. + +set -eu + + +verbose() +{ + echo "INFO: $@" +} + + +die() +{ + echo "$@" 1>&2 + exit 1 +} + + +# Check parameters. + +if [ "$#" -lt 2 ] +then + die "Usage: $ IMAGE PORT" +fi + + +# Command line parameters: image file and port number for SSH. +image="$1" +port="$2" +verbose "creating VM from image $image" +verbose "once it's running, log in from another terminal: ssh -p $port manager@localhost" + +shift 2 + +# Does the image exist? +if [ ! -e "$image" ] +then + echo "$image does not exist" 1>&2 + exit 1 +fi + +# Start VM. +qemu-system-x86_64 \ + -enable-kvm \ + -m 8192 \ + -drive "file=$image,format=raw,if=virtio" \ + -device virtio-net,netdev=user.0 \ + -netdev "user,id=user.0,hostfwd=tcp::$port-:22" + |