Cyberithub

How to Install KVM Server tools(virsh) on Linux (RHEL/CentOS 7/8) in 6 Easy Steps

In this article, I will take you through the steps to install kvm server tools(virsh) on Linux (RedHat/CentOS 7/8) in 6 Easy Steps. Many of you might be familiar with Virtualization concepts where one can create mutliple virtual machines on a host machine by converting host machine into Hypervisor. You can use certain KVM tools to manage your virtual machines in a Hypervisor. virsh is one such tool. There are many other tools along with virsh which will be used in Virtualization. We will see the steps below to install those tools.

Below are the List of tools which will be installed as part of KVM Server tools packages installation.

  • virsh
  • virt-alignment-scan
  • virt-copy-out
  • virt-format
  • virtlockd
  • virt-rescue
  • virt-tar-out
  • virt-builder
  • virt-customize
  • virt-get-kernel
  • virt-log virt-resize
  • virt-what
  • virt-builder-repository
  • virt-df virt-host-validate
  • virtlogd virt-sparsify
  • virt-win-reg
  • virt-cat
  • virt-diff
  • virt-index-validate
  • virt-ls
  • virt-sysprep
  • virt-xml
  • virt-clone
  • virt-edit
  • virt-inspector
  • virt-make-fs
  • virt-tail
  • virt-xml-validate
  • virt-copy-in
  • virt-filesystems
  • virt-install
  • virt-pki-validate
  • virt-tar-in

How to Install KVM Server tools(virsh) on Linux (RHEL/CentOS 7/8) in 6 Easy Steps 1

Install KVM Server tools(virsh) on Linux

Also Read: 18 Useful virsh commands example for KVM Hypervisor Management(virt-df,virt-log)

Step 1: Prerequisites

a)You need a running RHEL/CentOS 7/8 machine.

b)You need to have sudo access to run privilege commands in Linux. To know more about providing sudo access you can check Step by Step: How to Add User to Sudoers.

c)You should also have yum installed in your system.

Step 2: Update Your System

Before installing KVM Server tools it is necessary to update your System packages to the latest version. You can always run yum update -y command to update your system. As you can see from below output our system is already updated with latest version hence it is not detecting any new updates further.

[root@localhost ~]# yum update -y
Loaded plugins: fastestmirror
Determining fastest mirrors
epel/x86_64/metalink | 6.1 kB 00:00:00
* base: mirrors.piconets.webwerks.in
* epel: ftp.riken.jp
* extras: mirrors.piconets.webwerks.in
* updates: mirrors.piconets.webwerks.in
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/3): epel/x86_64/group_gz | 95 kB 00:00:00
(2/3): epel/x86_64/updateinfo | 1.0 MB 00:00:02
(3/3): epel/x86_64/primary_db | 6.8 MB 00:00:04
No packages marked for update

Step 3: Install KVM Server tools(virsh)

You need to use yum command to install all the KVM Server tools to turn your Linux OS into Hypervisor. This can be done by using below yum install command where it will install packages like qemu-kvm, libvirtd, libvirt-python, libguestfs-tools and virt-install.

[root@localhost ~]# yum install qemu-kvm libvirt libvirt-python libguestfs-tools virt-install -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.piconets.webwerks.in
* epel: ftp.riken.jp
* extras: mirrors.piconets.webwerks.in
* updates: mirrors.piconets.webwerks.in
Resolving Dependencies
--> Running transaction check
---> Package libguestfs-tools.noarch 1:1.40.2-9.el7 will be installed
--> Processing Dependency: libguestfs-tools-c = 1:1.40.2-9.el7 for package: 1:libguestfs-tools-1.40.2-9.el7.noarch
--> Processing Dependency: libguestfs = 1:1.40.2-9.el7 for package: 1:libguestfs-tools-1.40.2-9.el7.noarch
--> Processing Dependency: perl(Win::Hivex) >= 1.2.7 for package: 1:libguestfs-tools-1.40.2-9.el7.noarch
--> Processing Dependency: perl(warnings) for package: 1:libguestfs-tools-1.40.2-9.el7.noarch
--> Processing Dependency: perl(strict) for package: 1:libguestfs-tools-1.40.2-9.el7.noarch
--> Processing Dependency: perl(Win::Hivex::Regedit) for package: 1:libguestfs-tools-1.40.2-9.el7.noarch
--> Processing Dependency: perl(Win::Hivex) for package: 1:libguestfs-tools-1.40.2-9.el7.noarch
--> Processing Dependency: perl(Sys::Virt) for package: 1:libguestfs-tools-1.40.2-9.el7.noarch
--> Processing Dependency: perl(Sys::Guestfs) for package: 1:libguestfs-tools-1.40.2-9.el7.noarch
--> Processing Dependency: perl(Pod::Usage) for package: 1:libguestfs-tools-1.40.2-9.el7.noarch
--> Processing Dependency: perl(Locale::TextDomain) for package: 1:libguestfs-tools-1.40.2-9.el7.noarch
--> Processing Dependency: perl(Getopt::Long) for package: 1:libguestfs-tools-1.40.2-9.el7.noarch
--> Processing Dependency: perl(File::Temp) for package: 1:libguestfs-tools-1.40.2-9.el7.noarch
--> Processing Dependency: perl(File::Basename) for package: 1:libguestfs-tools-1.40.2-9.el7.noarch
---> Package libvirt.x86_64 0:4.5.0-33.el7_8.1 will be installed

