1

I have an Ubuntu server running xen (with xen-tools only) and when the server experiences a power failure I have to manually run xl create /etc/xen/MY_DOMU_GUEST.cfg to restart the vm.

My config settings for restarting look like this:

/etc/xen/MY_DOMU_GUEST.cfg:

on_poweroff = 'restart'
on_reboot   = 'restart'
on_crash    = 'restart'

But it doesn't start on dom0 boot. Am I missing something?

2 Answers 2

4

I found the answer here: https://askubuntu.com/questions/196444/how-do-i-auto-start-xen-guests-on-boot/906499#906499

The Short Answer

To load all config files on boot link the auto folder directly to /etc/xen:

ln -s /etc/xen/ /etc/xen/auto

To load only specific config files link each individually:

mkdir -p /etc/xen/auto
ln -s /etc/xen/MY_DOMU_GUEST_1.cfg /etc/xen/auto/
ln -s /etc/xen/MY_DOMU_GUEST_2.cfg /etc/xen/auto/

Explanation

There's a lesser-known xen config file /etc/default/xendomains.

There you can find in the comments documentation for three default settings:

XENDOMAINS_SAVE=/var/lib/xen/save
XENDOMAINS_RESTORE=true
XENDOMAINS_AUTO=/etc/xen/auto

To summarize the docs:

  • XENDOMAINS_SAVE causes the VMs to be saved on a proper reboot.

  • XENDOMAINS_RESTORE causes the VMs to be brought back up from the saved state when saved (whether saved manually with xl save or due to host reboot).

  • XENDOMAINS_AUTO specifies a folder from which to load configs for VMs when no save state exists (i.e. XENDOMAINS_SAVE is disabled or there was a power failure or explicit shutdown instead of a reboot)

If you create the auto folder under /etc/xen and give it symlinks to the config file of the virtual machine (DomU guest) you'd like to start on physical machine (Dom0 host) then generally speaking they'll restore from the saved state that happens during the physical (host) server on reboot, but when that isn't available (such as after a shutdown or power failure or crash), they'll still load anyway.

If you'd rather always have the VMs shutdown on reboot rather than save state you can set XENDOMAINS_SAVE= and XENDOMAINS_RESTORE=false.

The Old Way

It used to be that where there is now on_shutdown, on_reboot, and on_crash that you could also configure on_xend_start = 'start' and on_xend_stop = 'shutdown'... but those are not the current practice.

Current (apply to the VM state itself):

on_shutdown = 'destroy'
on_reboot = 'restart'
on_crash = 'restart'

Ignored / Deprecated (apply to the host state):

on_xend_start = 'start'
on_xend_stop = 'shutdown'
1
0

I know this is old post but there is an easier way.

Create a script MyScripNameHere.sh in this script add the following syntax, and add appropriate permissions to execute as root.

#!/bin/bash

export PATH=/opt/xensource/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr

sleep 60

xe vm-start vm="VMNAMEHERE1"

sleep 5

xe vm-start vm="VMNAMEHERE2"

Then add the path to the script in rc.local , however before execution add sleep 60 This will autostart all the VM in the script list. This is if you do not want to deal with UUID or pooling.

1
  • I'd argue that creating symlinks where xen expects them is, in fact, easier than creating an rc file with sleeps.
    – coolaj86
    Jun 23, 2020 at 6:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .