Skip to main content

LFCS Certification Course

Chapter #31: Managing and Configuring VMs and Containers

In this chapter, we explain how to install and manage virtual machines on RHEL and Ubuntu, set up Docker, and deploy an Apache container to serve web pages without installing a web server on the host.

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

Managing and Configuring Virtual Machines

For many decades, virtualization has helped IT professionals reduce operational costs and increase energy savings.

A virtual machine (VM) is an emulated computer system that runs on top of another system known as the host. VMs have limited access to the host’s hardware resources (CPU, memory, storage, network interfaces, USB devices, etc.).

The operating system running on the virtual machine is often referred to as the guest operating system.

Check CPU Extensions

Before proceeding, check if the virtualization extensions are enabled on your CPU(s) using 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

To begin, install the necessary tools on your RHEL system, using the following packages:

sudo yum install qemu-kvm libvirt libvirt-client virt-install virt-viewer virt-manager

On Ubuntu, use:

sudo apt install qemu-kvm qemu virt-manager virt-viewer libvirt-bin libvirt-dev

Next, download an RHEL minimal ISO file and create your first virtual machine with the following command, make sure to adjust the parameters to match your environment:

virt-install --name=rhelvm --ram=1024 --vcpus=1 --cdrom=/home/user/rhel-10.0-x86_64-boot.iso --os-type=linux --os-variant=rhel --network type=direct,source=eth0 --disk path=/var/lib/libvirt/images/rhelvm.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 and enable you to perform the installation as if you were doing it on a bare metal machine.

Useful Commands to Manage VM

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

List all VMs:

virsh --list --all

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

virsh dominfo rhelvm

Edit the settings of rhelvm in your default text editor:

virsh edit rhelvm

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

virsh autostart rhelvm
virsh autostart --disable rhelvm

Stop rhelvm:

virsh shutdown rhelvm

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

virt-clone --original rhelvm --auto-clone --name rhelvm2

For more information, refer to the virt-install, virsh, and virt-clone man pages.

Managing and Configuring Containers

If you're a Linux system administrator supporting developers, chances are you've heard of Docker. If not, this software solution will make your life easier by helping you reduce operating costs and accelerate deployments - among other benefits.