Objective
The objective is of this article is explain how to automatically start virtual machine using default Redhat’s KVM based hyper-visor configuration.
Operating System and Software Versions
- Operating System: – Redhat 7.3
- Software: – libvirtd (libvirt) 2.0.0
Requirements
Privileged access to your Redhat Linux installation will be required.
Difficulty
EASY
Conventions
- # – requires given linux commands to be executed with root privileges either directly as a root user or by use of
sudo
command - $ – requires given linux commands to be executed as a regular non-privileged user
Instructions
List Available Virtual Machines
To start let’s list all available Virtual machines on our host system:
# virsh list --all Id Name State ---------------------------------------------------- - server.linuxconfig.org shut off
To check whether given virtual machine is already configured to start after host system’s boot run:
# virsh dominfo server.linuxconfig.org Id: - Name: server.linuxconfig.org UUID: df25d714-1c73-4b4a-b566-9d0a17295702 OS Type: hvm State: shut off CPU(s): 2 Max memory: 1048576 KiB Used memory: 1048576 KiB Persistent: yes Autostart: disable Managed save: no Security model: selinux Security DOI: 0
Furthermore, to list all virtual machines already configured to autostart run:
# ls /etc/libvirt/qemu/autostart/
Enable Virtual Machine automatic start
To enable the above KVM virtual machine to start automatically run the following linux command:
# virsh autostart server.linuxconfig.org Domain server.linuxconfig.org marked as autostarted
If virsh
command is not available/installed, to configure austostart simply create a new symbolic link within /etc/libvirt/qemu/autostart/
directory using ln
command. Example:
# ln -s /etc/libvirt/qemu/server.linuxconfig.org.xml /etc/libvirt/qemu/autostart/server.linuxconfig.org.xml
and reload hyper-visor if necessary:
# systemctl reload libvirtd
Confirm whether autostart is enabled:
# virsh dominfo server.linuxconfig.org Id: - Name: server.linuxconfig.org UUID: df25d714-1c73-4b4a-b566-9d0a17295702 OS Type: hvm State: shut off CPU(s): 2 Max memory: 1048576 KiB Used memory: 1048576 KiB Persistent: yes Autostart: enable Managed save: no Security model: selinux Security DOI: 0
Disable Virtual Machine autostart
To disable virtual machine autostart execute:
# virsh autostart --disable server.linuxconfig.org Domain server.linuxconfig.org unmarked as autostarted
or simply use unlink
command to remove virtual machine’s symbolic link from /etc/libvirt/qemu/autostart/
directory:
# unlink /etc/libvirt/qemu/autostart/server.linuxconfig.org.xml