Virtual machine on linux centos

How to Install KVM on CentOS/RHEL 8

Kernel-based Virtual Machine (KVM in short) is an open-source and de facto standard virtualization solution that is tightly integrated into Linux. It is a loadable kernel module that turns Linux into a type-1 (bare-metal) hypervisor that creates a virtual operating platform used to run virtual machines (VMs).

Under KVM, each VM is a Linux process that is scheduled and managed by the kernel and has private virtualized hardware (i.e CPU, network card, disk, etc.). It also supports nested virtualization, which allows you to run a VM inside another VM.

Some of its key features include support for a wide range of Linux-supported hardware platforms (x86 hardware with virtualization extensions (Intel VT or AMD-V)), it provides enhanced VM security and isolation using both SELinux and secure virtualization (sVirt), it inherits kernel memory management features, and it supports both offline and real-time migration (migration of a running VM between physical hosts).

In this article, you will learn how to install KVM virtualization, create and manage Virtual Machines in CentOS 8 and RHEL 8 Linux.

Prerequisites

Additionally, make sure that your hardware platform supports virtualization by running the following command.

# grep -e 'vmx' /proc/cpuinfo #Intel systems # grep -e 'svm' /proc/cpuinfo #AMD systems

Also, confirm that KVM modules are loaded in the kernel (they should be, by default).

Here is sample output on the test system which is Intel-based:

Check Virtualization Support on CentOS 8

In a previous series of KVM guides, we showed how to create virtual machines in Linux using KVM (Kernel-based Virtual Machine) where we demonstrated how to create and manage VMs using virt-manager GUI tool (which is now deprecated according to the RHEL 8 documentation). For this guide, we will take a different approach, we will use the Cockpit web console.

Step 1: Setup Cockpit Web Console on CentOS 8

1. The cockpit is an easy-to-use, integrated and extendable web-based interface to administer a Linux server in a web browser. It enables you to perform system tasks such as configuring networks, administering storage, creating VMs, and inspecting logs with a mouse. It uses your system’s normal user logins and privileges, but other authentication methods are supported as well.

Читайте также:  Linux enumerate usb devices

It comes pre-installed and enabled on freshly installed CentOS 8 and RHEL 8 system, if you don’t have it installed, install it using the following dnf command. The cockpit-machines extension should be installed to manage VMs based on Libvirt.

# dnf install cockpit cockpit-machines

2. When the package installation is complete, start the cockpit socket, enable it to auto-start at system boot and check its status to confirm that it is up and running.

# systemctl start cockpit.socket # systemctl enable cockpit.socket # systemctl status cockpit.socket

Verify Cockpit Status

3. Next, add the cockpit service in the system firewall which is enabled by default, using the firewall-cmd command and reload the firewall configuration to apply the new changes.

# firewall-cmd --add-service=cockpit --permanent # firewall-cmd --reload

4. To access the cockpit web console, open a web browser and use the following URL to navigate.

https://FQDN:9090/ OR https://SERVER_IP:9090/

The cockpit uses a self-signed certificate to enable HTTPS, simply proceed with the connection when you get a warning from the browser. At the login page, use your server user account credentials.

Cockpit LoginCockpit Dashboard

Step 2: Installing KVM Virtualization CentOS 8

5. Next, install the virtualization module and other virtualization packages as follows. The virt-install package provides a tool for installing virtual machines from the command-line interface, and a virt-viewer is used to view virtual machines.

# dnf module install virt # dnf install virt-install virt-viewer

6. Next, run the virt-host-validate command to validate if the host machine is set up to run libvirt hypervisor drivers.

validate host virtualization setup

7. Next, start the libvirtd daemon (libvirtd) and enable it to start automatically on each boot. Then check its status to confirm that it is up and running.

# systemctl start libvirtd.service # systemctl enable libvirtd.service # systemctl status libvirtd.service

Verify Libvirtd Service

Step 3: Set Up Network Bridge (Virtual Network Switch) via Cockpit

8. Now create a network bridge (virtual network switch) to integrate virtual machines to the same network as the host. By default, once libvirtd daemon is started, it activates the default network interface virbr0 that represents the virtual network switch which operates in NAT mode.

For this guide, we will create a network interface in a bridged mode called br0. This will enable virtual machines to be accessible on the host networks.

From the cockpit main interface, click on Networking, then click Add Bridge as indicated in the following screenshot.

Add Bridge Network

9. From the pop-up window, enter the bridge name and select the bridge slaves or port devices (e.g enp2s0 representing the Ethernet interface) as shown in the following screenshot. Then click Apply.

Enter Network Bridge Settings

10. Now when you look at the list of Interfaces, the new bridge should appear there and after a few seconds, the Ethernet interface should be disabled (taken down).

Читайте также:  Linux выполнение команды в команде

Verify New Network Bridge

