Quantcast
Channel: Computing For Geeks
Viewing all articles
Browse latest Browse all 78

Complete Installation of KVM,QEMU and Virt Manager on Arch Linux and Manjaro

$
0
0
KVM is one of the most used Virtualization softwares in Linux World. In fact most cloud providers used KVM as their Hypervisor of choice. Big projects including Openstack use KVM as default Virtualization tool.
In this tutorial, we'll install KVM on Arch Linux and set Kernel modules required to automatically load at boot. We'll also install a guest machine running CentOS 7.2.
Our previous tutorials on KVM include:

How to Create and Configure Bridge Networking For KVM in LinuX

How To Clone and Use KVM Virtual Machine in Linux


First step is installing all packages needed to run KVM:
 # pacman -S qemu virt-manager dnsmasq iptables vde2 bridge-utils openbsd-netcat
warning: iptables-1.4.21-3 is up to date -- reinstalling
resolving dependencies...
looking for conflicting packages...
Packages (27) augeas-1.4.0-1 ceph-0.94.5-3 fcgi-2.4.0-11 gperftools-2.4-2

leveldb-1.18-2 libuser-0.62-1 libvirt-1.3.2-3
libvirt-glib-0.2.2-1 libvirt-python-1.3.1-1 netcf-0.2.8-3
newt-syrup-0.2.0-1 openbsd-netcat-1.105_7-7
python2-chardet-2.3.0-2 python2-ipaddr-2.1.11-1
python2-ipy-0.83-1 python2-pycurl-7.43.0-1
python2-requests-2.9.1-1 python2-urllib3-1.14-1 rarian-0.8.1-5
seabios-1.9.1-1 spice-0.12.6-2 urlgrabber-3.10.1-2
virt-install-1.3.2-3 dnsmasq-2.75-1 iptables-1.4.21-3
qemu-2.5.0-1 virt-manager-1.3.2-3
Total Download Size: 41.36 MiB
Total Installed Size: 230.61 MiB
Net Upgrade Size: 225.11 MiB
:: Proceed with installation? [Y/n] y
:: Retrieving packages...
seabios-1.9.1-1-any 148.8 KiB 65.5K/s 00:02 [######################] 100%
spice-0.12.6-2-x86_64 326.5 KiB 9.80K/s 00:33 [######################] 100%
qemu-2.5.0-1-x86_64 5.8 MiB 11.7K/s 08:25 [######################] 100%
fcgi-2.4.0-11-x86_64 35.9 KiB 19.1K/s 00:02 [######################] 100%
gperftools-2.4-2-x86_64 551.1 KiB 16.2K/s 00:34 [######################] 100%
leveldb-1.18-2-x86_64 165.7 KiB 12.5K/s 00:13 [######################] 100%
error: failed retrieving file 'ceph-0.94.5-3-x86_64.pkg.tar.xz' from archlinux.polymorf.fr : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds
error: failed retrieving file 'ceph-0.94.5-3-x86_64.pkg.tar.xz' from mirror.pseudoform.org : Resolving timed out after 10518 milliseconds
error: failed retrieving file 'ceph-0.94.5-3-x86_64.pkg.tar.xz' from mirror.js-webcoding.de : Resolving timed out after 10519 milliseconds
ceph-0.94.5-3-x86_64 1132.0 B -250.16K/s --:-- [----------------------] ceph-0.94.5-3-x86_64 1132.0 B -166.77K/s --:-- [----------------------] ceph-0.94.5-3-x86_64 1132.0 B -111.18K/s --:-- [----------------------] ceph-0.94.5-3-x86_64 1132.0 B -74.12K/s --:-- [----------------------] ceph-0.94.5-3-x86_64 1132.0 B -49.41K/s --:-- [----------------------] ceph-0.94.5-3-x86_64 1132.0 B -32.94K/s --:-- [----------------------] ceph-0.94.5-3-x86_64 1132.0 B -21.96K/s --:-- [----------------------] ceph-0.94.5-3-x86_64 1132.0 B -14.64K/s --:-- [----------------------] ceph-0.94.5-3-x86_64 1132.0 B -9.76K/s --:-- [----------------------] 0 ceph-0.94.5-3-x86_64 1132.0 B -6.51K/s --:-- [----------------------] 0 ceph-0.94.5-3-x86_64 1132.0 B -4.34K/s --:-- [----------------------] 0 ceph-0.94.5-3-x86_64 1132.0 B -2.89K/s --:-- [----------------------] 0 ceph-0.94.5-3-x86_64 1132.0 B -1974.00B/s --:-- [----------------------] ceph-0.94.5-3-x86_64 2.5 KiB -825.00B/s --:-- [----------------------] ceph-0.94.5-3-x86_64 2.5 KiB -550.00B/s --:-- [----------------------] ceph-0.94.5-3-x86_64 2.5 KiB -366.00B/s --:-- [----------------------] error: failed retrieving file 'ceph-0.94.5-3-x86_64.pkg.tar.xz' from ftp.nluug.nl : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds
error: failed retrieving file 'ceph-0.94.5-3-x86_64.pkg.tar.xz' from arch.tamcore.eu : Resolving timed out after 10520 milliseconds
ceph-0.94.5-3-x86_64 1028.0 B -22.77K/s --:-- [----------------------] ceph-0.94.5-3-x86_64 8.1 KiB -10.56K/s --:-- [----------------------] ceph-0.94.5-3-x86_64 10.9 KiB -4.44K/s --:-- [----------------------] 0 ceph-0.94.5-3-x86_64 12.3 KiB -2.17K/s --:-- [----------------------] 0error: failed retrieving file 'ceph-0.94.5-3-x86_64.pkg.tar.xz' from mirror.bitjungle.info : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds
error: failed retrieving file 'ceph-0.94.5-3-x86_64.pkg.tar.xz' from mirrors.uni-plovdiv.net : Resolving timed out after 10519 milliseconds
error: failed retrieving file 'ceph-0.94.5-3-x86_64.pkg.tar.xz' from arch.localmsp.org : Resolving timed out after 10520 milliseconds
ceph-0.94.5-3-x86_64 1052.0 B -9.56K/s --:-- [----------------------] 0error: failed retrieving file 'ceph-0.94.5-3-x86_64.pkg.tar.xz' from lug.mtu.edu : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds
ceph-0.94.5-3-x86_64 1148.0 B -29.86K/s --:-- [----------------------] ceph-0.94.5-3-x86_64 9.1 KiB -16.64K/s --:-- [----------------------] error: failed retrieving file 'ceph-0.94.5-3-x86_64.pkg.tar.xz' from mirrors.niyawe.de : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds
error: failed retrieving file 'ceph-0.94.5-3-x86_64.pkg.tar.xz' from muug.ca : Resolving timed out after 10520 milliseconds
error: failed retrieving file 'ceph-0.94.5-3-x86_64.pkg.tar.xz' from mirror.f4st.host : Resolving timed out after 10520 milliseconds
ceph-0.94.5-3-x86_64 420.5 KiB 6.90K/s 01:01 [######################] 100%
python2-urllib3-1.1... 98.7 KiB 6.57K/s 00:15 [######################] 100%
python2-requests-2.... 76.7 KiB 5.29K/s 00:15 [######################] 100%
python2-pycurl-7.43... 82.6 KiB 3.40K/s 00:24 [######################] 100%
rarian-0.8.1-5-x86_64 98.7 KiB 7.00K/s 00:14 [######################] 100%
dnsmasq-2.75-1-x86_64 197.4 KiB 5.83K/s 00:34 [######################] 100%
augeas-1.4.0-1-x86_64 445.5 KiB 3.72K/s 02:00 [######################] 100%
netcf-0.2.8-3-x86_64 52.7 KiB 6.47K/s 00:08 [######################] 100%
libvirt-1.3.2-3-x86_64 6.0 MiB 6.05K/s 16:59 [######################] 100%
libvirt-python-1.3.... 135.7 KiB 4.32K/s 00:31 [######################] 100%
python2-ipaddr-2.1.... 21.5 KiB 5.64K/s 00:04 [######################] 100%
virt-install-1.3.2-... 1053.9 KiB 6.71K/s 02:37 [######################] 100%
urlgrabber-3.10.1-2-any 85.0 KiB 6.08K/s 00:14 [######################] 100%
libuser-0.62-1-x86_64 278.9 KiB 7.55K/s 00:37 [######################] 100%
python2-ipy-0.83-1-any 27.3 KiB 7.79K/s 00:04 [######################] 100%
newt-syrup-0.2.0-1-any 13.3 KiB 3.56K/s 00:04 [######################] 100%
openbsd-netcat-1.10... 19.0 KiB 8.40K/s 00:02 [######################] 100%
libvirt-glib-0.2.2-... 275.7 KiB 5.23K/s 00:53 [######################] 100%
virt-manager-1.3.2-... 3.5 KiB 106K/s 00:00 [######################] 100%
(27/27) checking keys in keyring [######################] 100%
(27/27) checking package integrity [######################] 100%
(27/27) loading package files [######################] 100%
(27/27) checking for file conflicts [######################] 100%
(27/27) checking available disk space [######################] 100%
:: Processing package changes...
( 1/27) installing seabios [######################] 100%
( 2/27) installing spice [######################] 100%
( 3/27) reinstalling iptables [######################] 100%
( 4/27) installing qemu [######################] 100%
Optional dependencies for qemu

samba: SMB/CIFS server support
qemu-arch-extra: extra architectures support
qemu-block-iscsi: iSCSI block support
qemu-block-rbd: RBD block support
qemu-block-gluster: glusterfs block support
( 5/27) installing fcgi [######################] 100%
( 6/27) installing gperftools [######################] 100%
Optional dependencies for gperftools
graphviz: pprof graph generation [installed]
gv: pprof postscript generation
( 7/27) installing leveldb [######################] 100%
( 8/27) installing ceph [######################] 100%
Optional dependencies for ceph
xfsprogs: support xfs backend [installed]
( 9/27) installing augeas [######################] 100%
(10/27) installing netcf [######################] 100%
(11/27) installing libvirt [######################] 100%
>>> libvirt runs qemu from nobody:kvm by default
>>> change the USER if desired in /etc/libvirt/qemu.conf
>>> See https://wiki.archlinux.org/index.php/Libvirt for more info
Optional dependencies for libvirt
ebtables: required for default NAT networking
dnsmasq: required for default NAT/DHCP for guests [pending]
bridge-utils: for bridged networking
openbsd-netcat: for remote management over ssh [pending]
qemu [installed]
radvd
dmidecode
pm-utils: host power management [installed]
(12/27) installing libvirt-python [######################] 100%
(13/27) installing python2-ipaddr [######################] 100%
(14/27) installing python2-urllib3 [######################] 100%
(15/27) installing python2-chardet [######################] 100%
(16/27) installing python2-requests [######################] 100%
Optional dependencies for python2-requests
python2-ndg-httpsclient: HTTPS requests with SNI support
python2-grequests: asynchronous requests with gevent
(17/27) installing virt-install [######################] 100%
(18/27) installing python2-pycurl [######################] 100%
(19/27) installing urlgrabber [######################] 100%
(20/27) installing rarian [######################] 100%
(21/27) installing libuser [######################] 100%
(22/27) installing python2-ipy [######################] 100%
(23/27) installing newt-syrup [######################] 100%
(24/27) installing openbsd-netcat [######################] 100%
(25/27) installing libvirt-glib [######################] 100%
(26/27) installing virt-manager [######################] 100%
(27/27) installing dnsmasq Install iptable Firewall backend
# root at darkpy in ~ [21:32:01]
→ sudo pacman -S ebtables
resolving dependencies...
looking for conflicting packages...
Packages (1) ebtables-2.0.10_4-5
Total Download Size: 0.07 MiB
Total Installed Size: 0.24 MiB
:: Proceed with installation? [Y/n] y
:: Retrieving packages...
ebtables-2.0.10_4-5-x86_64 [####################################################] 100%
(1/1) checking keys in keyring [####################################################] 100%
(1/1) checking package integrity [####################################################] 100%
(1/1) loading package files [####################################################] 100%
(1/1) checking for file conflicts [####################################################] 100%
(1/1) checking available disk space [####################################################] 100%
:: Processing package changes...
(1/1) installing ebtables [####################################################] 100%
Enable and start libvirtd daemon:
# root at darkpy in ~ [21:36:22]
→  systemctl enable libvirtd.service
# root at darkpy in ~ [21:36:22]
→ systemctl start ibvirtd.service
Status show it's running:
# root at darkpy in ~ [21:36:22]
→ systemctl status libvirtd.service
libvirtd.service - Virtualization daemon
Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2016-03-26 21:36:22 EAT; 1s ago

Docs: man:libvirtd(8)
Main PID: 9725 (libvirtd)
Tasks: 19 (limit: 512)
CGroup: /system.slice/libvirtd.service
├─8314 /sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper
├─8315 /sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper
└─9725 /usr/bin/libvirtd
Mar 26 21:36:22 darkpy systemd[1]: Stopping Virtualization daemon...
Mar 26 21:36:22 darkpy systemd[1]: Stopped Virtualization daemon.
Mar 26 21:36:22 darkpy systemd[1]: Started Virtualization daemon.
Mar 26 21:36:22 darkpy dnsmasq[8314]: read /etc/hosts - 2 addresses
Mar 26 21:36:22 darkpy dnsmasq[8314]: read /var/lib/libvirt/dnsmasq/default.addnhosts - 0 addresses
Mar 26 21:36:22 darkpy dnsmasq-dhcp[8314]: read /var/lib/libvirt/dnsmasq/default.hostsfile
Mar 26 21:36:23 darkpy libvirtd[9725]: libvirt version: 1.3.2
Enable Nested virtualization for kvm_intel
# modprobe -r kvm_intel
# modprobe kvm_intel nested=1
To make it permanent,do:
# vi /etc/modprobe.d/kvm-intel..conf
Then add below line and save the file:
# options kvm_intel nested=1
One line command that can be used is:
# echo “options kvm-intel nested=1″ | sudo tee /etc/modprobe.d/kvm-intel.conf
You can also achieve the same by modifying 'GRUB_CMDLINE_LINUX‘ line in /etc/default/grub/
# vi /etc/default/grub/
Add kvm-intel.nested=1 to  GRUB_CMDLINE_LINUX line
GRUB_DEFAULT=0
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="Arch"
GRUB_CMDLINE_LINUX_DEFAULT="quiet"
GRUB_CMDLINE_LINUX="kvm-intel.nested=1"
Then update grub:
# grub2-mkconfig -o /boot/grub2/grub.cfg

Confirm that Nested Virtualization is set to Yes:
# root at darkpy in ~ [21:52:26]
→ systool -m kvm_intel -v | grep nested
nested = "Y"
Also:
# root at darkpy in ~ [21:55:17]
→ cat /sys/module/kvm_intel/parameters/nested
Y
# root at darkpy in ~ [22:06:47]
→ modinfo kvm_intel | grep nested
parm: nested:bool
After successfule installation, you are ready to install a Linux or Windows OS. I did installtion of CentOS 7.2 Server using Virsh command.Virt Manager can aslo be used for this purpose.
# mkdir -p /home/josepy/Libvirt/images
# qemu-img create -f qcow2 /home/josepy/Libvirt/images/centos-server.qcow2 10G
Then launch installation:
# virt-install \
--name CentOS7 \
--ram 1024 \
--disk path=/home/josepy/Libvirt/images/centos-server.qcow2 \
--vcpus 1 \
--os-type linux \
--os-variant rhel7 \
--graphics none \
--console pty,target_type=serial \
--location /home/josepy/Kvm\ images/CentOS-7-x86_64-Minimal-1503-01.iso \
--extra-args 'console=ttyS0,115200n8 serial'
Complete installation by following editing configuration settings.
Since i want to set nested Virtualization on this Virtual Machine, i will edit it as follows:
  1. Make vim default editor for virsh
# vim /etc/profile
Add following lines to the end of the file:
EDITOR=/usr/bin/vim
export EDITOR
  1. Save and exit. Then source it:
# source /etc/profile
  1. Edit centos-server xml file
# virsh edit centos-server
Look for cpu mode section, my origina look like this
<cpu mode='custom' match='exact'>
<model fallback='allow'>Westmere</model>
</cpu>
Then change mode from "custom" to "host-passthrough". This will Export host CPU model to guest CPU.
  1. Final:
<cpu mode='host-passthrough' match='exact'>
<model fallback='allow'>Westmere</model>
</cpu>
  1. Save and quit
:wq
Launch Virtual Machine added:
 → virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     centos-server                  shut off
 -     kamailio-cloud                 shut off
Start centos-server
# virsh start centos-server --console

That's all.

   

Viewing all articles
Browse latest Browse all 78

Trending Articles