Linux kvm ubuntu server

KVM hypervisor: a beginners’ guide

KVM (Kernel-based Virtual Machine) is the leading open source virtualisation technology for Linux. It installs natively on all Linux distributions and turns underlying physical servers into hypervisors so that they can host multiple, isolated virtual machines (VMs). KVM comes with no licenses, type-1 hypervisor capabilities and a variety of performance extensions which makes it an ideal candidate for virtualisation and cloud infrastructure implementation. But what are the benefits of KVM hypervisor and how do you get started?

In the following blog, we present the beginner’s guide to KVM on Ubuntu.

What is KVM hypervisor?

KVM hypervisor enables full virtualisation capabilities. It provides each VM with all typical services of the physical system, including virtual BIOS (basic input/output system) and virtual hardware, such as processor, memory, storage, network cards, etc. As a result, every VM completely simulates a physical machine.

KVM is available as a Linux kernel module. It plugs directly into the kernel’s code and allows it to function as a hypervisor. Every VM runs as a separate Linux process under systemd, with dedicated virtual hardware resources attached. KVM can only be used on a processor with hardware virtualisation extensions, such as Intel-VT or AMD-V.

KVM hypervisor benefits

The main benefit of the KVM hypervisor is its native availability on Linux. Since KVM is part of Linux, it installs natively, enabling straightforward user experience and smooth integration. But KVM brings more benefits compared to other virtualisation technologies. Those include:

  • Performance – One of the main drawbacks of traditional virtualisation technologies is performance degradation compared to physical machines. Since KVM is the type-1 hypervisor, it outperforms all type-2 hypervisors, ensuring near-metal performance. With KVM hypervisor VMs boot fast and achieve desired performance results.
  • Scalability – As a Linux kernel module, the KVM hypervisor automatically scales to respond to heavy loads once the number of VMs increases. The KVM hypervisor also enables clustering for thousands of nodes, laying the foundations for cloud infrastructure implementation.
  • Security – Since KVM is part of the Linux kernel source code, it benefits from the world’s biggest open source community collaboration, rigorous development and testing process as well as continuous security patching.
  • Maturity – KVM was first created in 2006 and has continued to be actively developed since then. It is a 15-year old project, presenting a high level of maturity. More than 1,000 developers around the world have contributed to KVM code.
  • Cost-efficiency – Last but not least, the cost is a driving factor for many organisations. Since KVM is open source and available as a Linux kernel module, it comes at zero cost out of the box. Businesses can optionally subscribe to various commercial programmes, such as UA-I (Ubuntu Advantage for Infrastructure) to receive enterprise support for their KVM-based virtualisation or cloud infrastructure.
Читайте также:  Linux remove all nvidia drivers

How to install KVM on Ubuntu 20.04

In the following section, we present how to install KVM on Ubuntu 20.04 LTS in three simple steps.

Step 1: Install required packages

On your Ubuntu 20.04 execute the following command to install the required packages:

$ sudo apt -y install bridge-utils cpu-checker libvirt-clients libvirt-daemon qemu qemu-kvm

Step 2: Check virtualisation capabilities

Execute the following command to make sure your processor supports virtualisation capabilities:

The output of this command is pretty straightforward and clearly indicates whether KVM can be used or not:

INFO: /dev/kvm exists KVM acceleration can be used

Step 3: Launch a VM

In order to launch your first Ubuntu Server 20.04 LTS instance on KVM execute the following command:

$ sudo virt-install --name ubuntu-guest --os-variant ubuntu20.04 --vcpus 2 --ram 2048 --location http://ftp.ubuntu.com/ubuntu/dists/focal/main/installer-amd64/ --network bridge=virbr0,model=virtio --graphics none --extra-args='console=ttyS0,115200n8 serial'

This opens an interactive console that you can use to manually install the Ubuntu guest.

Virtualisation management software

In order to facilitate the management of VMs and provide a graphical user interface various types of management software are available for KVM. In the following section, we briefly present the most popular ones.

