Improve the switching between virtual machines.
Improve the switching between virtual machines.
I currently host EndeavourOS and run Fedora as a guest, with Windows 10 also as a guest. GPU passthrough works well for both, using the iGPU for host display and virt-manager to manage VMs. The issue is that I frequently switch the monitor back to host mode when shutting down or starting a different VM. Someone with similar experience might suggest a solution to avoid this toggling. Ideally, I'd like to shut down the guest and use a keyboard shortcut to launch another VM, needing only a display switch for host configuration. Eventually, I want to run libvirt directly from the terminal without using DE or WM on the host.
I possess a quick link on my desktop, which executes a program to connect the keyboard and mouse to the virtual machine, while also disabling the host's display outputs. The screens then look for other inputs and locate the VM's GPU outputs, with the keyboard and mouse functioning as intended. On my Windows desktop (VM), I have a similar batch file for removing the keyboard and mouse using PuTTY to run a detach script on the host, followed by shutting down the VM's GPU display outputs. The process is reversed once the host's GPU goes to sleep and is recognized by the monitors. Closing down the VM automatically detaches the mouse and keyboard, so a simple tap or keystroke can reactivate the monitors. I’ll leave the scripts for you to adjust... attach.sh: #!/bin/bash sudo virsh attach-device $(sudo virsh list|awk '/Windows10AME/ {print $1}') ~/.config/mouse.xml && sudo virsh attach-device $(sudo virsh list|awk '/Windows10AME/ {print $1}') ~/.config/keyboard.xml && xset dpms force off The name between the /'s indicates the VM I'm connecting to, but virsh requires an ID number, hence the awk trick. mouse.xml shows a USB device on bus 3. keyboard.xml uses a different address from lsusb. detach.sh: #!/bin/bash sudo virsh detach-device $(sudo virsh list|awk '/Windows10AME/ {print $1}') # Removes the attached keyboard and mouse sudo virsh detach-device $(sudo virsh list|awk '/Windows10AME/ {print $1}') # Detaches the VM's GPU monitor outputs putty @detach nircmd.exe cmdwait 2000 monitor off I’m unsure if nircmd.exe is built-in, sorry. `@detach` is a saved PuTTY session that uses pub/priv keys and runs detach.sh before ending the SSH connection. I only use it when I need host access before powering down the guest. This setup could easily be copied for a Linux host. For full automation, you’d wrap virsh to start and stop the VM remotely via SSH/putty, though I’d probably want to also pass through the sound card so audio works without needing a viewer. If going completely headless, I’d use an autologin getty on a serial port with a script that tells it which VM to boot and ensures no other processes are running. YMMV—this is just a rough idea trying to shape it to your needs.**
This information is very helpful. I hadn't had a chance to review it before, but it gives a solid foundation for automating the process. I plan to explore it more tomorrow or the following day and share my results.