Running as root, obviously:
apt install -y qemu-kvm libvirt-bin bridge-utils virtinst
systemctl status libvirtd
A virtual bridge must now be present:
brctl show
cd /var/lib/libvirt
qemu-img create -f qcow2 images/hellovm-5.qcow2 10G
This creates a hard drive of size 10 gigs, enough for our sample
cd images && wget https://releases.ubuntu.com/18.04/ubuntu-18.04.5-live-server-amd64.iso && cd ..
virt-install --virt-type kvm \
--name hellovm-5 \
--ram 2048 \
--disk images/hellovm-5.qcow2,format=qcow2 \
--network network=default \
--graphics vnc,listen=0.0.0.0 \
--noautoconsole \
--cdrom boot/ubuntu-18.04.5-live-server-amd64.iso
Most important:
- without
--noautoconsole
, the creation process hung for more than 15 minutes. - without
listen=0.0.0.0
, I was not able to connect to the guest using VNC.
virsh vncdisplay hellovm-5
Make a note of the port. I installed TigerVNC on my Windows desktop to complete the installation.
The VNC port from the above command was 5900
.
Use puttygen to create an SSH key and save the private key so it can be used by pageant.
"c:\Program Files (x86)\PuTTY\puttygen.exe"
The server hosting the KVM machines is hostA
below.
Copy the exported OpenSSH key over to [email protected]:.ssh/authorized_keys
The following command (on Windows) opens an SSH tunnel to hostA
"c:\Program Files (x86)\PuTTY\plink.exe" -v -N -L 5900:hostA.example.com:5900 [email protected]
We connect to the VNC server on 5900 on the localhost thanks to the tunnel established above.
All set now. You can proceed with the installation of the guest OS.
You don't have to do this, but in case you need to:
On the host:
apt install libguestfs-tools
Ensure that the guest is shutdown.
``shell virsh shutdown
Now you can update the root password on the guest with (setting password to `PASSWORD`):
```shell
virt-customize -a <path to guest disk file> --root-password password:PASSWORD
First shutdown the VM
virsh shutdown <vmID>
Next, destroy the VM
virsh destroy <vmName>
And finally, undefine it (somewhat wonky, I know)
virsh undefine <vmName>
And now you have given it the final rites.