- Installation
- Use a 64 bit kernel (if possible)
- Installation of KVM
- Install Necessary Packages
- Add Users to Groups
- Verify Installation
- Optional: Install virt-manager (graphical user interface)
- Version-specific Notes
- 8.10 (Intrepid) Notes
- 11.10 (Oneric) Notes
- KVM / VirtManager
- Local Installation
- Installation for Remote Server
- Launching
- Creating a Virtual Machine
- Working with a Running Virtual Machine
- Console
- Details
- Deleting a Virtual Machine
Installation
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.
By default, if you booted into XEN kernel it will not display svm or vmx flag using the grep command. To see if it is enabled or not from xen, enter:
cat /sys/hypervisor/properties/capabilities
You must see hvm flags in the output.
Alternatively, you may execute:
which may provide an output like this:
INFO: /dev/kvm exists KVM acceleration can be used
INFO: Your CPU does not support KVM extensions KVM acceleration can NOT be used
You can still run virtual machines, but it’ll be much slower without the KVM extensions.
NOTE: You may see a message like «KVM acceleration can/can NOT be used». This is misleading and only means if KVM is *currently* available (i.e. «turned on»), *not* if it is supported.
Use a 64 bit kernel (if possible)
- 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.
- 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:
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:
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:
Cosmic (18.10) or later
$ sudo apt-get install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils
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 (but not 14.04 LTS and 18.10)
You need to ensure that your username is added to the group libvirtd:
$ sudo adduser `id -un` libvirtd Adding user '' 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.)
Bionic (18.04 LTS) and higher
The group name is changed to libvirt, and you also need to be a member of ‘kvm’:
$ sudo adduser `id -un` libvirt Adding user '' to group 'libvirt' . $ sudo adduser `id -un` kvm Adding user '' to group 'kvm' .
Releases prior to Karmic (9.10)
You need to ensure that your username is added to the groups: kvm and libvirtd.
$ groups adm dialout cdrom floppy audio dip video plugdev fuse lpadmin admin sambashare kvm libvirtd
To add your to the groups:
$ sudo adduser `id -un` kvm Adding user '' to group 'kvm' . $ sudo adduser `id -un` libvirtd Adding user '' 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 list --all Id Name State ---------------------------------- $
If on the other hand you get something like this:
$ virsh list --all 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
Also, /dev/kvm needs to be in the right group. If you see:
$ ls -l /dev/kvm crw-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:
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).
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 )
KVM/Installation (последним исправлял пользователь hamishmb 2020-03-23 20:00:34)
The material on this wiki is available under a free license, see Copyright / License for details
You can contribute to this wiki, see Wiki Guide for details
KVM / VirtManager
You can create, delete, run, stop, and manage your virtual machines graphically. The tool virt-manager allows you to use a graphical interface to interact with KVM.
Local Installation
sudo apt-get install virt-manager
- Applications ->Ubuntu Software Center -> Search for «virt-manager»
- Install «Virtual Machine Manager»
Installation for Remote Server
sudo apt-get install virt-manager ssh-askpass-gnome --no-install-recommends
This will give you virt-manager, and the tool to ask for an ssh password to connect to other servers, and that is all.
Launching
- Applications ->System Tools ->Virtual Machine Manager
- File ->Add Connection
- Hypervisor: QEMU/KVM
- Connection: Remote tunnel over SSH
- Hostname: hostname or IP address of the remote host. For a user other than root use the format username@hostname and make sure the user is part of the libvirtd on the remote server.
Creating a Virtual Machine
- First, download an ISO cd image of some OS you want to run. For Ubuntu, you can find these at:
- http://www.ubuntu.com/getubuntu/download
- Enter your virtual machine details
- Name: foo
- Choose Local install media (ISO image or CDROM), or you can use another method if you know what you’re doing
- Forward
- Locate your install media
- Use ISO image
- Browse to find the ISO you downloaded earlier
- Optional: Select the matching OS Type
- Optional: Select the matching Version
- Forward
- Choose Memory and CPU settings
- Memory (RAM): 512MB (your choice)
- CPUs: 1 (your choice)
- Forward
- Select Enable storage for this virtual machine
- Select Create a disk image on the computer’s hard drive
- 8 GB is the default
- To speed up VM creation, you can unselect Allocate entire disk now
- Forward
- Ready to begin installation
- Confirm the details
- Finish
- You should now see the OS installation proceed within a virt-manager window. Complete the installation and reboot.
Working with a Running Virtual Machine
If you double-click on any machine in Virtual Machine Manager, a new window will open, with functions unique to that virtual machine.
- Run
- Pause
- Shutdown (cleanly shuts down the VM OS)
- Reboot (cleanly reboots the VM OS)
- Force off (equivalent to yanking the power, could yield data loss in the VM)
- Fullscreen
Console
- The desktop is accessed over a VNC connection to the guest. When you are «inside» the guest, the keyboard and mouse are «locked» to the guest. To release the keyboard and mouse, press the buttons Ctrl-Alt at the same time.
- The tty console can been accessed by:
- Send Key ->Ctrl-Alt-F1
Details
- the number of processors allocated
- the amount of memory assigned
- the default boot device (CDROM or Hard Disk)
- a listing of the storage devices attached to the VM and their type (CDROM, IDE, SCSI, Virtio)
- the network adapter and its model
- the emulated mouse, display, serial, and sound hardware
Deleting a Virtual Machine
- Shutdown or force off the VM.
- In Virtual Machine Manager, highlight the VM you want to delete
- Click Delete at the bottom of the panel
- You can optionally delete the associated disk file for the VM. If you don’t want or need the data within the VM itself, you should delete the storage file, as these are usually very large.
KVM/VirtManager (последним исправлял пользователь c-73-136-18-217 2016-04-10 01:23:12)
The material on this wiki is available under a free license, see Copyright / License for details
You can contribute to this wiki, see Wiki Guide for details