https://www.funtoo.org/api.php?action=feedcontributions&user=46.59.61.80&feedformat=atomFuntoo - User contributions [en]2024-03-29T12:11:46ZUser contributionsMediaWiki 1.36.2https://www.funtoo.org/index.php?title=KVM&diff=2098KVM2013-04-23T18:31:20Z<p>46.59.61.80: Changed qemu-kvm to qemu (http://forums.funtoo.org/viewtopic.php?id=1657)</p>
<hr />
<div><br />
== Introduction ==<br />
<br />
KVM is a hardware-accelerated full-machine hypervisor and virtualization solution included as part of kernel 2.6.20 and later. It allows you to create and start hardware-accelerated virtual machines under Linux using the QEMU tools.<br />
<br />
== Kernel Setup ==<br />
<br />
To enable KVM, the following kernel config parameters should be enabled (this is based on a 3.x kernel):<br />
<br />
Under <tt>Processor type and features</tt>, enable <tt>Paravirtualized Guest Support</tt>. Under the <tt>Paravirtualized Guest Support</tt> menu, enable any options related to KVM, such as <tt>KVM paravirtualized clock</tt> and in particular <tt>KVM Guest Support</tt>.<br />
<br />
Under the <tt>Virtualization</tt> category from the main kernel config menu, enable <tt>Kernel-based Virtual Machine (KVM) support</tt>, and enable at least one type of KVM, either for Intel or AMD processors. It is also recommended to enable <tt>Host kernel acceleration for virtio net</tt>.<br />
<br />
You can use modules or build these parts directly into the kernel. Build your new kernel and modules, and reboot.<br />
<br />
== User-space tools ==<br />
<br />
KVM is essentially a kernel-accelerated version of QEMU. To enable KVM support in the user-space tools, add the following lines to <tt>/etc/make.conf</tt>:<br />
<br />
<pre><br />
QEMU_SOFTMMU_TARGETS="i386 x86_64"<br />
QEMU_USER_TARGETS="i386 x86_64"<br />
</pre><br />
<br />
Once the <tt>make.conf</tt> variables above are set, emerge qemu:<br />
<br />
<console><br />
# ##i## emerge qemu<br />
</console><br />
<br />
==Initial Setup==<br />
<br />
Prior to using KVM, modprobe the appropriate accelerated driver for Intel or AMD:<br />
<br />
<console><br />
# ##i##modprobe kvm_intel<br />
</console><br />
<br />
== Starting your first KVM virtual machine ==<br />
<br />
To start your first KVM virtual machine, first download SysRescueCD and save it to systemrescuecd.iso. Then use the following commands, which will create a 10GB qcow disk image to use for the first disk, and then the next command will start your virtual machine, booting from the CD:<br />
<br />
<console><br />
# ##i##qemu-img create -f qcow2 vdisk.qcow2 10<br />
# ##i##qemu-system-x86_64 vdisk.qcow2 -m 1024 -cdrom systemrescuecd.iso -vnc 127.0.0.1:1 -cpu host -net nic -net user<br />
VNC server running on `127.0.0.1:5900'<br />
</console><br />
<br />
Now you should be able to use a VNC client to connect to 127.0.0.1:5901 (VNC session 1) and access your virtual machine.<br />
<br />
== Networking Options ==<br />
<br />
Above, networking will be enabled but will be on its own private LAN, and ping will not work. If you have a local bridge that you use for networking, the following steps will allow you use your existing bridge to provide higher-performance and full-featured network access to your virtual machine. <br />
<br />
First, create <tt>/etc/qemu-ifup</tt> and add the following to it. Replace <tt>brlan</tt> with the name of your bridge:<br />
<br />
<syntaxhighlight lang="bash"><br />
#!/bin/bash<br />
ifconfig $1 0.0.0.0 promisc up<br />
brctl addif brlan $1<br />
sleep 2<br />
</syntaxhighlight><br />
<br />
Make it executable:<br />
<br />
<console><br />
# ##i##chmod +x /etc/qemu-ifup<br />
</console><br />
<br />
Start the virtual machine as follows:<br />
<br />
<console><br />
# ##i##qemu-system-x86_64 vdisk.qcow2 -m 1024 -cdrom systemrescuecd-x86-2.8.0.iso -cpu host -vnc 127.0.0.1:1 -net nic -net tap,id=foo<br />
</console><br />
<br />
== Tweaking KVM ==<br />
<br />
=== VNC Output ===<br />
<br />
If you wanted to have VNC listen on a different IP address or port, you can use the format <tt>-vnc IP:vncnum</tt> which will cause VNC to listen on the IP specified, and the TCP port 5900+vncnum.<br />
<br />
=== CPU Settings ===<br />
<br />
By default, the KVM guest will have one CPU with one core. To change this, use <tt>-cpu host</tt> (to export all of the host's CPU features) and <tt>-smp cores=X,threads=Y</tt>, where X is the number of cores, and Y is the number of threads on each core. You can emulate more CPUs and cores than you actually have.<br />
<br />
[[Category:Virtualization]]<br />
[[Category:OpenStack]]<br />
[[Category:Featured]]</div>46.59.61.80