How to set up dynamic screen sizing for a qemu windows 10 guest on ubuntu 18.04?
I have a dual-boot setup on my laptop: Ubuntu 18.04 and Windows 10. From within ubuntu, I can boot to my existing windows partition using qemu with the help of this guide. The command I am using is this:
sudo qemu-system-x86_64 --enable-kvm -cpu host -smp 8 -m 8192 \
-drive format=raw,file=/dev/nvme0n1,index=1 \
-bios /usr/share/ovmf/OVMF.fd \
-display sdl -vga qxl \
-device qemu-xhci,id=xhci \
-netdev user,id=vmnic,smb=/home/generic/Downloads \
-device virtio-net,netdev=vmnic -cdrom ~/Downloads/virtio-win-0.1.171.iso
The last line was only to install the virtio drivers so I'm pretty sure I don't need it every time.
The second line determines the partition /dev/nvme0n1p1
.
The guide mentions SPICE, which is apparently good for
dynamic screen resize, clipboard between guest/host, etc.
I'd like to have the virtual screen change its size and adapt the resolution when I resize the window. I tried to follow the guide on https://www.linux-kvm.org/page/SPICE and realized that spicec
is no longer a thing - that means I cannot connect to the guest with spicec -h 127.0.0.1 -p 5900
.
The Spice User Manual agrees:
The recommended client is remote-viewer (which is shipped with virt-viewer).
GNOME Boxes can also be used as a Spice client.
spicec is an obsolete legacy client, and spicy is only a test application.
So I had a go with adding -spice port=5900,addr=127.0.0.1,disable-ticketing
to my qemu
command and running remote-viewer
on spice://127.0.0.1:5009
. That actually opened a spice window - so now I have two windows that show my win10 guest.
The Spice window reacts more nicely when it is resized, but it keeps the same resolution and just adds white borders when necessary.
The question
How can I get a borderless view of my guest system that adapts well to being resized?
And if that is not a completely distinct question: How can I have only one window for that, instead of both the qemu and the spice window?
Further Details
When I connected remote-viewer
, its console window showed
** (remote-viewer:3066): CRITICAL **: 15:54:52.441: virt_viewer_util_extract_host: assertion 'uri != NULL' failed
And the qemu
output showed
main_channel_link: add main channel client
main_channel_client_handle_pong: net test: latency 0.110000 ms, bitrate 34711864406 bps (33103.813559 Mbps)
inputs_connect: inputs channel client create
red_qxl_set_cursor_peer:
TL;DR
points 3 and 12 might be sufficient, depending on how other users have setup their VM. -- kaiya
Ozymandias42 suggested to try using virt-manager
as a frontend and stepped me through it.
- Install
virt-manager
on the host ubuntu - Set up a group so you can use the virt-manager without sudo
sudo groupadd --system libvirt sudo usermod -a -G libvirt $(whoami) su - $USER
- Start
virt-manager
and go toView -> Edit -> Preferences -> Console
. ActivateResize guest with window: On
- Use the icon on the top left to "Create a new virtual machine". I was uncertain there because I did not want a new machine, I just wanted to boot my dualboot windows partition. But that's the button. Choose "Import existing disk image"
- Choose your os type and version, and type your device as the path. I have used
/dev/nvme0n1
I am not certain if/how it is possible to only give the VM access to certain partitions (I first tried only giving it the EFI partition, but that of course did not work. Maybe it is possible to add each partition needed for windows as a separate virtual disk. Or maybe using confinedrv) - continue going through the windows, make sure to check "Customize configuration before install"
- In the customization window, I chose
Firmware: UEFI x86_64: /usr/share/OVMF/OVMF_CODE.fd
which I already had on my linux. I think I installed that usingapt install ovmf
but no guarantees. - Your disk was added as an "IDE Disk" which is okay but I'm told virtio is better because it is not emulating the disk. If you want to use virtio, the guest needs support for it though. And Ozymandias42 also told me that it's important to have a device/controller set up that actually uses the driver, at the time the driver is installed, because otherwise it won't be available at boot in an intiramfs-like state. So add a second disk, make it small, backed by some file, and set its disk bus type to virtio. You can remove it again after installing the virtio guest tools in the guest.
- Top left:
Begin Installation
again, this sounds scary. But it does not mess with the installed windows. - I had, on the guest, already installed the Qemu Guest Tools and the spice guest tools. I assume you need both. Also install the virtio guest tools exe and run it.
- Reboot. If everything works, you can remove the temporary disk and change the NIC to virtio as well.
- In the VM machine go to
View -> Scale Display -> Auto resize VM with window
You need to add a virtio-serial device for the VM to communicate with the spice client on the host. Had you used virt-manager with libvirtd instead of using qemu directly it most likely would have taken care of that for you automatically.
Try adding
-device virtio-serial-pci,id=virtio-serial0,bus=pci.3,addr=0x0
-chardev spicevms,id=charchannel1,name=vdagent
-device virtserialport,bus=virtio-serial0.0,nr=2,chardev=charchannel1,id=channel1,name=com.redhat.spice.0
If that doesn't work, I'd suggest using virt-manager as frontend.