Virtual Machine Manager

Virtual Machine Manager is a desktop user interface for managing KVM VMs. It presents a summary view of running guest instances, their live performance and resource utilisation statistics. Virtual Machine Manager comes with wizards that enable the creation of new VMs and the configuration of their resource allocation and virtual hardware.

Multipass

Multipass is the recommended method to create Ubuntu VMs on workstations. It is designed for developers who want to quickly set up a fresh Ubuntu environment with just a single command. Multipass installs on Linux, Windows and macOS, and supports leading hypervisors, including KVM.

OpenStack

OpenStack is the most popular open source cloud computing platform that enables the management of distributed compute, network and storage resources in the data centre. It wraps around the KVM hypervisor providing virtualisation capabilities and enables fully automated provisioning of VMs through a self-service portal.

Next steps

Now, once you’ve learned what KVM hypervisor is and how to use it on Ubuntu, you may be wondering what next steps you should take. Here are some useful links that might help you on this journey.

Refer to Ubuntu Server documentation for more advanced scenarios and additional information about the different types of management software.

Learn more about OpenStack – the world’s leading open-source software for virtualisation management and cloud infrastructure implementation.

Ubuntu cloud

Ubuntu offers all the training, software infrastructure, tools, services and support you need for your public and private clouds.

Источник

Installation

To run KVM, you need a processor that supports hardware virtualization. Intel and AMD both have developed extensions for their processors, deemed respectively Intel VT-x (code name Vanderpool) and AMD-V (code name Pacifica). To see if your processor supports one of these, you can review the output from this command:

egrep -c '(vmx|svm)' /proc/cpuinfo

If 0 it means that your CPU doesn’t support hardware virtualization.

Читайте также:  What is linux based hosting

If 1 or more it does — but you still need to make sure that virtualization is enabled in the BIOS.

By default, if you booted into XEN kernel it will not display svm or vmx flag using the grep command. To see if it is enabled or not from xen, enter:

cat /sys/hypervisor/properties/capabilities

You must see hvm flags in the output.

Alternatively, you may execute:

which may provide an output like this:

INFO: /dev/kvm exists KVM acceleration can be used
INFO: Your CPU does not support KVM extensions KVM acceleration can NOT be used

You can still run virtual machines, but it’ll be much slower without the KVM extensions.

NOTE: You may see a message like «KVM acceleration can/can NOT be used». This is misleading and only means if KVM is *currently* available (i.e. «turned on»), *not* if it is supported.

Use a 64 bit kernel (if possible)

  1. To serve more than 2GB of RAM for your VMs, you must use a 64-bit kernel (see 32bit_and_64bit). On a 32-bit kernel install, you’ll be limited to 2GB RAM at maximum for a given VM.
  2. Also, a 64-bit system can host both 32-bit and 64-bit guests. A 32-bit system can only host 32-bit guests.

To see if your processor is 64-bit, you can run this command:

If 0 is printed, it means that your CPU is not 64-bit.

If 1 or higher, it is. Note: lm stands for Long Mode which equates to a 64-bit CPU.

Now see if your running kernel is 64-bit, just issue the following command:

x86_64 indicates a running 64-bit kernel. If you use see i386, i486, i586 or i686, you’re running a 32-bit kernel.

Note: x86_64 is synonymous with amd64.

Installation of KVM

Install Necessary Packages

For the following setup, we will assume that you are deploying KVM on a server, and therefore do not have any X server on the machine.

You need to install a few packages first:

Cosmic (18.10) or later

$ sudo apt-get install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils

Lucid (10.04) or later

$ sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils

Karmic (9.10) or earlier

$ sudo aptitude install kvm libvirt-bin ubuntu-vm-builder bridge-utils
  • libvirt-bin provides libvirtd which you need to administer qemu and kvm instances using libvirt
  • qemu-kvm (kvm in Karmic and earlier) is the backend
  • ubuntu-vm-builder powerful command line tool for building virtual machines
  • bridge-utils provides a bridge from your network to the virtual machines

