ArchLinux:KVM: Difference between revisions
m (→Vagrant) |
mNo edit summary |
||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:{{TitleIcon|arch=true}} KVM on Arch Linux}}<metadesc>How to | {{DISPLAYTITLE:{{TitleIcon|arch=true}} Automate KVM on Arch Linux}}<metadesc>How to automate VMs using QEMU KVM with libvirt, Packer and Vagrant on Arch Linux.</metadesc> | ||
<div id="tocalign">__TOC__</div> | <div id="tocalign">__TOC__</div> | ||
{{Back|Arch Linux}} | {{Back|Arch Linux}} | ||
= {{Icon24|sitemap}} Introduction = | = {{Icon24|sitemap}} Introduction = | ||
This is a tutorial on how to setup | This is a tutorial on how to automate the setup of VMs using KVM on Arch Linux. This tutorial uses [//www.qemu.org QEMU] as a back-end for KVM and [//libvirt.org libvirt], [//www.packer.io Packer] and [[//www.vagrantup.com Vagrant]. | ||
{{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}} | ||
= {{Icon24|sitemap}} 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 libvirt openssl-1.0}} | {{Console|1=pacaur -S qemu-headless qemu-headless-arch-extra vagrant libvirt openssl-1.0 packer-io}} | ||
== {{Icon|notebook}} Hugepages == | == {{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. | 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. |
Revision as of 00:54, 7 August 2017
Introduction
This is a tutorial on how to automate the setup of VMs using KVM on Arch Linux. This tutorial uses QEMU as a back-end for KVM and libvirt, Packer and [Vagrant.
This tutorial is meant as a supplement to my OVH: Custom Installation tutorial |
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 libvirt openssl-1.0 packer-io |
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 |
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.
On 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.
vm.nr_hugepages = 6144 |
Again verify the changes.
# grep HugePages_Total /proc/meminfo |
Vagrant
The libvirt plugin installation for vagrant is extremely finicky on Arch. Some cleanup is needed first.
# sudo mv /opt/vagrant/embedded/lib/libcurl.so{,.backup} # sudo mv /opt/vagrant/embedded/lib/libcurl.so.4{,.backup} # sudo mv /opt/vagrant/embedded/lib/libcurl.so.4.4.0{,.backup} # sudo mv /opt/vagrant/embedded/lib/pkgconfig/libcurl.pc{,backup} |
Then build the plugin.
# vagrant plugin install vagrant-libvirt |
Finally create a user for KVM.
# sudo useradd -g kvm -s /usr/bin/nologin kvm |
Then modify the libvirt QEMU config to reflect this.
user = "kvm" group = "kvm" |