Debian 9: Install KVM for virtualization

This article will describe installing KVM and running virtual machine.

1 Install qemu-kvm and libvirt

Install qemu-kvm package and some packages for virtual machine operation.

$ sudo apt install -y qemu-kvm libvirt0 virt-manager bridge-utils

Reboot system.

$ sudo reboot

2 Bridge interface

The bridge interface is needed for accessing virtual machine via network from other machine.

3 libvirt group

The user in libvirt group can run libvirt command without sudo.

$ sudo gpasswd libvirt -a <username>

4 Create iso directory

Create iso directory for sharing iso images with libvirt group. Move debian-9.0.0-amd64-netinst.iso to iso directory.

$ sudo mkdir /var/lib/libvirt/iso
$ sudo mv debian-9.0.0-amd64-netinst.iso /var/lib/libvirt/iso/
$ sudo chown libvirt-qemu:libvirt \
/var/lib/libvirt/iso/debian-9.0.0-amd64-netinst.iso

5 Create virtual machine with virt-manager

The virt-manager is a GUI frontend tool for libvirt. Create virtual machine with virt-manager.

$ virt-manager

Click "New Virtual Machine" at the upper left.

0001_New-Virtual-Machine.png

Select install media. This article uses debian-9.0.0-amd64-netinst.iso in iso directory.

0002_Install-media.png

Select "Browse" button at "Use ISO image".

0003_Select-ISO-image.png

The iso directory cannot be found yet. Click "+" icon for adding iso directory. Input storage pool name and select "dir:Filesystem Directory".

0004_Add-a-New-Storage-Pool.png

Input storage pool path.

0005_Target-Path.png

The iso directory can be found. Select debian-9.0.0-amd64-netinst.iso.

0006_Choose-Storage-Volume.png

debian-9.0.0-amd64-netinst.iso is selected. Select OS type for memory size calculation. The memory size can be changed after this.

0007_OS-type.png

Input core number and memory size.

0008_Choose-Memory-and-CPU-settings.png

Create storage.

0009_Enable-storage-for-this-virtual-machine.png.png

Select network. "Virtual network 'default': NAT" can be accessed from other machine and "Virtual network 'default': NAT" cannot be accessed. Both network can access to other machine.

0010_Network-selection.png

OS installation on virtual machine is starting.