Skip to content

qemu-system-x86_64 fails to run with regular user after following arch wiki article

Host environment

  • Operating system: Arch Linux
  • OS/kernel version: Linux computer 5.11.9-arch1-1 #1 SMP PREEMPT Wed, 24 Mar 2021 18:53:54 +0000 x86_64 GNU/Linux
  • Architecture: x86
  • QEMU flavor: qemu-system-x86_64
  • QEMU version: QEMU emulator version 5.2.0
  • QEMU command line: qemu-system-x86_64 --version

Description of problem

When qemu-system-x86_64 binary is run with a regular user, it fails with no output. No matter if it's run with --help, --version or any other parameter. By checking the resulting error code (echo $?) it is possible to see that it finished with error code 1.

After seeing this post on reddit, it became clear that the reason was that my /etc directory had a subdirectory qemu, in which my regular user did not have access to. That is, qemu binary looks for /etc/qemu/qemu.conf and if it can't determine if the file is there or not, it fails.

Here goes the logic: strace showed the permission error (even though there was no output to indicate that).

$ strace /usr/bin/qemu-system-x86_64

mmap(NULL, 4928, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_POPULATE, 3, 0) = 0x7f4d01e6e000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_POPULATE, 3, 0x10000000) = 0x7f4d01e6c000
eventfd2(0, EFD_CLOEXEC|EFD_NONBLOCK)   = 4
sysinfo({uptime=92539, loads=[109952, 80640, 118144], totalram=16643309568, freeram=5314445312, sharedram=2590158848, bufferram=1301561344, totalswap=20479733760, freeswap=19551150080, procs=1202, totalhigh=0, freehigh=0, mem_unit=1}) = 0
rt_sigaction(SIGPIPE, {sa_handler=SIG_IGN, sa_mask=~[RTMIN RT_1], sa_flags=SA_RESTORER, sa_restorer=0x7f4d01ad7960}, NULL, 8) = 0
openat(AT_FDCWD, "/etc/qemu/qemu.conf", O_RDONLY) = -1 EACCES (Permission denied)
exit_group(1)                           = ?
+++ exited with 1 +++

The thing was that initially that folder did not exist, and I created it to make the qemu bridges work, like indicated in this arch wiki article. I will be suggesting modifications to that article.

When the directory did not exit, qemu noticed that the folder didn't exist and moved on, once it was created, in case the regular user had no access to it, it fails with no warning.

I just gave access to the folder ant it worked again (if you delete the folder it works too).

If you use libvirt, by using virsh for example, you may not notice this issue as it may be running as system (by setting the following system variable export LIBVIRT_DEFAULT_URI='qemu:///system')

So, to fix this issue, in my opinion a warning should be printed out to the stderr. Otherwise, qemu could move on if it doens't have access to /etc/qemu/qemu.conf.

Edited by adriano-pinaffo
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information