You are not logged in.

#1 2020-12-25 21:41:09

Adriano Epifas
Member
Registered: 2020-12-25
Posts: 17

[Solved] Can't run QEMU with regular non-root user

When I run /usr/bin/qemu-system-x86_64 with my regular non-root user there is no output, in fact, nothing runs.

Even a simple /usr/bin/qemu-system-x86_64 --version gives no feedback. When I try the same using sudo, it works just fine.

$ /usr/bin/qemu-system-x86_64 --version
$ sudo /usr/bin/qemu-system-x86_64 --version
QEMU emulator version 5.2.0
Copyright (c) 2003-2020 Fabrice Bellard and the QEMU Project developers

I have qemu 5.2.0-2 installed in arch with kernel 5.9.13. I usually start my VMs using libvirt's virsh start command, which works just fine. As you can see below, the VM is started by "nobody" user, when started from libvirt's virsh. For virsh, I'm running it with default URI set to system.

$ pacman -Q qemu
qemu 5.2.0-2

$ set | grep -i qemu
LIBVIRT_DEFAULT_URI=qemu:///system

$ virsh start debian9
Domain debian9 started

$ ps aux | grep qemu
nobody      8310 93.1  0.4 1719356 68472 ?       Sl   21:43   0:11 /usr/bin/qemu-system-x86_64 -name guest=debian9,debug-threads=on -S -object secret,id=masterKey0,format=raw,file=/var/lib/libvirt/qemu/domain-4-debian9/master-key.aes -machine pc-i440fx-4.1,accel=kvm,usb=off,dump-guest-core=off -cpu host,migratable=on -m 1024 -overcommit mem-lock=off -smp 2,sockets=2,cores=1,threads=1 -uuid 8d9bbe82-1ef6-4aa0-b383-76be87d21567 -no-user-config -nodefaults -chardev socket,id=charmonitor,fd=30,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=utc,driftfix=slew -global kvm-pit.lost_tick_policy=delay -no-hpet -no-shutdown -global PIIX4_PM.disable_s3=1 -global PIIX4_PM.disable_s4=1 -boot strict=on -device ich9-usb-ehci1,id=usb,bus=pci.0,addr=0x5.0x7 -device ich9-usb-uhci1,masterbus=usb.0,firstport=0,bus=pci.0,multifunction=on,addr=0x5 -device ich9-usb-uhci2,masterbus=usb.0,firstport=2,bus=pci.0,addr=0x5.0x1 -device ich9-usb-uhci3,masterbus=usb.0,firstport=4,bus=pci.0,addr=0x5.0x2 -blockdev {"driver":"file","filename":"/var/lib/libvirt/images/debian9.qcow2","node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"} -blockdev {"node-name":"libvirt-2-format","read-only":false,"driver":"qcow2","file":"libvirt-2-storage","backing":null} -device virtio-blk-pci,bus=pci.0,addr=0x4,drive=libvirt-2-format,id=virtio-disk0,bootindex=1 -device ide-cd,bus=ide.0,unit=0,id=ide0-0-0 -netdev tap,fd=32,id=hostnet0,vhost=on,vhostfd=33 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:dd:02:c2,bus=pci.0,addr=0x3 -netdev tap,fd=34,id=hostnet1 -device rtl8139,netdev=hostnet1,id=net1,mac=52:54:00:ea:d9:fc,bus=pci.0,addr=0x7 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -spice port=5900,addr=127.0.0.1,disable-ticketing,image-compression=off,seamless-migration=on -device qxl-vga,id=video0,ram_size=67108864,vram_size=16777216,vram64_size_mb=0,vgamem_mb=16,max_outputs=1,bus=pci.0,addr=0x2 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6 -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny -msg timestamp=on

I'm a member of the groups libvirt and kvm

$ id
uid=1000(myuser) gid=1000(myuser) groups=1000(myuser),108(vboxusers),150(wireshark),962(lightdm),965(docker),976(libvirt),984(systemd-journal),992(kvm),998(wheel),999(adm)

/dev/kvm has permission 666 (user root, group kvm)

 ls -l /dev/kvm
crw-rw-rw- 1 root kvm 10, 232 Dec 25 22:15 /dev/kvm

This is impacting other unrelated applications (like GNS3). I did some digging, posted some questions around, but I had no feedback. I also checked the Arch wiki, but could not find any help there.
Can anyone at least run /usr/bin/qemu-system-x86_64 --version with your regular user and tell me what the feedback is?

Does anyone have any idea what I can do to debug this?

Last edited by Adriano Epifas (2025-01-08 17:17:56)

Offline

#2 2020-12-26 11:38:38

BobsUrUncle
Member
Registered: 2020-12-22
Posts: 1

Re: [Solved] Can't run QEMU with regular non-root user

this is because to run qemu it requires root privileges to add ur user without the need to put in sudo privileges do: sudo usermod -aG kvm username
Next time RTFM

Offline

#3 2020-12-26 16:34:19

Adriano Epifas
Member
Registered: 2020-12-25
Posts: 17

Re: [Solved] Can't run QEMU with regular non-root user

BobsUrUncle wrote:

this is because to run qemu it requires root privileges to add ur user without the need to put in sudo privileges do: sudo usermod -aG kvm username
Next time RTFM

Really? You didn't even bother to read my post and told me to RTFM? Maybe you should RTF Post first... you would have seen I'm already a member of the kvm group

Offline

#4 2020-12-26 19:12:30

Ropid
Member
Registered: 2015-03-09
Posts: 1,069