Step 4: Check virsh command version

After successful installtion of KVM Server tools you can check the virsh tool version using virsh -v command as shown below.

[root@localhost ~]# virsh -v
4.5.0

You can check virt-copy-in version using virt-copy-in --version command as shown below.

[root@localhost ~]# virt-copy-in --version
virt-copy-in 1.40.2rhel=7,release=9.el7,libvirt

You can check virt-copy-out version using virt-copy-out --version command as shown below.

[root@localhost ~]# virt-copy-out --version
virt-copy-out 1.40.2rhel=7,release=9.el7,libvirt

You can check virt-customize version using virt-customize --version command as shown below.

[root@localhost ~]# virt-customize --version
virt-customize 1.40.2rhel=7,release=9.el7,libvirt

You can check virt-df version using virt-df --version command as shown below.

[root@localhost ~]# virt-df --version
virt-df 1.40.2rhel=7,release=9.el7,libvirt

You can check virt-diff version using virt-diff --version command as shown below.

[root@localhost ~]# virt-diff --version
virt-diff 1.40.2rhel=7,release=9.el7,libvirt

You can check virt-edit version using virt-edit --version command as shown below.

[root@localhost ~]# virt-edit --version
virt-edit 1.40.2rhel=7,release=9.el7,libvirt

You can check virt-filesystems version using virt-filesystems --version command as shown below.

[root@localhost ~]# virt-filesystems --version
virt-filesystems 1.40.2rhel=7,release=9.el7,libvirt

Step 5: Start libvirtd Service

If you check the libvirtd service status immediately after virsh tool installation then you will see the service is in inactive state. Virtualization daemon will not start itself after package installation like most services does.

[root@localhost ~]# systemctl status libvirtd
● libvirtd.service - Virtualization daemon
Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:libvirtd(8)
https://libvirt.org

So you need to go ahead and start the libvirtd service using systemctl start libvirtd command.

[root@localhost ~]# systemctl start libvirtd

Now you can check the status and get confirmed by running systemctl status libvirtd command as shown below.

[root@localhost ~]# systemctl status libvirtdlibvirtd.service - Virtualization daemon
Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2020-05-31 02:30:12 EDT; 2s ago
Docs: man:libvirtd(8)
https://libvirt.org
Main PID: 3393 (libvirtd)
Tasks: 19 (limit: 32768)
CGroup: /system.slice/libvirtd.service
├─3393 /usr/sbin/libvirtd
├─3468 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
└─3469 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper

May 31 02:30:14 localhost.localdomain dnsmasq[3461]: listening on virbr0(#3): 192.168.122.1
May 31 02:30:14 localhost.localdomain dnsmasq[3468]: started, version 2.76 cachesize 150
May 31 02:30:14 localhost.localdomain dnsmasq[3468]: compile time options: IPv6 GNU-getopt DBus no-i18n IDN DHCP DHCPv6 no-Lua TFTP no-conntrack ipset auth ...t inotify
May 31 02:30:14 localhost.localdomain dnsmasq-dhcp[3468]: DHCP, IP range 192.168.122.2 -- 192.168.122.254, lease time 1h
May 31 02:30:14 localhost.localdomain dnsmasq-dhcp[3468]: DHCP, sockets bound exclusively to interface virbr0
May 31 02:30:14 localhost.localdomain dnsmasq[3468]: reading /etc/resolv.conf
May 31 02:30:14 localhost.localdomain dnsmasq[3468]: using nameserver 192.168.0.1#53
May 31 02:30:14 localhost.localdomain dnsmasq[3468]: read /etc/hosts - 2 addresses
May 31 02:30:14 localhost.localdomain dnsmasq[3468]: read /var/lib/libvirt/dnsmasq/default.addnhosts - 0 addresses
May 31 02:30:14 localhost.localdomain dnsmasq-dhcp[3468]: read /var/lib/libvirt/dnsmasq/default.hostsfile
Hint: Some lines were ellipsized, use -l to show in full.

NOTE:

Please note that if you try to connect vm without starting libvirtd service then you might get "Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory" error. Hence libvirtd service needs to be started first.

Step 6: List all Virtual Machines 

Here I have not created any virtual machine so you won’t see anything in the output if you run virsh list command. This will get covered in the next article where I will show you how to create virtual machine and perform other VM operations using virsh commands.

[root@localhost ~]# virsh list
Id Name State
----------------------------------------------------

 

 

 

Popular Recommendations:-

15 virt-install examples | KVM Virtualization commands cheatsheet

How to Enable or Disable SELinux Temporarily or Permanently on RedHat/CentOS 7/8

10 Popular Examples of sudo command in Linux(RedHat/CentOS 7/8)

How to Install and Use telnet command in Linux (RedHat/Linux 7/8) using 5 Easy Steps

12 Most Popular rm command in Linux with Examples

Create a Self Signed Certificate using OpenSSL

How to Check timezone in Linux (timedatectl and date commands) Using 4 Easy Methods

Leave a Comment