ArchLinux:KVM: Difference between revisions

From Wiki³
Line 5: Line 5:
This is a tutorial on how to setup KVMs on Arch Linux using Ansible and vagrant-libvirt with QEMU as a back-end.
This is a tutorial on how to setup KVMs on Arch Linux using Ansible and vagrant-libvirt with QEMU as a back-end.
{{Note|This tutorial is meant as a supplement to my [[ArchLinux:OVH|OVH: Custom Installation]] tutorial}}
{{Note|This tutorial is meant as a supplement to my [[ArchLinux:OVH|OVH: Custom Installation]] tutorial}}
== {{Icon|notebook}} Installation ==
= {{Icon24|sitemap}} Installation =
Before getting started there are a few packages that will be needed to set all of this up.
Before getting started there are a few packages that will be needed to set all of this up.
{{Console|1=pacaur -S qemu-headless qemu-headless-arch-extra vagrant}}
{{Console|1=pacaur -S qemu-headless qemu-headless-arch-extra vagrant}}
== {{Icon|notebook}} Hugepages ==
Enabling hugepages can improve the performance of virtual machines. First add an entry to the fstab, make sure to first check what the group id of the group {{mono|kvm}} is.
{{Console|1=grep kvm /etc/group|2=sudoedit /etc/fstab}}<br/>
{{Console|title=/etc/fstab|prompt=false|1=hugetlbfs /dev/hugepages hugetlbfs mode=1770,gid=999 0 0}}
Instead of rebooting, remount instead.
{{Console|1=sudo umount /dev/hugepages|2=mount /dev/hugepages}}
This can then be verified.
{{Console|1=sudo mount {{!}} grep huge|2=ls -FalG /dev/ {{!}} grep huge}}
Now to set the number of hugepages to use. For this one has to do a bit of math, for each gigabyte of the system RAM that you want to use for VMs you divide the size in megabytes by two.
{{Note|On my setup I will dedicated 12GB out of the 16GB of system RAM to VMs. This means {{mono|(12 * 1024) / 2}} or {{mono|6144}}}}
Set the number of hugepages.
{{Console|1=echo 6144 {{!}} sudo tee /proc/sys/vm/nr_hugepages}}
Also set this permanently by adding a file to {{mono|/etc/sysctl.d}}.
{{Console|title=/etc/sysctl.d/40-hugepages.conf|prompt=false|1=vm.nr_hugepages = 6144}}


= {{Icon24|book-brown}} References =
= {{Icon24|book-brown}} References =

Revision as of 16:00, 6 August 2017

Icon Introduction

This is a tutorial on how to setup KVMs on Arch Linux using Ansible and vagrant-libvirt with QEMU as a back-end.

IconThis tutorial is meant as a supplement to my OVH: Custom Installation tutorial

Icon Installation

Before getting started there are a few packages that will be needed to set all of this up.

# pacaur -S qemu-headless qemu-headless-arch-extra vagrant

Icon Hugepages

Enabling hugepages can improve the performance of virtual machines. First add an entry to the fstab, make sure to first check what the group id of the group kvm is.

# grep kvm /etc/group
# sudoedit /etc/fstab


filename: /etc/fstab
hugetlbfs /dev/hugepages hugetlbfs mode=1770,gid=999 0 0

Instead of rebooting, remount instead.

# sudo umount /dev/hugepages
# mount /dev/hugepages

This can then be verified.

# sudo mount | grep huge
# ls -FalG /dev/ | grep huge

Now to set the number of hugepages to use. For this one has to do a bit of math, for each gigabyte of the system RAM that you want to use for VMs you divide the size in megabytes by two.

IconOn my setup I will dedicated 12GB out of the 16GB of system RAM to VMs. This means (12 * 1024) / 2 or 6144

Set the number of hugepages.

# echo 6144 | sudo tee /proc/sys/vm/nr_hugepages

Also set this permanently by adding a file to /etc/sysctl.d.

filename: /etc/sysctl.d/40-hugepages.conf
vm.nr_hugepages = 6144

Icon References