You might also want to install virt-viewer, for viewing instances.

Add Users to Groups

Karmic (9.10) and later (but not 14.04 LTS and 18.10)

You need to ensure that your username is added to the group libvirtd:

$ sudo adduser `id -un` libvirtd Adding user '' to group 'libvirtd' .

After this, you need to relogin so that your user becomes an effective member of the libvirtd group. The members of this group can run virtual machines. (You can also ‘newgrp kvm’ in a terminal, but this will affect only that terminal.)

Bionic (18.04 LTS) and higher

The group name is changed to libvirt, and you also need to be a member of ‘kvm’:

$ sudo adduser `id -un` libvirt Adding user '' to group 'libvirt' . $ sudo adduser `id -un` kvm Adding user '' to group 'kvm' .

Releases prior to Karmic (9.10)

Читайте также:  Linux командная строка поиск файлов

You need to ensure that your username is added to the groups: kvm and libvirtd.

$ groups adm dialout cdrom floppy audio dip video plugdev fuse lpadmin admin sambashare kvm libvirtd

To add your to the groups:

$ sudo adduser `id -un` kvm Adding user '' to group 'kvm' . $ sudo adduser `id -un` libvirtd Adding user '' to group 'libvirtd' .

After the installation, you need to relogin so that your user becomes an effective member of kvm and libvirtd user groups. The members of this group can run virtual machines.

Verify Installation

You can test if your install has been successful with the following command:

$ virsh list --all Id Name State ---------------------------------- $

If on the other hand you get something like this:

$ virsh list --all libvir: Remote error : Permission denied error: failed to connect to the hypervisor $

Something is wrong (e.g. you did not relogin) and you probably want to fix this before you move on. The critical point here is whether or not you have write access to /var/run/libvirt/libvirt-sock.

The sock file should have permissions similar to:

$ sudo ls -la /var/run/libvirt/libvirt-sock srwxrwx--- 1 root libvirtd 0 2010-08-24 14:54 /var/run/libvirt/libvirt-sock

Also, /dev/kvm needs to be in the right group. If you see:

$ ls -l /dev/kvm crw-rw----+ 1 root root 10, 232 Jul 8 22:04 /dev/kvm

You might experience problems when creating a virtual machine. Change the device’s group to kvm/libvirtd instead:

sudo chown root:libvirtd /dev/kvm

Now you need to either relogin or restart the kernel modules:

Optional: Install virt-manager (graphical user interface)

If you are working on a desktop computer you might want to install a GUI tool to manage virtual machines.

$ sudo apt-get install virt-manager

Virtual Machine Manager will appear in Applications -> System Tools menu. First create a new connection to local QEMU instance from File -> Add Connection menu. Localhost (QEMU) or QEMU/KVM should appear in the virtual machine list. Note: there already exist Localhost (QEMU Usermode) connection but this does not work at least on Ubuntu 10.04.

Create a new virtual machine by pressing the top left Create a new virtual machine toolbar button.

Version-specific Notes

8.10 (Intrepid) Notes

  • Two meta packages have been added: ubuntu-virt-server and ubuntu-virt-mgmt. Ubuntu-virt-server installs the packages needed to setup a base virtulization host (kvm, libvirt-bin and openssh-server) and ubuntu-virt-mgmt installs what you need to administer it from a management station (virt-manager, python-vm-builder and virt-viewer).
  • ubuntu-vm-builder has been replaced by python-vm-builder (tutorial).

or reboot your system before being able to use it.

11.10 (Oneric) Notes

Switching to the server kernel might be helpful if there are start problems with virtual machines (i.e. Windows XP freezes approximately once every 5 starts )

KVM/Installation (последним исправлял пользователь hamishmb 2020-03-23 20:00:34)

The material on this wiki is available under a free license, see Copyright / License for details
You can contribute to this wiki, see Wiki Guide for details

Источник

Оцените статью
Adblock
detector