Difference between revisions of "Linux on KVM"

From Funtoo
Jump to navigation Jump to search
(vmware, cirrus vga)
Line 4: Line 4:


<console>
<console>
# ##i##qemu-img create -f qcow2 vdisk.qcow2 10
# ##i##qemu-img create -f qcow2 vdisk.qcow2 10G
</console>
</console>



Revision as of 03:14, April 2, 2015

Starting your first KVM virtual machine

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:

root # qemu-img create -f qcow2 vdisk.qcow2 10G

You have several possibillities to display your virtual machine. You can tell qemu to start a VNC server, or you can display it directly in it's own window.

   Note

It might be possible that you have to add '--enable-kvm' switch to 'qemu-system-x86_64'.

Output

It might be possible that some parts of the windows in your guest system look fuzzy, this might be because of the cirrus/std driver. A solution for this is to use vmware driver for displaying. First download the driver:

root #  emerge -a xf86-video-vmware xf86-input-vmmouse

It might be that you need to add some USE flags before you can emerge those:

root #  echo "x11-libs/libdrm video_cards_vmware" >> /etc/portage/package.use
root #  echo "media-libs/mesa xa" >> /etc/portage/package.use

Now add the '-vga vmware' switch when calling 'qemu-system'.

Own window

Qemu needs to be compiled with either 'gtk' or 'sdl' use flags.

root # qemu-system-x86_64 vdisk.qcow2 -m 1024 -cdrom systemrescuecd.iso  -cpu host -net nic -net user -vgs std -monitor stdio

VNC

root # qemu-system-x86_64 vdisk.qcow2 -m 1024 -cdrom systemrescuecd.iso -cpu host -net nic -net user  -vnc 127.0.0.1:1
VNC server running on `127.0.0.1:5900'

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. A plus for this method is, that you can close the window but the machine will keep on running, if you need it again just connect again via VNC.

Networking Options

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.

First, create /etc/qemu-ifup and add the following to it. Replace brlan with the name of your bridge:

#!/bin/bash
ifconfig $1 0.0.0.0 promisc up
brctl addif brlan $1
sleep 2

Make it executable:

root # chmod +x /etc/qemu-ifup

Start the virtual machine as follows:

root # 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

Tweaking KVM

VNC Output

If you wanted to have VNC listen on a different IP address or port, you can use the format -vnc IP:vncnum which will cause VNC to listen on the IP specified, and the TCP port 5900+vncnum.

CPU Settings

By default, the KVM guest will have one CPU with one core. To change this, use -cpu host (to export all of the host's CPU features) and -smp cores=X,threads=Y, 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.