Difference between revisions of "Virtualization"

From docwiki
Jump to: navigation, search
(Native KVM on Linux)
Line 34: Line 34:
 
== Native KVM on Linux ==
 
== Native KVM on Linux ==
   
If you are not hooked on a certain platform then KVM is a good and save choice for virtualization.
+
If you are not hooked on a certain platform then KVM is a good and save choice for virtualization.
  +
  +
First we create a virtual hard disk image. (We could also use a real partition or a file that is a 1:1 raw image of a partition). The qcow2 format from QEMU offers a "copy on write" file that only grows as the guest operation system writes data into it:
  +
  +
<pre>
  +
# create a file mybox.qcow2 with an 8GB image
  +
  +
qemu-img create -f qcow2 mybox.qcow2 8G
  +
  +
# initially the image only takes a few kB.
  +
</pre>
  +
  +
Now we can boot into our system. E.g. via:
  +
  +
<pre>
  +
kvm -k de -m 2G mybox.qcow2
  +
</pre>
  +
  +
Where '''-k de''' gives us a german (de) keyboard layout and -m 2G reserves 2G of main memory for our machine. Since our mybox.qcow2 disk is completely empty the system will not boot, but at least we see a window with a virutal PC that tries to boot. Now lets install someting there:
  +
  +
<pre>
  +
wget https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-10.6.0-amd64-netinst.iso
  +
  +
kvm -k de -m 2G --cdrom debian-10.6.0-amd64-netinst.iso -boot d mybox.qcow2
  +
  +
</pre>
  +
  +
And now we are able to install a debian into our virtual machine. In a few minutes of install you will have a fresh install of e.g. debian. You can then stop the machine and keep a copy of that fresh install in order to experiment with it later.
   
 
== libvirt frontend to KVM ==
 
== libvirt frontend to KVM ==

Revision as of 16:14, 30 October 2020


Motivation

With virtual machine you can run a virtual computer inside your real computer. Thus you can save resources by avoiding to have many small machines and you can move these virtual machines between physical hardware in order to allow a higher degree of redundancy. There are a few free software/open source options in and around Linux and also some commercial offerings for virtualization. Here is an overview:

Free Software / Open Source Virtualization

QEMU

Qemu is a software that can emulate a lot of different CPUs and also hardware. It does not require any support from the OS so you can emulate everywhere. The downside is that it is much slower then virtualization with OS and hardware support. The Upside is that you can emulate e.g. an ARM system on your X86 Intel hardware. Etc. Qemu supports among others: x86, x86-64, Spar, ARM, PowerPC, RiscV processors.

Qemu can emulate a full system or just run a binary compiled for a different CPU on another system.

KVM

KVM is the virtualization native to Linux Kernel. It borrows a lot from QEMU and adds native virtualization. The userland tools are similar to that of QEMU. KVM is uses in Googles Cloud but also by IBM and also in parts of Amazons AWS.

XEN

Xen is a dedicated Hypervisor. In order to operate it and have access to hardware devices you need to run a Linux kernel in "Dom0". Xen is older then KVM and customized versions of XEN are used heavily by Amazons AWS Cloud.


Virtual Box

Is a (mostly) open source Virtualization that was developed by SUN and aimed at the desktop. Unfortunately it is now in the Hands of Oracle.

Commercial

  • VMware / ESX VMware was the first software that allowed virtualization of a PC. It is now the market leader in commercial virtualization. In 2004 it was bought by Dell/EMC.
  • Microsoft HyperV This is Microsofts native Virtualization and also powers Microsofts Azure Cloud.
  • Citrix Xen Server A commercial version of Xen,.

Native KVM on Linux

If you are not hooked on a certain platform then KVM is a good and save choice for virtualization.

First we create a virtual hard disk image. (We could also use a real partition or a file that is a 1:1 raw image of a partition). The qcow2 format from QEMU offers a "copy on write" file that only grows as the guest operation system writes data into it:

# create a file mybox.qcow2 with an 8GB image

qemu-img create -f qcow2 mybox.qcow2 8G

# initially the image only takes a few kB.

Now we can boot into our system. E.g. via:

kvm -k de -m 2G mybox.qcow2

Where -k de gives us a german (de) keyboard layout and -m 2G reserves 2G of main memory for our machine. Since our mybox.qcow2 disk is completely empty the system will not boot, but at least we see a window with a virutal PC that tries to boot. Now lets install someting there:

wget https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-10.6.0-amd64-netinst.iso

kvm -k de -m 2G  --cdrom debian-10.6.0-amd64-netinst.iso -boot d  mybox.qcow2 

And now we are able to install a debian into our virtual machine. In a few minutes of install you will have a fresh install of e.g. debian. You can then stop the machine and keep a copy of that fresh install in order to experiment with it later.

libvirt frontend to KVM