We already have covered [**setting up Oracle VirtualBox on Ubuntu 18.04**][1] headless server. In this tutorial, we will be discussing how to setup headless virtualization server using **KVM** and how to manage the guest machines from a remote client. As you may know already, KVM ( **K** ernel-based **v** irtual **m** achine) is an open source, full virtualization for Linux. Using KVM, we can easily turn any Linux server in to a complete virtualization environment in minutes and deploy different kind of VMs such as GNU/Linux, *BSD, Windows etc.
### Setup Headless Virtualization Server Using KVM
I tested this guide on Ubuntu 18.04 LTS server, however this tutorial will work on other Linux distributions such as Debian, CentOS, RHEL and Scientific Linux. This method will be perfectly suitable for those who wants to setup a simple virtualization environment in a Linux server that doesn’t have any graphical environment.
For the purpose of this guide, I will be using two systems.
**KVM virtualization server:**
* **Host OS** – Ubuntu 18.04 LTS minimal server (No GUI)
* **IP Address of Host OS** : 192.168.225.22/24
* **Guest OS** (Which we are going to host on Ubuntu 18.04) : Ubuntu 16.04 LTS server
**Remote desktop client :**
* **OS** – Arch Linux
### Install KVM
First, let us check if our system supports hardware virtualization. To do so, run the following command from the Terminal:
```
$ egrep -c '(vmx|svm)' /proc/cpuinfo
```
If the result is **zero (0)** , the system doesn’t support hardware virtualization or the virtualization is disabled in the Bios. Go to your bios and check for the virtualization option and enable it.
if the result is **1** or **more** , the system will support hardware virtualization. However, you still need to enable the virtualization option in Bios before running the above commands.
Alternatively, you can use the following command to verify it. You need to install kvm first as described below, in order to use this command.
```
$ kvm-ok
```
**Sample output:**
```
INFO: /dev/kvm exists
KVM acceleration can be used
```
If you got the following error instead, you still can run guest machines in KVM, but the performance will be very poor.
```
INFO: Your CPU does not support KVM extensions
INFO: For more detailed results, you should run this as root
HINT: sudo /usr/sbin/kvm-ok
```
Also, there are other ways to find out if your CPU supports Virtualization or not. Refer the following guide for more details.
Next, Install KVM and other required packages to setup a virtualization environment in Linux.
Once KVM installed, start libvertd service (If it is not started already):
```
$ sudo systemctl enable libvirtd
$ sudo systemctl start libvirtd
```
### Create Virtual machines
All virtual machine files and other related files will be stored under **/var/lib/libvirt/**. The default path of ISO images is **/var/lib/libvirt/boot/**.
First, let us see if there is any virtual machines. To view the list of available virtual machines, run:
Note down the port number **5900**. Install any VNC client application. For this guide, I will be using TigerVnc. TigerVNC is available in the Arch Linux default repositories. To install it on Arch based systems, run:
```
$ sudo pacman -S tigervnc
```
Type the following SSH port forwarding command from your remote client system that has VNC client application installed.
Again, **192.168.225.22** is my Ubuntu server’s (virtualization server) IP address.
Then, open the VNC client from your Arch Linux (client).
Type **localhost:5900** in the VNC server field and click **Connect** button.
![][6]
Then start installing the Ubuntu VM as the way you do in the physical system.
![][7]
![][8]
Similarly, you can setup as many as virtual machines depending upon server hardware specifications.
Alternatively, you can use **virt-viewer** utility in order to install operating system in the guest machines. virt-viewer is available in the most Linux distribution’s default repositories. After installing virt-viewer, run the following command to establish VNC access to the VM.
Managing VMs from the command-line using virsh management user interface is very interesting and fun. The commands are very easy to remember. Let us see some examples.
As you see in the above output, Ubuntu 16.04 virtual machine’s Id is 2. So, in order to start it, just specify its Id like below.
```
$ sudo virsh start 2
```
To restart a VM, run:
```
$ sudo virsh reboot Ubuntu-16.04
```
**Sample output:**
```
Domain Ubuntu-16.04 is being rebooted
```
![][11]
To pause a running VM, run:
```
$ sudo virsh suspend Ubuntu-16.04
```
**Sample output:**
```
Domain Ubuntu-16.04 suspended
```
To resume the suspended VM, run:
```
$ sudo virsh resume Ubuntu-16.04
```
**Sample output:**
```
Domain Ubuntu-16.04 resumed
```
To shutdown a VM, run:
```
$ sudo virsh shutdown Ubuntu-16.04
```
**Sample output:**
```
Domain Ubuntu-16.04 is being shutdown
```
To completely remove a VM, run:
```
$ sudo virsh undefine Ubuntu-16.04
$ sudo virsh destroy Ubuntu-16.04
```
**Sample output:**
```
Domain Ubuntu-16.04 destroyed
```
![][12]
For more options, I recommend you to look into the man pages.
```
$ man virsh
```
That’s all for now folks. Start playing with your new virtualization environment. KVM virtualization will be opt for research & development and testing purposes, but not limited to. If you have sufficient hardware, you can use it for large production environments. Have fun and don’t forget to leave your valuable comments in the comment section below.