Re: [Solved] Can't run QEMU with regular non-root user

I'd try creating a new user account and test how things behave when logged into that new user.

Offline

#5 2020-12-27 20:38:27

Adriano Epifas
Member
Registered: 2020-12-25
Posts: 17

Re: [Solved] Can't run QEMU with regular non-root user

Ropid wrote:

I'd try creating a new user account and test how things behave when logged into that new user.

I tried to create a new user, and I also tried making that user be a member of every single group I had in my machine. The result was the same.
When you try it there, does it show a proper output?

Offline

#6 2020-12-28 14:50:25

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 15,038

Re: [Solved] Can't run QEMU with regular non-root user

What is the output of pacman -Qkk qemu ?


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#7 2020-12-28 15:27:43

equalizer876
Member
Registered: 2018-09-11
Posts: 79

Re: [Solved] Can't run QEMU with regular non-root user

Why don't you just use libvirt or the easier GUI wrapper called virt-manager? You don't have to try too hard. Virt-Manager also runs on restricted users without sudo.

Last edited by equalizer876 (2020-12-28 15:28:35)

Offline

#8 2020-12-28 16:33:17

Adriano Epifas
Member
Registered: 2020-12-25
Posts: 17

Re: [Solved] Can't run QEMU with regular non-root user

Lone_Wolf wrote:

What is the output of pacman -Qkk qemu ?

The output is

$ pacman -Qkk qemu
qemu: 393 total files, 0 altered files

Weirdly enough, -Qk and -Qkk gives the same output

Offline

#9 2020-12-28 16:35:09

Adriano Epifas
Member
Registered: 2020-12-25
Posts: 17

Re: [Solved] Can't run QEMU with regular non-root user

equalizer876 wrote:

Why don't you just use libvirt or the easier GUI wrapper called virt-manager? You don't have to try too hard. Virt-Manager also runs on restricted users without sudo.

I do use libvirt and it works fine there. The problem is that I also use GNS3 (a network simulator), and GNS3 can use QEMU's devices in the simulation, but it won't recognize QEMU is installed because it is trying to run qemu-system-x86_64 commands with regular user.

Offline

#10 2021-02-08 08:34:55

scot
Member
Registered: 2017-04-22
Posts: 36

Re: [Solved] Can't run QEMU with regular non-root user

I apologize that the following is a mixture of science and voodoo. The fact is that now, after a few hours of trial-and-error, I can reliably make the user that owns the qemu-system-x86_64 process be any one of the users: "scott", "nobody", and "root"  --- and I can do this solely by typing!! No magical incantations are required. However, it would be unscientific of me NOT to admit that this all-too-rational state of affairs followed a certain amount of desperate fiddling -- or not to admit that when it first began to "work", it was after I did several things in a row, which made it seem like magic at the time.

OK, so first, the science: to get qmeu-system-x86_64 to run as (an existing non-root) user foo, I edit /etc/libvirt/qemu.conf and change the two lines: 
 
    #user=root 
    #group=root 

to 

    user=foo 
    group=kvm 

then I restart libvirtd.service: 
 
     #systemctl restart libvirtd.service 

and THEN I run virt-manager as user foo. 
   
If I want to run the qemu-system-x86_64 process as root, I restore the qemu.conf file to what it was before the above edits, restart libvirtd.service, <bold>AND</bold> I start virt-manager as root. 

If I run virt-manager as a regular non-root user, and libvirtd.service is running with a qemu.conf user/group configuration as root/root (which is the default if nothing is set), then qenu-system-x86_64 runs as "nobody". 
 
As for voodoo: at various points in the traditional ceremonial tearing-hair-out stage, I did such things as reboot the machine and chown foo.kvm /usr/bin/virt-manager. (I was thinking that it's virt-manager that spawns qemu-system-x86_64, and was hoping that there might be a non-sexist version of "like father, like son" that goes "like parent, like child"). But I don't think either one was "it". 
 
EDIT: One final bit of potential voodoo: Here is something else I did and then (maybe) had to undo to be able to actually boot a VM as (non-root) user foo. (The previous stuff enabled me to run the qemu-system-x86_64 process as me, but I still couldn't actually boot a VM, because of disk-access permission issues).   
 
One reads that disk devices are owned by root:disk, and that one way to enable user foo to access the device is to add user foo to the "disk" group. Well, in my case, at some point in the process of setting up dual-boot I had used gdisk to change some partition sizes. (Specifically, I shrank the 2nd "MS Reserved Partition" to grow the EFI system partition (so that it could hold that 123871928319283719 files that Windows puts there), and I shrank the NTFS partition to create a ext4 partition for Arch). As a result, it seems the partition devices were now owned by root:root, and the fact that user foo is in the "disk" group did NOT give me access.   
 
The fix, of course, was just to chown the various disk devices back to root:disk.   
 
I classify this as "voodoo" and not "science" because (as it happens smile), I had to fix a few other problems before my VM actually booted. I am quite sure that those "other problems" are unrelated to user identities, so no need to mention them here. But I can't **know** if changing the disk devices back to root:disk was something I HAD to do, or just something I did while on the road to qemu/kvm nirvana.

Last edited by scot (2021-02-09 16:47:43)

Offline

#11 2025-01-08 17:16:21

Adriano Epifas
Member
Registered: 2020-12-25
Posts: 17

Re: [Solved] Can't run QEMU with regular non-root user

This was solved using a Reddit article. Arch wiki was also adapted to show this.
https://www.gns3.com/gns3-cannot-work-with-qemu

Offline

Board footer

Powered by FluxBB