Quick Start Guide: Virtualization with KVM
Introduction
KVM is an open source software providing full virtualization solution for Linux running on x86 (including 64-bit) processors that support virutalization Intel VT and AMD-V). KVM requires that the Host's machine processor has virutalization support, to find our whether your host's machine processor support virtualization, you may either run:
$ LC_ALL=C lscpu | grep Virtualization
$ grep -E --color=auto 'vmx|svm|0xc0f' /proc/cpuinfo
Installation
For minimal installation on Debian Stretch, run:# apt-get install qemu-kvm libvirt-clients libvirt-daemon-system
# apt-get install qemu-kvm libvirt-bin
Installing Virtual Machine
Install virtinst by running: # apt install virtinst
# virt-manager
Other options is to use the command line interface, from the command line we may install machines as normal user. For example we can define Kali Linux machine and name if foo by using the following command:
virt-install \
--virt-type kvm \
--name foo \
--memory 2048 \
--cdrom ~/Downloads/kali/kali-linux-2016.2-amd64.iso \
--disk /home/user/kvm/kali2/kali2.qcow2,size=15 \
--os-variant linux
Initiating the Virtual Machine (VM)
Let us focus on managing and initializing VM via the command line interface or CLI. To list all virtual machines we run # virsh list --all
# virsh start foo
# apt install virtinst
# virt-viewer foo
# virsh console foo
- On the guest machine: run:
# systemctl enable serial-getty@ttyS0.service # systemctl start serial-getty@ttyS0.service
- On the guest machine: Open /etc/default/grub file, find the lines
GRUB_CMDLINE_LINUX_DEFAULT="quiet" #GRUB_TERMINAL=console
GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0" GRUB_TERMINAL="serial console"
- On the guest machine: run
# update grub
and then shutdown your guest machine.
- IN the host machine: run
$ virsh start foo --console
$ virsh console foo