Installation of KVM

Install Necessary Packages

For the following setup, we will assume that you are deploying KVM on a server, and therefore do not have any X server on the machine.

You need to install a few packages first:

Lucid (10.04) or later

$ sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils

Karmic (9.10) or earlier

$ sudo aptitude install kvm libvirt-bin ubuntu-vm-builder bridge-utils

  • libvirt-bin provides libvirtd which you need to administer qemu and kvm instances using libvirt

  • qemu-kvm (kvm in Karmic and earlier) is the backend

  • ubuntu-vm-builder powerful command line tool for building virtual machines

  • bridge-utils provides a bridge from your network to the virtual machines

You might also want to install virt-viewer, for viewing instances.

Add Users to Groups

Karmic (9.10) and later

You need to ensure that your username is added to the group libvirtd:

$ sudo adduser `id -un` libvirtdAdding user '<username>' to group 'libvirtd' ...

After this, you need to relogin so that your user becomes an effective member of the libvirtd group.   The members of this group can run virtual machines.  (You can also 'newgrp kvm' in a terminal, but this will affect only that terminal.)

Releases prior to Karmic (9.10)

You need to ensure that your username is added to the groups: kvm and libvirtd.

To check:

$ groupsadm dialout cdrom floppy audio dip video plugdev fuse lpadmin admin sambashare kvm libvirtd

To add your <username> to the groups:

$ sudo adduser `id -un` kvmAdding user '<username>' to group 'kvm' ...$ sudo adduser `id -un` libvirtdAdding user '<username>' to group 'libvirtd' ...

After the installation, you need to relogin so that your user becomes an effective member of kvm and libvirtd user groups. The members of this group can run virtual machines.

Verify Installation

You can test if your install has been successful with the following command:

$ virsh -c qemu:///system list Id Name                 State----------------------------------$

If on the other hand you get something like this:

$ virsh -c qemu:///system listlibvir: Remote error : Permission deniederror: failed to connect to the hypervisor$

Something is wrong (e.g. you did not relogin) and you probably want to fix this before you move on. The critical point here is whether or not you have write access to /var/run/libvirt/libvirt-sock.

The sock file should have permissions similar to:

$ sudo ls -la /var/run/libvirt/libvirt-socksrwxrwx--- 1 root libvirtd 0 2010-08-24 14:54 /var/run/libvirt/libvirt-sock

Also, /dev/kvm needs to be in the right group.  If you see:

 $ ls -l /dev/kvmcrw-rw----+ 1 root root 10, 232 Jul  8 22:04 /dev/kvm

You might experience problems when creating a virtual machine. Change the device's group to kvm/libvirtd instead:

sudo chown root:libvirtd /dev/kvm

Now you need to either relogin or restart the kernel modules:

rmmod kvmmodprobe -a kvm

Optional:  Install virt-manager (graphical user interface)

If you are working on a desktop computer you might want to install a GUI tool to manage virtual machines.

$ sudo apt-get install virt-manager

Virtual Machine Manager will appear in Applications -> System Tools menu. First create a new connection to local QEMU instance from File -> Add Connection menu. Localhost (QEMU) or QEMU/KVM should appear in the virtual machine list. Note: there already exist Localhost (QEMU Usermode) connection but this does not work at least on Ubuntu 10.04.

Create a new virtual machine by pressing the top left Create a new virtual machine toolbar button.

Version-specific Notes

8.10 (Intrepid) Notes

  • Two meta packages have been added: ubuntu-virt-server and ubuntu-virt-mgmt.  Ubuntu-virt-server installs the packages needed to setup a base virtulization host (kvm, libvirt-bin and openssh-server) and ubuntu-virt-mgmt installs what you need to administer it from a management station (virt-manager, python-vm-builder and virt-viewer).  

  • ubuntu-vm-builder has been replaced by python-vm-builder (tutorial).

Note: libdevmapper does not load its module when it is installed (bug 277648) , so you will either need to do a

  •  $ sudo modprobe dm-loop 

or reboot your system before being able to use it.

11.10 (Oneric) Notes

Switching to the server kernel might be helpful if there are start problems with virtual machines (i.e. Windows XP freezes approximately once every 5 starts )


你可能感兴趣的:(Installation of KVM)