blob: 2b8f55045aed454204793d0c6af1a07d174fc8f1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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"
|