Last active
May 29, 2018 21:21
-
-
Save devisnotnull/18cf9b3422ad170a7aca2acba69b2758 to your computer and use it in GitHub Desktop.
KVM virt-install Ubuntu 18.04
This file contains hidden or 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 [ $# -ne 1 ] ; then | |
echo 'Please provide a name for the virtual machine ' | |
exit 1 | |
fi | |
############################################ | |
function print_with_line_numbers { | |
local IFS=$'\n' | |
local lines=($1) | |
local i | |
echo ${lines[0]} | |
} | |
############################################ | |
# Download boot iso | |
sudo wget http://releases.ubuntu.com/18.04/ubuntu-18.04-live-server-amd64.iso -O /var/lib/libvirt/boot/ubuntu-18.04.iso | |
NAME=$1 | |
# Create new VM, Note that you can connect to this machine via ssh reverse proxy and the VNC client | |
virt-install --virt-type=kvm \ | |
--name $NAME --ram 2048 --vcpus=1 \ | |
--os-variant=ubuntu17.04 --cdrom=/var/lib/libvirt/boot/ubuntu-18.04-live-server-amd64.iso \ | |
--graphics vnc --network bridge:vmbr2,model=virtio \ | |
--disk path=/var/lib/libvirt/images/$NAME.qcow2,size=40,bus=virtio,format=qcow2 \ | |
--noautoconsole | |
############################################ | |
# You should get something similar to below | |
# <graphics type='vnc' port='5900' autoport='yes' listen='127.0.0.1'> | |
ITEM=$(virsh dumpxml $NAME | grep vnc) | |
############################################ | |
RESULT="$(echo $ITEM | grep -oE '[0-9-]+')" | |
PORT=$(print_with_line_numbers "$RESULT") | |
# You will now need to forward the previous port number over ssh to your host; Change 5900 as required | |
# ssh [email protected] -L 5900:127.0.0.1:5900 | |
echo "VNC PORT TO CONNECT TO "$PORT | |
echo "Proxy command : ssh [email protected] -L $PORT:127.0.0.1:$PORT" | |
# Now open the VNC client app, Create a new connection to 127.0.0.1:5900 and BOOSH your in |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment