9. Automatic Startup and Shutdown

9.1. Hypervisor Host autologin

If you want to enable automatic login to the Hypervisor Host after booting has finished, follow the next steps.

sudo -e mousepad /usr/share/lightdm/lightdm.conf.d/60-lightdm-gtk-greeter.conf
# autologin-settings to be appended in Section [Seat:*]
autologin-user=insert_your_username_here
autologin-user-timeout=0

9.2. Automatic guest startup

9.2.1. Enable autostart

In this section we will show how one or multiple guests can be started automatically after the Hypervisor has finished booting.

9.2.1.1. Introduction

To automatically start guests after the hypervisor finished booting, you need to adjust the /hv/config/usr_guest_autostart.config file.

mousepad /hv/config/usr_guest_autostart.config

All guests that shall be started automatically have to be included here by inserting their respective guest foldername. The following example configuration will automatically start 4 guests, located in the folders guest0001 to guest0004.

/hv/guests/guest0001
/hv/guests/guest0002
/hv/guests/guest0003
/hv/guests/guest0004

The configuration settings will only become effective after running the command hv_set_autostart. This command requires the hypervisor root configuration file name as parameter. The root configuration file used by the System Manager and the examples is located in /hv/config/hv.config.

hv_set_autostart -enable /hv/config/hv.config

Hint

This command will copy, rename and adjust the hv_guest_autostart.service template located in the guest folders into the /hv/services/hv_guest_autostart-GUEST.service (where GUEST is the guest foldername).
Then it will enable a respective systemd service located in /etc/systemd/system.
This service will automatically start the guest after booting the system.

Caution

If you change the settings in usr_guest_autostart.config you need to first disable the autostart configuration and then re-enable the new configuration:

hv_set_autostart -disable
hv_set_autostart -enable /hv/config/hv.config

9.2.1.2. Automatic startup of example guests (RT-Linux)

Hint

Initially, the Hypervisor Host does not provide any example guest folders. To switch to the RT-Linux guest example, you need to perform the suitable initialization. For instructions on initializing the examples, please see the RTOS Guests chapter in the Hypervisor Manual.

hv_open_example rt-linux
hv_sync_example rt-linux
cd /hv/guests/guestrtlinux

Uncomment the line /hv/guests/guestrtlinux show_console in usr_guest_autostart.config to automatically configure starting the example RT-Linux guest. You may also uncomment the line /hv/guests/guestwindows show_console to automatically configure starting the example virtual KVM guest (e.g. Windows or Ubuntu). In this case, you should initialize the associated example.

;###################################################
; user specific guest autostart configuration script
;###################################################

; autostart example RT-Linux guest
; if guest console shall be shown automatically, use parameter show_console
/hv/guests/guestrtlinux show_console

; autostart example Windows guest
; if guest console shall be shown automatically, use parameter show_console
/hv/guests/guestwindows show_console

; autostart example Ubuntu guest
; if guest console shall be shown automatically, use parameter show_console
; /hv/guests/guestubuntu show_console

; autostart system manager created guests (to be removed if system manager supports autostart handling)
; if guest console shall be shown automatically, use parameter show_console

Then enable autostart:

hv_set_autostart -enable /hv/config/hv.config

9.2.1.3. Automatic startup of System Manager managed guests

Currently, the System Manager does not support setting autostart configuration from within the GUI. It is required to add additional lines /hv/guests/guestXXXX show_console in usr_guest_autostart.config to automatically configure starting System Manager generated guests.

;###################################################
; user specific guest autostart configuration script
;###################################################

; autostart example RT-Linux guest
; if guest console shall be shown automatically, use parameter show_console
/hv/guests/guestrtlinux show_console

; autostart example Windows guest
; if guest console shall be shown automatically, use parameter show_console
/hv/guests/guestwindows show_console

; autostart example Ubuntu guest
; if guest console shall be shown automatically, use parameter show_console
; /hv/guests/guestubuntu show_console

; autostart system manager created guests (to be removed if system manager supports autostart handling)
; if guest console shall be shown automatically, use parameter show_console
/hv/guests/guest0001
/hv/guests/guest0002

When enabling autostart, the /hv/config/hv.config file needs to be used:

hv_set_autostart -enable /hv/config/hv.config

9.2.1.4. Standard console mode

The show_console parameter following the guest foldername will automatically launch a console window to the guest when logging in into the Hypervisor Host.

The following example configuration will automatically start 3 guests, located in the folder guest0001 to guest0003. A console window will be displayed for guest 1 and 3.

/hv/guests/guest0001 show_console
/hv/guests/guest0002
/hv/guests/guest0003 show_console

Hint

