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.

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

whereas in Ubuntu:

$ 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:

List all VMs:

# virsh --list all

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

# virsh dominfo centos7vm

Edit the settings of centos7vm in your default text editor:

# virsh edit centos7vm

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

# virsh autostart centos7vm
# virsh autostart --disable centos7vm

Stop centos7vm:

# virsh shutdown 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.

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Gabriel Cánepa

Gabriel Cánepa is a GNU/Linux sysadmin and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

4 Responses

  1. I want to create VM and join interface of the VM to a OVS bridge i.e. eth0 on VM and TAP interface on Bridge. Please let me know the commands

  2. DarkSun says:

    How can I delete the Virtual Machines?

    • Ravi Saive says:

      @DarkSun,

      Deleting a VM Guest, also remove its configuration stored under /etc/ directory, along with its storage files.

      To remove VM, first list the running VM guests, once you the name of the VM, shutdown and delete using following commands.

      # virsh list
      # virsh shutdown VM_NAME
      # virsh undefine VM_NAME
      
  3. Eugene says:

    So where is the info about using containers?

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.