Setup a KVM Hypervisor on Ubuntu to Host Virtual Machines
Today we will setup a KVM (Kernel Virtual Machine) Hypervisor, where we can host Virtual Machines. In order to do so, your host needs to Support Hardware Virtualization.
What we will be doing today:
Check if your host supports Hardware Virtualization
Setup the KVM Hypervisor
Setup a Alpine VM
Check for Hardware Virtualization Support:
We will install the package required to do the check:
Starting install...
Allocating 'alpine1.img'|8 GB 00:00:01
Creating domain... |0 B 00:00:00
Connected to domain alpine1
Escape character is ^]ISOLINUX 6.04 6.04-pre1 Copyright (C) 1994-2015 H. Peter Anvin et al
boot:
OpenRC 0.24.1.a941ee4a0b is starting up Linux 4.9.65-1-virthardened (x86_64)Welcome to Alpine Linux 3.7
Kernel 4.9.65-1-virthardened on an x86_64 (/dev/ttyS0)localhost login:
Login with the root user and no password, then setup the VM by running setup-alpine:
1234
localhost login: root
Welcome to Alpine!
localhost:~# setup-alpine
After completing the prompts reboot the VM by running reboot, then you will be dropped out of the console. Check the status of the reboot:
1234
$ virsh list
Id Name State
----------------------------------------------------
2 alpine1 running
As we can see our guest is running, lets console to our guest, provide the root user and password that you provided during the setup phase:
1234567
$ virsh console 2
Connected to domain alpine1
Escape character is ^]alpine1 login: root
Password:
Welcome to Alpine!
Setup OpenSSH so that we can SSH to our guest over the network:
12
$ apk update
$ apk add openssh
Configure SSH to accept Root Passwords, this is not advisable for production environments, but for testing this is okay. For Production servers, we will rather look at Key Based Authentication etc.
12
$ sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
$ /etc/init.d/sshd restart