Kvm on gentoo

 
 
 

Contents

Gentoo

We tested the instructions using a fresh Gentoo Live CD 2008 Installation. Regardless of the Gentoo version, make sure to refresh the repository information by

emerge --sync

We use the term Host Machine to refer to machines where Virtual Machines will be running. We use the term Management Machine to refer to the machine where Convirt will run to manage all the Host Machines. In the simplest case of just one computer, the Management Machine is also the Host Machine.

Setup the Management Machine

ConVirt depends on the following packages:

  • dev-python/pycairo
  • dev-python/pycrypto - requires the GNU MP library which can be enabled using the "gmp" USE-flag
  • dev-python/paramiko
  • x11-libs/vte
  • net-misc/socat
  • gnome-base/gvfs - required for File Browsing

Please make sure you enable the "gmp" USE-flag for dev-python/pycrypto by either adding it to the USE-variable in the /etc/make.conf file or edit/create /etc/portage/package.use and put the following line in: dev-python/pycrypto gmp

Than install the dependencies:

emerge -av pycairo pycrypto paramiko vte socat gvfs

alternatively you can install the pycrypto package using the following line:

USE=gmp emerge -a pycrypto

If you ever need a console (guess you would need instantly!) you need to install also vncviever:

emerge tightvnc

Install Xen-tools -- (No longer necessary in Convirt 0.9.5)

sudo mkdir -p /etc/portage/package.keywords
sudo echo app-emulation/xen-tools ~x86 >>  /etc/portage/package.keywords
sudo emerge -a xen-tools

Download and unpack convirt

wget http://www.convirture.com/downloads/convirt/1.0/convirt-1.0.tar.gz
tar -zxvf convirt-1.0.tar.gz

If you have remote host machines with KVM setup already, go to the Start Convirt section directly.

Setup KVM on the Host Machines (Gentoo)

Ensure sshd (SSH Daemon) is running, unless the Host Machine is the localhost.

sudo rc-update add sshd default

Install KVM

sudo mkdir -p /etc/portage/package.keywords
sudo echo app-emulation/kvm ~x86 >> /etc/portage/package.keywords/package.keywords
sudo emerge -a genkernel
sudo emerge -a kvm

Note: emerge kvm for the first time will first fail, as it requires KVM compilation in the kernel or as a kernel module. emerge -a kvm will force install all the required dependencies, including Linux Kernel 2.6.25-gentoo-r7 or later.

Compile the kernel, KVM is installed as a module by default.

cd /usr/src/linux
sudo genkernel --menuconfig all

Now emerge kvm should work.

sudo emerge -a kvm             
                             

Link the missing dependencies, because the latest version of gcc on Gentoo is not compatible with qemu, and Convirt uses qemu-system-x86_64 as the KVM binary.

sudo ln -s /usr/bin/kvm      /usr/bin/qemu-system-x86_64
sudo ln -s /usr/bin/kvm-img  /usr/bin/qemu-img

Reboot is necessary to reload the new kernel.

reboot

Start KVM

sudo /sbin/modprobe kvm
sudo /sbin/modprobe kvm-intel

Verify KVM Setup

To make sure you are using the right KVM

sudo kvm | head -n1

Should see something like QEMU PC emulator ... (kvm-7x)

sudo lsmod | grep kvm
sudo modinfo kvm

Should also show kvm-7x.

Test KVM Setup by create a disk image

kvm-img create -f qcow2 vdisk.qcow2 10G

Run KVM manually. Note: -net nic -net user may be necessary for network access

sudo kvm -hda vdisk.qcow2 -m 1024 -cdrom path-to-an-iso-file -net nic -net user

Other Steps

Convirt uses /dev/cdrom by default. Gentoo uses /dev/cdrom1 etc by default. Link your cdrom device, e.g. /dev/cdrom1 to /dev/cdrom

sudo ln -s /dev/cdrom1 /dev/cdrom

Troubleshoot KVM Setup Issues

If you see

open /dev/kvm: No such file or directory
Could not initialize KVM, will disable KVM support

That means either

  • KVM was not compiled as modules
  • KVM was not loaded into the kernel via modprobe kvm and modprobe kvm-intel
  • Didn't run kvm as root, or as a user who has read/write access to /dev/kvm

Start Convirt on the Management Machine

cd convirt-0.9.5
sudo ./Convirt   # managing localhost and remote hosts via SSH, or
./Convirt        # managing remote host via SSH.
 
Have more questions? Submit a request

Comments

 
Adding comment, please wait....

Provide Feedback on Article:

Subject:
Comments:*