Here, the hv_guest_autostart_xfce.sh template will also be copied, renamed and adjusted into /hv/services/hv_guest_autostart_xfce-GUEST.sh.
When rebooting and after logging in, the Hypervisor will read the autostart.desktop file located in the home folder in ~/.config/autostart. This file points to a script file /hv/bin/xfce-hv_autostart.sh which launches all console windows that are configured in usr_guest_autostart.config.

9.2.1.5. Standalone console mode

The standalone_console parameter following the guest foldername will automatically launch a full screen console window to the guest when logging in into the Hypervisor Host.

The following example configuration will automatically start 3 guests, located in the folder guest0001 to guest0003. A full screen console window will be displayed for guest 3.

/hv/guests/guest0001
/hv/guests/guest0002
/hv/guests/guest0003 standalone_console
By default, the monitor/display is configured to never turn off.
This can be adjusted by editing the script /hv/bin/guest_autostart_standalone_dispconf.sh and commenting out the respective commands.
# disable DPMS (Energy Star) features
# sudo xset -dpms >>$HV_BIN/guest_autostart_standalone_dispconf.log 2>&1

# turn off screen saver
# sudo xset s off >>$HV_BIN/guest_autostart_standalone_dispconf.log 2>&1

Caution

You should disable the Hypervisor Host desktop to assure the standalone console mode works properly. See section Disable Hypervisor Host desktop how to disable the Hypervisor Host desktop.

Caution

In the current RTOSVisor version, the standalone_console only works for the guest which is started last.

Caution

The standalone_console must not be used in conjunction with graphics passthrough.

Hint

This command will copy, rename and adjust the hv_guest_autostart_standalone.service template located in the guest folders into the /hv/services/hv_guest_autostart_standalone-GUEST.service (where GUEST is the guest foldername).
Then it will enable a respective systemd service located in /etc/systemd/system.
This service will automatically start the guest after booting the system.

Caution

Only one single KVM guest (no RTOS guest) can use the standalone console. Furthermore, if one guest is using the standalone console, no other guests can use the standard console anymore.

9.2.2. Disable autostart

To disable automatic start of guests, run the command

hv_set_autostart -disable

A complete reset of the autostart configuration can be done using the following command (it will not change the configuration settings in usr_guest_autostart.config):

hv_set_autostart -reset

9.2.3. Verify autostart

To show the current autostart configuration, run the command

hv_set_autostart -show

9.3. Hypervisor Host services

The hypervisor is using systemd services to automatically start guests, drivers etc. All services are located in the /hv/services folder. Active services will have a link set in /etc/systemd/system which point to the respective service file in /hv/services

The following services exist:

hv_initial_cleanup.service      - run initial cleanup tasks (e.g. in case of a non graceful shutdown)
hv_netif_restore.service        - restore network settings after reboot (in case KVM guests were not graceful shutdown)
hv_system_observer.service      - handles graceful system shutdown or reboot
hv_diskshare_observer.service   - support for dynamic disk forwarding to KVM guests (e.g. USB sticks)
hv_sysmgr.service               - start the graphical System Manager web server backend
hv_loaddriver.service           - load the basic hypervisor drivers
hv_part.service                 - hypervisor partitioning, e.g. assigns PCI Ethernet Cards to a RTOS
hv_ifup_vnet0.service           - bring up the virtual network device
hv_usbip_expose.service         - expose USB devices to Real-time guests
hv_vmf_autostart.service        - start the Virtual Machine Framework (the RTOS-VM Hypervisor) and load the hypervisor configuration
hv_guest_autostartXxxx.service  - start one specific guest

9.4. Autostart RT-Linux Applications

Automatic startup of RT-Linux applications is configured in the guest.config file located in the guest folder (section [Rtos\Autostart\1]). By default automatic start is enabled.

If this autostart section is active, the autostart script autostart.sh will be executed after RT-Linux has booted. This file is located in the files subfolder of the guest folder.

You may adjust both files according to your needs.

9.5. System Shutdown and Power-off/Reboot

When the system shall be powered off or rebooted, it is required to savely shutdown all guests before. Every time when a power off or reboot sequence is initiated, the Hypervisor host will assure that before it is shutting down, all the guests will be terminated first. This is handled by the hv_system_observer.service service which calls the hv_observer command to manage the system termination sequence.

Hint

Whenever the guest is started, the script /hv/bin/observer.sh is executed which will then wait for the guest to terminate.

Hint

For each KVM guest, a timeout value can be configured in usr_guest_config.sh. If the guest does not gracefully terminate it will be forcibly terminated, if the timeout elapsed.

cd /hv/guests/guestxxxx
mousepad usr_guest_config.sh

Adjust or add the following line:

export shutdown_timeout=900

9.5.1. Manual power-off/reboot

You can initiate rebooting or powering off the System by means of the Hypervisor host. For example running the following commands:

sudo shutdown -h 0
# or
sudo reboot

This will implicitely call the hv_shutdown command.

You can also directly call this command to power off the system:

hv_shutdown
# or
hv_shutdown --reboot

Alternatively, you can use the Hypervisor GUI to shutdown or reboot the system. This will also implicitely call the hv_shutdown command.

9.5.2. Reboot/shutdown initiated by Windows KVM guests

In this section we will show how the whole system can be rebooted or shutdown from within a Windows guest:

  • Start the Windows guest

  • Open the Explorer

  • Switch to folder \\10.0.2.4\qemu\files\WinTools\DesktopShortcuts

  • Copy all the shortcuts onto your desktop (you may have to adjust the shortcuts based on your Windows version and language)

  • Run the “System Shutdown” or “System Reboot” shortcut

Hint

To avoid being asked to allow execution, you may adjust the related Windows settings.

Open the Control Panel, select Internet Options, select security, select local intranet, select sites, select advanced and add \\10.0.2.4\qemu

9.5.3. Reboot/shutdown initiated by Linux KVM guests

There are multiple scripts available to either reboot or shut down the Linux guest or the entire system from within a Linux guest itself.

  • hv_linux_reboot: Reboot the Linux guest

  • hv_linux_shutdown: Shutdown the Linux guest

  • hv_system_reboot: Reboot the Hypervisor Host

  • hv_system_shutdown: Shutdown the Hypervisor Host

Hint

The scripts for system reboot or shutdown utilize a file share within QEMU.
This file share is established by installing the RTOS Communication Support on the Linux guest system.
You will need sudo privileges to use these scripts.
Refer to the Hypervisor - Ubuntu Guest Guide chapter RTOS Communication Support for installation instructions.

9.5.4. Reboot/shutdown initiated by RTOS guests

To initiate a reboot or shutdown sequence, respective files have to be created in the /hv/guests/files folder. Once the shutdown service recognize these files, they will shutdown all guests and finally reboot or shutdown the whole system. Within a Real-time Linux guest, this folder is located in /mnt/rtfiles/files.

  • Initiate system reboot: Create the /hv/guests/files/system_doreboot with arbitrary content.

  • Initiate system shutdown: Create the /hv/guests/files/system_doshutdown with arbitrary content.

9.5.5. Shutdown hooks

The Hypervisor provides a flexible hook mechanism to execute custom scripts at both the guest and system levels during shutdown or reboot sequences. Hooks are invoked at defined stages (pre- and post-termination) to allow graceful cleanup, logging, or any other custom tasks.

9.5.5.1. Invocation methods

Shutdown and reboot requests can originate from various sources:

  • Power button Pressing the PC’s power button sends an ACPI event, handled by the hv_shutdown.service unit.

  • GUI Selecting “Shutdown” or “Reboot” in the Hypervisor Host desktop also calls the same hv_shutdown logic.

  • Command line

    # Standard Linux commands
    sudo shutdown -h now
    sudo reboot
    
    # Direct hypervisor script
    hv_shutdown
    hv_shutdown --reboot
    
  • Guest request A Real-time or KVM guest can request a host shutdown or reboot by creating one of the following trigger files in /hv/guests/files:

    • /hv/guests/files/system_doshutdown

    • /hv/guests/files/system_doreboot

    The shutdown service watches for these files and will terminate all guests before powering off or rebooting.

9.5.5.2. Guest-level hooks

When an individual guest (KVM or RTOS) terminates, it can run a per-guest hook script vm_shutdown_hook.sh located in the guest’s directory. This script is called twice:

# Before guest process exits
vm_shutdown_hook.sh --pre_termination <shutdown_flag> <reboot_flag>

# After guest has fully stopped
vm_shutdown_hook.sh --post_termination <shutdown_flag> <reboot_flag>
  • <shutdown_flag> is 1 if the host is shutting down.

  • <reboot_flag> is 1 if the host is rebooting.

Use pre-termination to quiesce in-guest services or save state, and post-termination to collect logs or free resources. You can modify or replace vm_shutdown_hook.sh in each guest folder to suit your cleanup needs.

9.5.5.3. System-level hooks

For host-wide shutdown or reboot, the script system_init_shutdown_hook.sh in $HV_BIN is invoked at these points:

  1. Initialization (system boot)

    system_init_shutdown_hook.sh --start_system
    
  2. shutdown/reboot/terminate

    system_init_shutdown_hook.sh --shutdown
    

Use these hooks to restore network interfaces, archive logs, notify external systems, or perform any host-level cleanup before and after the entire shutdown/reboot sequence.