Laboratory 8 - Linux virtualization

A very short introduction to Linux virtualization. This is the last laboratory from the series.

Laboratory 8 - Linux virtualization

Lab 8 - Virtualization management

In this laboratory you will exercise with KVM, one of the most advanced virtualization hypervisor available.


  1. Lab 8 Working with KVM

    • Lab objective 1: installing KVM from the command line
    • Lab objective 2: creating first Virtual Machines with KVM

Laboratory objective 1: installing KVM from the command line

There might be times when working at the command line is more suited then from a GUI, thus you will need to know how to manage virtualization from the console. Here's how it goes.

1 add virtualization software to your system:

for Debian:

sudo apt install libvirt-bin kvm bridge-utils qemu-common qemu-kvm qemu-utils

for openSUSE:

sudo zypper in kvm_server qemu-kvm patterns-openSUSE-kvm_server bridge-utils

2 if you want to manage virtual machines from the command line using a regular user, you will need to add it to the "libvirtd" group. For example:

sudo adduser yourusername libvirtd

3 to make sure that all necessary services are running, just do:

sudo systemctl enable libvirtdsudo systemctl start libvirtdsudo systemctl status libvirtd

Laboratory objective 2: creating first Virtual Machines

Now that you already installed KVM, you can install a virtual machine with virt-install command, clone an existing virtual machine with virt-clone, or manage you virtual machines with virsh to start, stop, reboot and show infos about virtual machines. Before we start, you need to have an image of a Linux distribution already downloaded, or written on a DVD.

1 create storage with qemu-img:

sudo qemu-img create -f qcow2 -o preallocation=metadata /home/alexandru/vm/debian.qcow2 8G

2 check the image for consistency:

sudo qemu-img check /home/alexandru/vm/debian.qcow2

3 check the amount of space using the info option:

sudo qemu-img info debian.qcow2

4 install the virtual machine with virt-install:

virt-install --connect qemu:///system --name vm_debian9 --ram 1024 --disk path=/home/alexandru/vm/debian.qcow2,format=qcow2 --network=bridge:virbr0,model=virtio --vnc --os-type=linux --cdrom /home/alexandru/downloads/debian-9.1.0-amd64-DVD-1.iso --noautoconsole --keymap=en-us

5 once the virtual machine was installed, you can manage it with virsh command. You can show currently running VMs (list), shutdown a VM (shutdown), immediately stop a VM (destroy), totally remove a VM definition (undefine), show current version information (version), show hostname of the hypervisor (hostname), set VM to start at boot time (autostart):

virsh helpvirsh listvirsh shutdown VMNamevirsh distroy VMNamevirsh undefine VMNamevirsh versionvirsh hostnamevirsh autostart VMName