How do you install a VM with GUI via ssh on Ubuntu Server
Sophia Terry
I'm trying to install Windows 10 with virt-install on my Ubuntu Server LTS 20.04. I'm not really an expert on virtualization, but I try installing with:
$ virt-install --name=windows10 --vcpus=4 --memory=8192\
--cdrom=/mnt/data/iso/Win10_20H2_v2_EnglishInternational_x64.iso\
--disk /mnt/data/vm-images/win10-vm,size=50,format=qcow2,bus=virtio\
--network bridge=br0,model=virtio --os-type=win10 --os-variant=win10\
--graphics vncBut get the following warning, and it hangs at the Waiting for installation to complete. (probably because I need to access Windows GUI to actually install?).
WARNING Graphics requested but DISPLAY is not set. Not running virt-viewer.
WARNING No console to launch for the guest, defaulting to --wait -1
Starting install...
Allocating 'win10-vm' | 50 GB 00:00:06
Domain installation still in progress.
Waiting for installation to complete.I have a VNC client on my MacBook (TigerVNC 1.11.0 on macOS Big Sur), but I can't connect. A bit of searching tells me something about virt-install not finding a display (since no display is connected to the Ubuntu machine?), and something about X-forwarding in SSH, but I couldn't find a clear guide. Guides I could find all either use GUI on Linux machine, using virt-manager, or install VMs that only need SSH access. But I did this when I was testing oVirt on CentOS (headless) so I know it should be possible, but I can't figure out how to do from CLI (via SSH).
Could anyone point me to a (thorough, since I'm quite new at this) guide for how to install a VM that needs VNC access on a headless machine that I access via SSH?
31 Answer
Please don't mind my previous comment. This one is tested. You have to give some more parameters to --graphics option when you install the VM, as below:
$ virt-install --name=windows10 --vcpus=4 --memory=8192\ --cdrom=/mnt/data/iso/Win10_20H2_v2_EnglishInternational_x64.iso\ --disk /mnt/data/vm-images/win10-vm,size=50,format=qcow2,bus=virtio\ --network bridge=br0,model=virtio --os-type=win10 --os-variant=win10\ --graphics vnc,port=5901,listen=0.0.0.0`It specifies that server will listen to the VNC requests on all IPs, otherwise it listens to them on loopback address (127.0.0.1). After then, with the following command you will see the listening port of VNC:
virsh domdisplay windows10It must return something like: vnc://localhost:1 Then you can connect to your server with VNC at the specified port.