Manual:KVM: Difference between revisions

From MikroTik Wiki
Jump to navigation Jump to search
m (spelling)
Line 61: Line 61:




If kernel and initrd fields are left empty, KVM will use hosts kernel and initrd. This is dangerous if you are going to run different RotuerOS version on host and guest and '''can brake your system'''. Guests other than RouterOS can brake if you leave these values empty.
If kernel and initrd fields are left empty, KVM will use hosts kernel and initrd. This is dangerous if you are going to run different RouterOS version on host and guest and '''can break your system'''. Guests other than RouterOS can break if you leave these values empty.




Line 90: Line 90:
If static interface is added and no mac address is set, it is automatically generated and set. For ''static'' interface this address will not change during use of guest. MAC address of ''dynamic'' interface will change every time dynamic interface is created. Automatically generate MAC addresses will be in form of 02:XX:XX:XX:XX:XX
If static interface is added and no mac address is set, it is automatically generated and set. For ''static'' interface this address will not change during use of guest. MAC address of ''dynamic'' interface will change every time dynamic interface is created. Automatically generate MAC addresses will be in form of 02:XX:XX:XX:XX:XX


'''Add and remove interfaces only when KVM guest is shut-down, stoped or disabled'''. Making changes to running guest may lead to host system crash.
'''Add and remove interfaces only when KVM guest is shut-down, stopped or disabled'''. Making changes to running guest may lead to host system crash.


==States of KVM guest==
==States of KVM guest==

Revision as of 13:20, 28 October 2009

Version.png

Applies to RouterOS: v4 on x86

Overview

Kernel-based Virtual Machine provides visualization on x86 RouterOS. It provides full virtualization to allow run multiple operating systems as guests on RouterOS host.

Requirements

KVM requires CPU virtualization support in form of Intel VT-x or AMD-V. To run guest it requires at least 16 MB of RAM and sufficient storage space on image file. Image file cannot be expanded after created and its size be equal to one you entered in creation process of image.

Packages needed to be installed for KVM

  • system
  • kvm

Configuration

All KVM related configuration is done in /kvm menu in console. Available menus for KVM guest configuration are:

  • /kvm - main KVM configuration menu
  • /kvm interface - KVM interface configuration menu
  • /interface virtual-ethernet - KVM interface "hook-up" with host.

KVM commands

Commands available under /kvm menu:

  • add - Create new KVM guest entry
  • comment - Set comment for KVM guest entry
  • console - to connect to KVM guest console display
  • continue - resume KVM guest if it was paused
  • disable - change global state of KVM guest. If enabled KVM guest will be started when RouterOS boots. KVM guest cannot change
  • edit - edit selected value of KVM guest entry
  • enable - change KVM guest global state to enable operation of KVM guest. If guest where disabled before - KVM guest is automatically started.
  • export - Print or save an export script that can be used to restore configuration of current sub-menu, KVM guest configuration, image files will not be saved
  • find - Find items by value
  • get - Gets value of item's property
  • make-routeros-image - creates RouterOS image from current installation installed on the router with no configuration. It is advised to create Image file larger than minimal, so you are able to upload new package files and upgrade/update RouterOS installation. Also, all the additional files created in KVM guest will be stored in file image. This image file is not connected to host RouterOS and user is able to run different RouterOS versions on host and guest. This command will create RAW image file containing RouterOS installation.
  • pause - suspend operation of KVM guest
  • print - Print values of item properties
  • reboot - issue ACPI shut-down command to KVM guest, if guest does not support ACPI, command have no effect. After KVM guest is shut-downed it will be automatically started by host when shut down is complete.
  • reconfigure-routeros-image - sets up default configuration for RouterOS image.
  • remove - Remove item
  • set - Change item properties
  • shut-down - issue ACPI shut-down command to KVM guest, if guest does not support ACPI, command have no effect.
  • start - to start KVM guest

Creating KVM guest

To add new KVM guest you will have to issue command add under /kvm menu with attributes as follows:

  • comment - to add simple text description of the KVM guest
  • cpu-count - available count of processing cores for guest. Allowed values are [1..32]
  • disabled - to set guest state after creation, values: yes or no
  • disk-images - what files to use as virtual disks for KVM guest.
  • initrd - path to initrd file
  • kernel - path to kernel image file
  • kernel-cmdline - parameters that are passed to kernel, it is space separated string.
  • memory - to set up amount of memory that is available to KVM guest
  • name - name of KVM guest that it will be accessible though the system
  • copy-from - use configuration from already existing KVM guest


If kernel and initrd fields are left empty, KVM will use hosts kernel and initrd. This is dangerous if you are going to run different RouterOS version on host and guest and can break your system. Guests other than RouterOS can break if you leave these values empty.


Example:

 /kvm add comment="example kvm guest" cpu-count=2 disabled=no disk-images=hda:ros.img initrd=/boot/initrd.rgz \ 
 kernel=/boot/vmlinuz-smp kernel-cmdline="console=ttyS0" memory=128MiB name=ROS1

KVM guest interfaces

To add interface to KVM guest you have to go to /kvm interface menu and use command add with attributes:

  • comment - description of interface
  • disabled - state of interface after creation
  • host-mac-address - MAC address of virtual interface that host will see
  • model - mode of virtual interface. Available options are:
    • virtio - default value. Fastest available option, should be chosen if no other problems are encountered
    • e1000 - emulates card that uses e1000 driver. This option where added for compatibility with some guest operating systems that where not able to communicate with host RouterOS if virtio interface model where used.
    • pcnet - emulates card that uses pcnet driver. This option where added for compatibility with some guest operating systems that where not able to communicate with host RouterOS if virtio interface model where used.
  • vm-mac-address - MAC address of virtual interface that guest will see
  • copy-from - use configuration from existing virtual interface
  • dynamic-bridge - if set, dynamic interface will be automatically added as port to bridge interface
  • interface - is set for static interface, to assign it to created virtual-ethernet interface, already created under /interface virtual-ethernet
  • type - to set if interface is either static or dynamic. Dynamic interface will add entry to /interface virtual-ethernet automatically when virtual machine starts. Static interface have to have created entry in /interface virtual-ethernet menu at the time of creation of interface.
  • virtual-machine - name of virtual machine this interface will be assigned to


If static interface is added and no mac address is set, it is automatically generated and set. For static interface this address will not change during use of guest. MAC address of dynamic interface will change every time dynamic interface is created. Automatically generate MAC addresses will be in form of 02:XX:XX:XX:XX:XX

Add and remove interfaces only when KVM guest is shut-down, stopped or disabled. Making changes to running guest may lead to host system crash.

States of KVM guest

This field is read-only and is set by RouterOS. These are possible values that can be set:

  • stopped - KVM guest is not running, either successful shut-down or disabled.
  • stopping - KVM guest is shutting down
  • starting - KVM guest is starting
  • running - KVM guest has started successfully and is executing guest operating system
  • restarting - KVM guest is reloading its guest operating system
  • failed - KVM guest has encountered unknown error and is not operational.
  • image-busy - image file set in configuration is already in use by other KVM guest entry
  • no-kernel-or-initrd - initrd or kernel was not found in files set in configuration, mentioned files could not be found or no values in those fields where set
  • no-disk-image - either disk image was not found or disk image was not set in configuration.