====== Virtualization with KVM-QEMU ======
QEMU is a virtualization solution that is fully open-source and probably the most efficient free option on a Linux kernel. It can use the kernel KVM technology to access the highest possible virtualization level.
===== Reference links =====
The [[https://wiki.gentoo.org/wiki/QEMU|Gentoo Wiki]] page on QEMU has lots of good information, as well as [[https://www.linux-kvm.org/page/KvmOnGentoo|this]] page.
===== Kernel and required packages =====
I am asusming you use **genkernel** with //gentoo-sources// or **gentoo-kernel-bin** with the //dist// flags to have a standard kernel, that ships with all the required options enables. If this is not the case, follow the instructions on the Gentoo Wiki page linked above and compile a compliant kernel.
You also need to have all the virtualization options enabled on your BIOS/UEFI firmware.
Now, as for packages, you will want the VirtManager GUI and the QEMU package, so install the following:
emerge net-misc/bridge-utils app-emulation/libvirt app-emulation/virt-manager qemu -vp
And make sure your libvirtd has proper access configuration for the sockets:
**/etc/libvirt/libvirtd.conf**:
unix_sock_group = "libvirt"
unix_sock_rw_perms = "0770"
===== Networking configuration =====
If you want to use **bridged** networking, which means assign local LAN IP to your virtual machines, you need to convert your LAN interfaces to bridged.
This means, given the following example (in /etc/conf.d/net):
config_eno1="10.0.0.50/24"
route_eno1="default via 10.0.0.1"
To this:
bridge_br0="eno1"
config_br0="10.0.0.50/24"
route_br0="default via 10.0.0.1"
config_eno1="null"
And add the required init links:
cd /etc/init.d
ln -s net.lo net.br0
rc-update add net.br0 default
rc-update del net.eno1 default
./net.eno1 stop
./net.br0 start
===== Users configuration =====
add your users to groups **kvm**, **qemu** and **libvirt**.
gpasswd -a user libvirt
gpasswd -a user kvm
gpasswd -a user qemu
rc-update add libvirt-guests
rc-update add libvirtd
/etc/init.d/libvirtd start
/etc/init.d/libvirt-guests start