Skip to content

Instantly share code, notes, and snippets.

@tatumroaquin
Last active May 3, 2024 19:28
Show Gist options
  • Star 25 You must be signed in to star a gist
  • Fork 13 You must be signed in to fork a gist
  • Save tatumroaquin/c6464e1ccaef40fd098a4f31db61ab22 to your computer and use it in GitHub Desktop.
Save tatumroaquin/c6464e1ccaef40fd098a4f31db61ab22 to your computer and use it in GitHub Desktop.
QEMU-KVM Installation for Arch Linux

Arch Linux QEMU-KVM

install all necessary packages

sudo pacman -S virt-manager virt-viewer qemu qemu-arch-extra \
edk2-ovmf vde2 ebtables dnsmasq bridge-utils openbsd-netcat libguestfs

enable libvirt daemon

systemctl enable libvirtd.service
systemctl start libvirtd.service

create bridge interface

sudo nvim br10.xml

<network>
  <name>br10</name>
  <forward mode='nat'>
    <nat>
      <port start='1024' end='65535'/>
    </nat>
  </forward>
  <bridge name='br10' stp='on' delay='0'/>
  <ip address='192.168.30.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.30.50' end='192.168.30.200'/>
    </dhcp>
  </ip>
</network>

define and autostart network bridge

sudo virsh net-define br10.xml
sudo virsh net-start br10
sudo virsh net-autostart br10

enable normal user account to use KVM

sudo nvim /etc/libvirt/libvirtd.conf

unix_sock_group = "libvirt"
unix_sock_ro_perms = "0777"
unix_sock_rw_perms = "0770"

add current user to kvm and libvirt groups

sudo usermod -a -G kvm $(whoami)
sudo usermod -a -G libvirt $(whoami)
newgrp libvirt

enable nested virtulization (optional)

sudo modprobe -r kvm_intel
sudo modprobe kvm_intel nested=1
echo "options kvm-intel nested=1" | sudo tee /etc/modprobe.d/kvm-intel.conf

verify nested virtualization

systool -m kvm_intel -v | grep nested
cat /sys/module/kvm_intel/parameters/nested
@tuananh
Copy link

tuananh commented Apr 13, 2024

@tatumroaquin I'm getting error error: target not found: qemu-arch-extra. Looks like that package doesn't exists?

@tatumroaquin
Copy link
Author

@tuananh I think the package did exists at the time of writing this gist, I guess either they've renamed the package to something else or they've demoted it to the AUR.

But the qemu-arch-extra-git package is still available in the AUR, you can check it with yay -Ss qemu-arch-extra, you may want to use that instead.

@tuananh
Copy link

tuananh commented Apr 13, 2024

@tatumroaquin thanks. lemme try that

@tatumroaquin
Copy link
Author

@tuananh Do keep in mind that the network config recipe here has only been tested on direct cable Ethernet connection. I did not manage to make it work via hosts running on wireless card (Wi-Fi), such as laptop machines.

This gist is quite old, I've not updated it in two years, so if it works for you that's great, if not don't waste too much time on it.

@KSHMR1337
Copy link

Nice and quick guide, kudos!

@NullifyDev
Copy link

I have gotten this error from building qemu-arch-extra-git:

FAILED: libqemu-hexagon-linux-user.fa.p/target_hexagon_op_helper.c.o 
cc -m64 -mcx16 -Ilibqemu-hexagon-linux-user.fa.p -I. -I.. -Itarget/hexagon -I../target/hexagon -I../common-user/host/x86_64 -I../linux-user/include/host/x86_64 -I../linux-user/include -Ilinux-user -I../linux-user -I../linux-user/hexagon -Iqapi -Itrace -Iui -Iui/shader -I/usr/include/capstone -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/sysprof-6 -fdiagnostics-color=auto -Wall -Winvalid-pch -std=gnu11 -O2 -g -fstack-protector-strong -Wempty-body -Wendif-labels -Wexpansion-to-defined -Wformat-security -Wformat-y2k -Wignored-qualifiers -Wimplicit-fallthrough=2 -Winit-self -Wmissing-format-attribute -Wmissing-prototypes -Wnested-externs -Wold-style-declaration -Wold-style-definition -Wredundant-decls -Wshadow=local -Wstrict-prototypes -Wtype-limits -Wundef -Wvla -Wwrite-strings -Wno-missing-include-dirs -Wno-psabi -Wno-shift-negative-value -isystem /home/saturn/.cache/paru/clone/qemu-git/src/qemu/linux-headers -isystem linux-headers -iquote . -iquote /home/saturn/.cache/paru/clone/qemu-git/src/qemu -iquote /home/saturn/.cache/paru/clone/qemu-git/src/qemu/include -iquote /home/saturn/.cache/paru/clone/qemu-git/src/qemu/host/include/x86_64 -iquote /home/saturn/.cache/paru/clone/qemu-git/src/qemu/host/include/generic -iquote /home/saturn/.cache/paru/clone/qemu-git/src/qemu/tcg/i386 -Wno-unused-function -pthread -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-common -fwrapv -ftrivial-auto-var-init=zero -fzero-call-used-regs=used-gpr -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=3 -Wformat -Werror=format-security -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fPIE -isystem../linux-headers -isystemlinux-headers -DCOMPILING_PER_TARGET '-DCONFIG_TARGET="hexagon-linux-user-config-target.h"' '-DCONFIG_DEVICES="hexagon-linux-user-config-devices.h"' -MD -MQ libqemu-hexagon-linux-user.fa.p/target_hexagon_op_helper.c.o -MF libqemu-hexagon-linux-user.fa.p/target_hexagon_op_helper.c.o.d -o libqemu-hexagon-linux-user.fa.p/target_hexagon_op_helper.c.o -c ../target/hexagon/op_helper.c
during RTL pass: ira
In file included from ../target/hexagon/op_helper.c:1496:
target/hexagon/helper_funcs_generated.c.inc: In function ‘helper_V6_vgathermw’:
target/hexagon/helper_funcs_generated.c.inc:2347:1: internal compiler error: Segmentation fault
 2347 | }
      | ^
