KVM

From Indie IT Wiki
Jump to: navigation, search

Introduction

KVM (for Kernel-based Virtual Machine) is a full virtualization solution for Linux on x86 hardware containing virtualization extensions (Intel VT or AMD-V). It consists of a loadable kernel module, kvm.ko, that provides the core virtualization infrastructure and a processor specific module, kvm-intel.ko or kvm-amd.ko.

Using KVM, one can run multiple virtual machines running unmodified Linux or Windows images. Each virtual machine has private virtualized hardware: a network card, disk, graphics adapter, etc.

KVM is open source software. The kernel component of KVM is included in mainline Linux, as of 2.6.20. The userspace component of KVM is included in mainline QEMU, as of 1.3.

HOWTOs

Install

sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils

Guest Agent

ssh user@guest
sudo apt-get install qemu-guest-agent
sudo reboot

List

virsh --connect qemu:///system list --all

Start

virsh --connect qemu:///system start '<Name>'

Stop

virsh --connect qemu:///system stop '<Name>'

Reboot

virsh --connect qemu:///system stop '<Name>'

Connect Remotely

virsh --connect qemu+ssh://username@servername/system

https://libvirt.org/remote.html#Remote_URI_reference

https://libvirt.org/uri.html

http://manpages.ubuntu.com/manpages/bionic/en/man1/virsh.1.html

Management

Ubuntu KVM Page

VirSH (Command Line)

Virtual Machine Manager (X Based GUI)

WebVirtMgr (Web Based)

Upgrade Virtual Disk Size

SSH in the host...

ssh login@host

Switch to root user...

sudo -i

Change to the Images directory...

cd /var/lib/libvirt/images

Check disk file...

qemu-img info disk1.qcow2

Increase disk size...

qemu-img resize disk1.qcow2 +10G

Check disk file again...

qemu-img info disk1.qcow2

Log out of host...

logout

Log in to guest...

ssh login@guest

Switch to root...

sudo -i

Install Cloud Utils for growpart software...

sudo apt-get -y install cloud-guest-utils

List current blocks...

lsblk

Extend partition to fill remaining space...

 growpart /dev/vda 2

Extend filesystem to fill remaining space...

resize2fs /dev/vda2

Reboot...

reboot

Information

Offical Web Site

Ubuntu Official Documentation

Nice Command Line examples