6

My system is Arch Linux 5.17.9 running i3wm.

I am trying to start a VM which is configured in Virt-Manager and Qemu.

I have tried the command,

sudo virsh list --all

this brings up the installed VMs on Virt-Manager in the terminal.

I have then tried,

sudo virsh start "VM-Name"

This apparently starts the VM, but no window opens and I have to open the Virt-Manager machine manually. I want to run a single command and have the VM in a window appear.

Eventually I want to attach this command to a key binding on my i3 install and have it open with one keystroke.

2 Answers 2

8

There is a virt-manager command analog to the virt-viewer command from cas' answer:

# start the VM
virsh --connect qemu:///system start "VM-NAME"
# connect to the VM
virt-manager --connect qemu:///system --show-domain-console "VM-NAME"
3

I don't think that's possible. virsh and virt-manager are both front-ends for controlling libvirtd - the former is a CLI interface, the latter a GUI interface.

You could run something like sudo virsh start "VM-Name" && virt-viewer "VM-Name". And, of course, you could write a shell function or script to do that. For example:

#!/bin/bash

sudo virsh start "$1" && sudo virt-viewer "$1"

Note that this won't start virt-manager itself, it will just start virt-viewer (which is very similar to virt-manager's GUI console for your VM, but lacking several useful features like menu options or buttons to Reboot or Power Off the VM). If you wanted to make use of virt-manager's other features, you'd have to run that separately.


BTW, it's possible to run virsh and virt-viewer without sudo, depending on how libvirtd is configured on your system, and what group(s) your user account is a member of.

For example: on my Debian system, my user account (cas) is a member of the libvirt group. That allows me to run the following:

virsh --connect qemu:///system start VM-NAME &&
  virt-viewer --connect qemu:///system VM-NAME

You've mentioned arch-linux in your tags, so you should read https://wiki.archlinux.org/title/Libvirt for details on how libvird is set up on arch.

1
  • 1
    I had to first add myself to the libvirt group with sudo usermod -a -G libvirt user then I managed to get it all working thanks to this, #!/bin/bash virsh --connect qemu:///system start vm-name; virt-viewer --connect qemu:///system vm-name then added bindsym $mod+Shift+w exec /home/user/folder/vm-name.sh to my i3 config. It now starts and opens a window with a single keybinding. Also, I added assign [class="Virt-viewer"] $ws4 to my i3 config which opens it in a predetermined workspace. Don't forget to run chmod u+x /home/user/folder/vm-name.sh to make it executable.
    – Orcam
    Jun 3, 2022 at 4:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .