- Packages required: kvm system
- Applies to: v3.28< , v4
- Architecture: x86
Kernel-based Virtual Machine provides visualization on x86 RouterOS. It provides full virtualization to allow run multiple operating systems as guests on RouterOS host.
KVM requires CPU virtualization support in form of Intel VT-x and 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 when created and its size be equal to one you entered in creation process of image.
All KVM related configuration is done under /kvm menu in console. Available menus for KVM guest configuration are:
- /kvm interface
- 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
- 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.
- reconfigure-routeros-image - sets up default configuration for RouterOS image.
- remove - Remove item
- set - Change item properties
- shut-down - issues 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
/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="" memory=128MiB name=ROS1
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 mode 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 mode 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.
States of KVM guest
These values can be set as status messages for state field. This field is set by RouterOS and can only be read.
- 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.