Step 4: Creating and Managing Virtual Machines via Cockpit Web Console

11. From the cockpit main interface, click on the Virtual Machines option as highlighted in the following screenshot. From the Virtual Machines page, click on Create VM.

Create New Virtual Machine

12. A window with options to create a new VM will display. Enter the Connection, Name (e,g ubuntu18.04), Installation Source Type (on the test system, we have stored ISO images under the storage pool i.e /var/lib/libvirt/images/), Installation Source, Storage, Size, Memory as shown in the following image. The OS Vendor and Operating System should be picked automatically after entering Installation Source.

Also check the option to immediately start the VM, then click Create.

Add New Virtual Machine in KVM

13. After clicking Create from the previous step, the VM should be automatically started and it should boot using the ISO image provided. Proceed to install the guest operating system (Ubuntu 18.04 in our case).

Install Guest OS on KVM

If you click on Network Interfaces of the VM, the network source should indicate the newly created bridge network interface.

Network Bridge of VM

And during the installation, at the step of configuring a network interface, you should be able to notice that the VMs Ethernet interface receives an IP address from the DHCP server of the host network.

IP Address of VM

Note that you need to install the OpenSSH package to access the guest OS via SSH from any machine on the host network, as described in the last section.

14. When the guest OS installation is complete, reboot the VM, then go to Disks and detach/remove the cdrom device under the VMs disks. Then click Run to start the VM.

Detach Cdrom After VM InstallationRun VM Console

15. Now under Consoles, you can log into the guest OS using a user account you created during the installation of the OS.

VM Login

Step 5: Accessing a Virtual Machine Guest OS via SSH

16. To access the newly installed guest OS from the host network via SSH, run the following command (replace 10.42.0.197 with your guest’s IP address).

Guest VM SSH Login

17. To shut down, restart or delete a VM, click on it from the list of VMs, then use the buttons highlighted in the following screenshot.

Delete Guest VM from KVM

That’s all for now! In this guide, we have shown how to install KVM virtualization packages, and create and manage VMs via the cockpit web console. For more detail, see: Getting started with virtualization in RHEL 8.

Источник

How to Install and Manage Virtual Machines and Containers

Virtualization and containers are hot topics in today’s IT industry. In this article we will list the necessary tools to manage and configure both in Linux systems.

Читайте также:  Linux mint telegram update

For many decades, virtualization has helped IT professionals to reduce operational costs and increase energy savings. A virtual machine (or VM for short) is an emulated computer system that runs on top of another system known as host.

VMs have limited access to the host’s hardware resources (CPU, memory, storage, network interfaces, USB devices, and so forth). The operating system running on the virtual machine is often referred to as the guest operating system.

CPU Extensions

Before we proceed, we need to check if the virtualization extensions are enabled on our CPU(s). To do that, use the following command, where vmx and svm are the virtualization flags on Intel and AMD processors, respectively:

# grep --color -E 'vmx|svm' /proc/cpuinfo

No output means the extensions are either not available or not enabled in the BIOS. While you may continue without them, performance will be negatively impacted.

Install Virtualization Tools in Linux

To begin, let’s install the necessary tools. In CentOS you will need the following packages:

# yum install qemu-kvm libvirt libvirt-client virt-install virt-viewer
$ sudo apt-get install qemu-kvm qemu virt-manager virt-viewer libvirt-bin libvirt-dev

Next, we will download a CentOS 7 minimal ISO file for later use:

# wget http://mirror.clarkson.edu/centos/7/isos/x86_64/CentOS-7-x86_64-Minimal-1804.iso

At this point we are ready to create our first virtual machine with the following specifications:

  • RAM: 512 MB (Note that the host must have at least 1024 MB)
  • 1 virtual CPU
  • 8 GB disk
  • Name: centos7vm
# virt-install --name=centos7vm --ram=1024 --vcpus=1 --cdrom=/home/user/CentOS-7-x86_64-Minimal-1804.iso --os-type=linux --os-variant=rhel7 --network type=direct,source=eth0 --disk path=/var/lib/libvirt/images/centos7vm.dsk,size=8

Depending on the computing resources available on the host, the above command may take some time to bring up the virtualization viewer. This tool will enable you to perform the installation as if you were doing it on a bare metal machine.

How to Manage Virtual Machines in Linux

After you have created a virtual machine, here are some commands you can use to manage it:

Get info about a VM (centos7vm in this case):

Edit the settings of centos7vm in your default text editor:

Enable or disable autostart to have the virtual machine boot (or not) when the host does:

# virsh autostart centos7vm # virsh autostart --disable centos7vm

Once it is stopped, you can clone it into a new virtual machine called centos7vm2:

# virt-clone --original centos7vm --auto-clone --name centos7vm2

And that’s it. From this point on, you may want to refer to the virt-install, virsh, and virt-clone man pages for further info.

Источник

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