qemu/kvm: which VM's are running [Solved]

Kernels & Hardware, configuring network, installing services

qemu/kvm: which VM's are running [Solved]

Postby peer » 2020-12-10 13:53

As root I can easily show which VM's are running with the command "sudo virsh list --state-running" or "sudo virsh list --all"
Code: Select all
peer@debian:~$ sudo virsh list --state-running
[sudo] password for peer:
 Id   Name       State
--------------------------
 1    Debian10   running

How can I get the same information as user without sudo???????
Last edited by peer on 2020-12-11 14:53, edited 1 time in total.
peer
 
Posts: 150
Joined: 2017-03-26 10:14

Re: qemu/kvm: which VM's are running

Postby morgon » 2020-12-10 14:35

Your account needs to be in the "libvirt" user group.

Then you can run virsh without sudo.
morgon
 
Posts: 183
Joined: 2010-08-28 03:04

Re: qemu/kvm: which VM's are running

Postby CwF » 2020-12-11 01:20

Code: Select all
$ virsh --connect qemu:///session list --state-running

...or just -c
CwF
 
Posts: 872
Joined: 2018-06-20 15:16

Re: qemu/kvm: which VM's are running

Postby peer » 2020-12-11 08:06

I am member of the groups: libvirt and libvirt-qemu.

The virsh command needs root to show relevant info on my pc. My VM's are also owned by root.

So my question remains.

edit: When I use the command lsof I find the following
Code: Select all
peer@debian:~$ sudo lsof  +D /home/peer/Kvm/Images/
COMMAND    PID         USER   FD   TYPE DEVICE    SIZE/OFF     NODE NAME
qemu-syst 3327 libvirt-qemu   18u   REG   8,17 21478375424 42075670 /home/peer/Kvm/Images/Debian10.qcow2
peer@debian:~$ lsof -u libvirt-qemu
COMMAND    PID         USER   FD      TYPE DEVICE SIZE/OFF NODE NAME
qemu-syst 3327 libvirt-qemu  cwd   unknown                      /proc/3327/cwd (readlink: Permission denied)
qemu-syst 3327 libvirt-qemu  rtd   unknown                      /proc/3327/root (readlink: Permission denied)
qemu-syst 3327 libvirt-qemu  txt   unknown                      /proc/3327/exe (readlink: Permission denied)
qemu-syst 3327 libvirt-qemu NOFD                                /proc/3327/fd (opendir: Permission denied)
peer@debian:~$

The first command (with sudo) shows that the vm is running and that the user is libvirt-qemu.
The second command (with user libvirt-qemu) shows that there is activity (vm is running?)

Why is sudo needed in the firs command since I am in the group libvirt-qemu??
peer
 
Posts: 150
Joined: 2017-03-26 10:14

Re: qemu/kvm: which VM's are running

Postby morgon » 2020-12-11 11:23

Strange, sudo should not be needed.

On my system all files (both the xml-files and the storage-files) are owned by root, yet I can run virsh without sudo.

My account is only member of the libvirt group but not of the libvirt-qemu group, that is the only difference I can see but I very much doubt that this is the problem.
morgon
 
Posts: 183
Joined: 2010-08-28 03:04

Re: qemu/kvm: which VM's are running

Postby CwF » 2020-12-11 14:04

Code: Select all
$  virsh --connect qemu:///session list --state-running
 Id   Name   State
--------------------

$  virsh --connect qemu:///system list --state-running
 Id   Name       State
--------------------------
 2    fo...     running
 3    me...    running
 7    fa...   running
 9    sr...    running


and only libvirt group...no sudo, so I was opposite in my response above, sorry...
I use virsh in many GUI 'buttons' for many actions, no sudo, '--connect qemu:///system' is required.
CwF
 
Posts: 872
Joined: 2018-06-20 15:16

Re: qemu/kvm: which VM's are running

Postby peer » 2020-12-11 14:52

Solved:
I copied the file /etc/libvirt/libvirt.conf to /home/peer/.config/libvirt/libvirt.conf and uncommented the line "uri_default = "qemu:///system".

Now I can can use the virsh command as normal user.


I found this solution here: "https://serverfault.com/questions/803283/how-do-i-list-virsh-networks-without-sudo"
peer
 
Posts: 150
Joined: 2017-03-26 10:14

Re: qemu/kvm: which VM's are running [Solved]

Postby CwF » 2020-12-11 15:15

peer wrote: /home/peer/.config/libvirt/libvirt.conf


Good to know, good job!
CwF
 
Posts: 872
Joined: 2018-06-20 15:16


Return to System configuration

Who is online

Users browsing this forum: No registered users and 14 guests

fashionable