In this article we are going to detail how to install KVM on Gentoo, for the most part it is a normal KVM install but with some Gentoo differences.
Going to be installed:
QEMU/KVM – Our Base
libvirt – For Management
virt-manager – For Extra Tools
virt-manager – On our client machine for managing the system remotely
Lets get started..
First we need to make some tweaks in the kernel to enable KVM otherwise we are just going to end up with QEMU on its own which is slow. The tweaks below are for Intel but same applies for AMD just make sure that you pick the AMD options instead.
To configure the kernel run
genkernel --menuconfig all
In the heading Virtualization enable the following options:
Kernel-based Virtual Machine (KVM) support KVM for Intel processors support Host kernel accelerator for virtio net
Under the heading Device Drivers and sub-heading Network Device Support ensure that the following are enabled:
[*] Network core driver support Universal TUN/TAP device driver support
Because we are going to be using a bridged network we need to enable the following under the Heading Networking Support and the Sub-Heading Networking Options
802.1d Ethernet Bridging
Now for our file system under the heading File Systems enable the following:
The Extended 4 (ext4) filesystem [*] Ext4 Security Labels
Save the kernel update any programs like Grub if need be then reboot
reboot
Assuming your system boots then lets continue..
We do not need to add any special use flags for QEMU so you can just emerge it
emerge --ask -jv app-emulation/qemu
Now we need to install the bridging utils so that we can create our network bridge
emerge --ask -jv bridge-utils
Now to set up our bridge in conf.d/net
vi /etc/conf.d/net
Below is an example replace with values for your host
dns_domain_lo="agix.lan" config_eth0="10.0.0.1/24" # #Additions for KVM # config_eth1="null" bridge_br0="eth1" config_br0="10.0.0.2/24" brctl_br0="setfd 0 stp off"
Now we need to make the init file for our new network
ln -s /etc/init.d/net.lo /etc/init.d/net.br0 ; /etc/init.d/net.br0 start
Add it to the default run level
rc-update add net.br0 default
In the version of QEMU that our test system pulled in there appears to be a bug with some permissions that stop kvm from working, run the following to resolve the issue.
chown root:kvm /dev/kvm ; chmod 660 /dev/kvm
That should resolve the issue now lets install some management tools (The versions listed here were current at the time of testing)
echo ">=dev-libs/libxml2-2.9.2-r1 python" >> /etc/portage/package.use ; echo ">=app-emulation/libvirt-glib-0.2.0 python" >> /etc/portage/package.use
emerge --ask -jv app-emulation/libvirt app-emulation/virt-manager
Now we should be ready to start building some virtual machines, below is a “one liner” that will get you started building a VM also don’t forget to change the /kvm directory to one that actually exists
virt-install --name=Centos66 --arch=x86_64 --vcpus=2 --ram=1024 --os-type=linux --os-variant=rhel6 --hvm --connect=qemu:///system --network bridge:br0 --cdrom=/home/agix/Downloads/CentOS-6.6-x86_64-minimal.iso --disk path=/kvm/centos66.img,size=20 --accelerate --vnc --noautoconsole --keymap=es
From here everything on the host is finished and in our case we installed virt-manager on a laptop so we can manage our host remotely, one thing to check if you are getting strange keyboard layouts in your virtual machine but cannot figure out why it is because virt-manager sets its own have a look at the below article to show you how to change it
Pyrosoft Fixing Keyboard Problems Virt-Manager