Diff for "KVM/Installation"


Differences between revisions 35 and 36
Revision 35 as of 2010-09-08 18:13:33
Size: 6311
Editor: cpe-67-249-204-157
Comment: fixed obvious typo
Revision 36 as of 2010-09-16 18:58:07
Size: 6092
Editor: bi-01f
Comment: Reorganized and restructured. Moved some version specific notes into the main text.
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
||<tablestyle="float:right; font-size: 0.9em; width:30%; background:#F1F1ED; margin: 0 0 1em 1em;" style="padding:0.5em;"><<TableOfContents(2)>>|| ||<tablestyle="float:right; font-size: 0.9em; width:30%; background:#F1F1ED; margin: 0 0 1em 1em;" style="padding:0.5em;"><<TableOfContents(3)>>||
Line 7: Line 7:
== Check that your CPU supports hardware virtualization == == Pre-installation checklist ==
=
== Check that your CPU supports hardware virtualization ===
Line 20: Line 21:
== Use a 64 bit kernel (if possible) == === Use a 64 bit kernel (if possible) ===

Running a 64 bit kernel on the host operating system is recommended but not required.
Line 43: Line 46:
Line 46: Line 48:
=== Install Necessary Packages ===
Line 50: Line 53:
'''Lucid (10.4) or later'''
{{{
$ sudo aptitude install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils
}}}

'''Karmic (9.10) or earlier'''
Line 54: Line 63:
 * libvirt-bin provides libvirtd which you need to administer qemu and kvm instances using libvirt
 * kvm 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
 * ''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
Line 60: Line 69:

=== Add Users to Groups ===

'''Karmic (9.10) and later'''

The libvirtd-bin package will automatically add your username to the libvirtd group. There is no need to be part of the kvm group.

After the installation, '''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.

'''Releases prior to Karmic (9.10)'''
Line 81: Line 100:
=== Verify Installation ===
Line 99: Line 120:
Something is wrong (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''. 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''.
Line 107: Line 129:
== virt-manager - graphical user interface == === Optional: Install virt-manager (graphical user interface) ===
Line 121: Line 143:
=== 10.04 (Lucid) Notes ===
 * The package 'kvm' is replaced by 'qemu-kvm'. The kvm package is now marked as transitional so it still works to install it.

=== 9.10 (Karmic) Notes ===
'''Adding Users:'''
 * The libvirt-bin package will now automatically add members of the ''admin'' group to the ''libvirtd'' group. You still need to log out, and log back in for this change to take effect.

Add yourself to the ''libvirtd'' group (note that there is no need to add yourself to the ''kvm'' group):
{{{
$ sudo adduser `id -un` libvirtd
}}}

This will give you access to the system-wide libvirtd instance. This is preferable for you because it gives you access to the advanced networking options rather than simply the "userspace networking" option as you may know it from QEmu.

Note: You need to log out and log back in for the new group membership to take effect.

Note: The `id -un` command will return the current username, for example if your username is ''joe'' you will be effectively be running ''sudo adduser joe libvirtd''.
Line 147: Line 151:

Installation

Pre-installation checklist

Check that your CPU supports hardware virtualization

To run KVM, you need a processor that supports hardware virtualization. Intel and AMD both have developed extensions for their processors, deemed respectively Intel VT-x (code name Vanderpool) and AMD-V (code name Pacifica). To see if your processor supports one of these, you can review the output from this command:

egrep -c '(vmx|svm)' /proc/cpuinfo

If 0 it means that your CPU doesn't support hardware virtualization.

If 1 (or more) it does - but you still need to make sure that virtualization is enabled in the BIOS.

Use a 64 bit kernel (if possible)

Running a 64 bit kernel on the host operating system is recommended but not required.

  1. To serve more than 2GB of RAM for your VMs, you must use a 64-bit kernel (see 32bit_and_64bit). On a 32-bit kernel install, you'll be limited to 2GB RAM at maximum for a given VM.

  2. Also, a 64-bit system can host both 32-bit and 64-bit guests. A 32-bit system can only host 32-bit guests.

To see if your processor is 64-bit, you can run this command:

egrep -c ' lm ' /proc/cpuinfo

If 0 is printed, it means that your CPU is not 64-bit.

If 1 or higher, it is. Note: lm stands for Long Mode which equates to a 64-bit CPU.

Now see if your running kernel is 64-bit, just issue the following command:

uname -m

x86_64 indicates a running 64-bit kernel. If you use see i386, i486, i586 or i686, you're running a 32-bit kernel.

Note: x86_64 is synonymous with amd64.

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.4) or later

$ sudo aptitude 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

The libvirtd-bin package will automatically add your username to the libvirtd group. There is no need to be part of the kvm group.

After the installation, 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.

Releases prior to Karmic (9.10)

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

To check:

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

To add your <username> to the groups:

$ sudo adduser `id -un` kvm
Adding user '<username>' to group 'kvm' ...
$ sudo adduser `id -un` libvirtd
Adding 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 list
libvir: Remote error : Permission denied
error: 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-sock
srwxrwx--- 1 root libvirtd 0 2010-08-24 14:54 /var/run/libvirt/libvirt-sock

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) 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.

KVM/Installation (last edited 2020-03-23 20:00:34 by hamishmb)