0x1905658 internal_error(char const*, ...)
	???:0
0xa9fb38 ira_soft_conflict(ira_allocno*, ira_allocno*)
	???:0
0xa74469 ira_traverse_loop_tree(bool, ira_loop_tree_node*, void (*)(ira_loop_tree_node*), void (*)(ira_loop_tree_node*))
	???:0
0xab06d4 ira_color()
	???:0
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues> for instructions.
[3611/9734] Compiling C object libqemu-hexagon-linux-user.fa.p/target_hexagon_genptr.c.o
ninja: build stopped: subcommand failed.
==> ERROR: A failure occurred in build().
    Aborting...
error: failed to build 'qemu-git-22:9.0.0.r92.g88daa112d4-1 (qemu-git qemu-arch-extra-git)': 
error: packages failed to build: qemu-git-22:9.0.0.r92.g88daa112d4-1 (qemu-git qemu-arch-extra-git)

Does anyone know about this error? Im on Endeavour OS v6.8.7-zen1-2-zen

@KSHMR1337
Copy link

I have gotten this error from building qemu-arch-extra-git:

FAILED: libqemu-hexagon-linux-user.fa.p/target_hexagon_op_helper.c.o 
cc -m64 -mcx16 -Ilibqemu-hexagon-linux-user.fa.p -I. -I.. -Itarget/hexagon -I../target/hexagon -I../common-user/host/x86_64 -I../linux-user/include/host/x86_64 -I../linux-user/include -Ilinux-user -I../linux-user -I../linux-user/hexagon -Iqapi -Itrace -Iui -Iui/shader -I/usr/include/capstone -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/sysprof-6 -fdiagnostics-color=auto -Wall -Winvalid-pch -std=gnu11 -O2 -g -fstack-protector-strong -Wempty-body -Wendif-labels -Wexpansion-to-defined -Wformat-security -Wformat-y2k -Wignored-qualifiers -Wimplicit-fallthrough=2 -Winit-self -Wmissing-format-attribute -Wmissing-prototypes -Wnested-externs -Wold-style-declaration -Wold-style-definition -Wredundant-decls -Wshadow=local -Wstrict-prototypes -Wtype-limits -Wundef -Wvla -Wwrite-strings -Wno-missing-include-dirs -Wno-psabi -Wno-shift-negative-value -isystem /home/saturn/.cache/paru/clone/qemu-git/src/qemu/linux-headers -isystem linux-headers -iquote . -iquote /home/saturn/.cache/paru/clone/qemu-git/src/qemu -iquote /home/saturn/.cache/paru/clone/qemu-git/src/qemu/include -iquote /home/saturn/.cache/paru/clone/qemu-git/src/qemu/host/include/x86_64 -iquote /home/saturn/.cache/paru/clone/qemu-git/src/qemu/host/include/generic -iquote /home/saturn/.cache/paru/clone/qemu-git/src/qemu/tcg/i386 -Wno-unused-function -pthread -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fno-common -fwrapv -ftrivial-auto-var-init=zero -fzero-call-used-regs=used-gpr -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=3 -Wformat -Werror=format-security -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fPIE -isystem../linux-headers -isystemlinux-headers -DCOMPILING_PER_TARGET '-DCONFIG_TARGET="hexagon-linux-user-config-target.h"' '-DCONFIG_DEVICES="hexagon-linux-user-config-devices.h"' -MD -MQ libqemu-hexagon-linux-user.fa.p/target_hexagon_op_helper.c.o -MF libqemu-hexagon-linux-user.fa.p/target_hexagon_op_helper.c.o.d -o libqemu-hexagon-linux-user.fa.p/target_hexagon_op_helper.c.o -c ../target/hexagon/op_helper.c
during RTL pass: ira
In file included from ../target/hexagon/op_helper.c:1496:
target/hexagon/helper_funcs_generated.c.inc: In function ‘helper_V6_vgathermw’:
target/hexagon/helper_funcs_generated.c.inc:2347:1: internal compiler error: Segmentation fault
 2347 | }
      | ^
0x1905658 internal_error(char const*, ...)
	???:0
0xa9fb38 ira_soft_conflict(ira_allocno*, ira_allocno*)
	???:0
0xa74469 ira_traverse_loop_tree(bool, ira_loop_tree_node*, void (*)(ira_loop_tree_node*), void (*)(ira_loop_tree_node*))
	???:0
0xab06d4 ira_color()
	???:0
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues> for instructions.
[3611/9734] Compiling C object libqemu-hexagon-linux-user.fa.p/target_hexagon_genptr.c.o
ninja: build stopped: subcommand failed.
==> ERROR: A failure occurred in build().
    Aborting...
error: failed to build 'qemu-git-22:9.0.0.r92.g88daa112d4-1 (qemu-git qemu-arch-extra-git)': 
error: packages failed to build: qemu-git-22:9.0.0.r92.g88daa112d4-1 (qemu-git qemu-arch-extra-git)

Does anyone know about this error? Im on Endeavour OS v6.8.7-zen1-2-zen

The package no longer exists. Just continue without it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment