How to Install and Configure KVM on Ubuntu 18.04

Requirements

Launch Alibaba Cloud ECS Instance

apt-get update -y

Verify Hardware Support

egrep -c '(vmx|svm)' /proc/cpuinfo
2
apt-get install cpu-checker
kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used

Install KVM

apt-get install qemu qemu-kvm libvirt-bin bridge-utils virt-manager virt-viewer  -y
systemctl start libvirtd
systemctl enable libvirtd
service libvirtd status
¡ñ libvirtd.service - Virtualization daemon
Loaded: loaded (/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2019-01-16 06:24:18 UTC; 8min ago
Docs: man:libvirtd(8)
https://libvirt.org
Main PID: 5047 (libvirtd)
Tasks: 19 (limit: 32768)
CGroup: /system.slice/libvirtd.service
©À©€5047 /usr/sbin/libvirtd
©À©€5586 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper
©ž©€5587 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper
Jan 16 06:32:22 ubuntu1804 dnsmasq[5586]: reading /etc/resolv.conf
Jan 16 06:32:22 ubuntu1804 dnsmasq[5586]: using nameserver 127.0.0.53#53
Jan 16 06:32:22 ubuntu1804 dnsmasq[5586]: reading /etc/resolv.conf
Jan 16 06:32:22 ubuntu1804 dnsmasq[5586]: using nameserver 127.0.0.53#53
Jan 16 06:32:22 ubuntu1804 dnsmasq[5586]: reading /etc/resolv.conf
Jan 16 06:32:22 ubuntu1804 dnsmasq[5586]: using nameserver 127.0.0.53#53
Jan 16 06:32:24 ubuntu1804 dnsmasq[5586]: reading /etc/resolv.conf
Jan 16 06:32:24 ubuntu1804 dnsmasq[5586]: using nameserver 127.0.0.53#53
Jan 16 06:32:24 ubuntu1804 dnsmasq[5586]: reading /etc/resolv.conf
Jan 16 06:32:24 ubuntu1804 dnsmasq[5586]: using nameserver 127.0.0.53#53

Configure Bridge Networking

nano /etc/netplan/50-cloud-init.yaml
network:
version: 2
ethernets:
enp0s3:
dhcp4: no
dhcp6: no
bridges:
br0:
interfaces: [enp0s3]
dhcp4: no
addresses: [192.168.0.100/24]
gateway4: 192.168.0.1
nameservers:
addresses: [192.168.0.1]
netplan apply
networkctl status -a
¡ñ 1: lo
Link File: /lib/systemd/network/99-default.link
Network File: n/a
Type: loopback
State: carrier (unmanaged)
Address: 127.0.0.1
::1
¡ñ 2: enp0s3
Link File: /lib/systemd/network/99-default.link
Network File: /run/systemd/network/10-netplan-enp0s3.network
Type: ether
State: carrier (configured)
Path: pci-0000:00:03.0
Driver: e1000
Vendor: Intel Corporation
Model: 82540EM Gigabit Ethernet Controller (PRO/1000 MT Desktop Adapter)
HW Address: 08:00:27:58:d6:9b (PCS Systemtechnik GmbH)
¡ñ 3: virbr0
Link File: /lib/systemd/network/99-default.link
Network File: n/a
Type: ether
State: no-carrier (unmanaged)
Driver: bridge
HW Address: 52:54:00:e0:0b:f0
Address: 192.168.122.1
¡ñ 4: virbr0-nic
Link File: /lib/systemd/network/99-default.link
Network File: n/a
Type: ether
State: off (unmanaged)
Driver: tun
HW Address: 52:54:00:e0:0b:f0
¡ñ 5: br0
Link File: /lib/systemd/network/99-default.link
Network File: /run/systemd/network/10-netplan-br0.network
Type: ether
State: routable (configured)
Driver: bridge
HW Address: 3a:26:a7:35:e0:af
Address: 192.168.0.100
fe80::3826:a7ff:fe35:e0af
Gateway: 192.168.0.1
fe80::225:5eff:fe60:65c (Shanghai Dare Technologies Co.,Ltd.)
DNS: 192.168.0.1

Create Virtual Machine

virt-manager

Manage KVM Virtual Machines Using CLI

virsh list --all
Id    Name                           State
----------------------------------------------------
- Alibaba-Ubuntu14.04 shut off
virsh start Alibaba-Ubuntu14.04
Domain Alibaba-Ubuntu14.04 started
virsh list --all
Id    Name                           State
----------------------------------------------------
6 Alibaba-Ubuntu14.04 running
virsh suspend Alibaba-Ubuntu14.04
Domain Alibaba-Ubuntu14.04- suspended
virsh resume Alibaba-Ubuntu14.04
Domain Alibaba-Ubuntu14.04 resumed
virsh shutdown Alibaba-Ubuntu14.04
Domain Alibaba-Ubuntu14.04 is being shutdown
virt-clone --original=Alibaba-Ubuntu14.04 --name=Alibaba-Ubuntu14.04-Clone --file=/var/lib/libvirt/images/Alibaba-Ubuntu14.04-clone.img
Allocating 'Alibaba-Ubuntu14.04-clone.img'             | 8.0 GB     00:02     Clone 'Alibaba-Ubuntu14.04-Clone' created successfully.
virsh list --all
Id    Name                           State
----------------------------------------------------
- Alibaba-Ubuntu14.04 shut off
- Alibaba-Ubuntu14.04-Clone shut off
virsh undefine Alibaba-Ubuntu14.04-Clone
Domain Alibaba-Ubuntu14.04-Clone has been undefined
virt-install --name=Ubuntu-16.10 --vcpus=1 --ram=1024 --cdrom=/Data/ISO/ubuntu-16.10-desktop-amd64.iso --disk path=/var/lib/libvirt/images/ubuntu-16.10.img,size=10 --os-type=linux

Original Source

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store