Automatically restart a qube on stop

Introduction

The point of this tutorial is to make Qubes OS automatically restart a given qube if it stops, this can be useful for a crashing sys-usb for instance.

The guide uses sys-usb as an example.

Explanation

This looks for the pid file of qubesdb in /run/qubes/qubesdb.QUBE_NAME.pid, if that file changes (which is the case on deletion), it runs qvm-start to run it again.

Note that this can’t start the qube the first time, but it should not be a problem as Qubes OS handles this when you check “automatically start this qube on boot”.

Implementation

In dom0 create /etc/systemd/system/always-on-qube.path

[Path]
PathChanged=/run/qubes/qubesdb.sys-usb.pid

[Install]
WantedBy=multi-user.target

Create /etc/systemd/system/always-on-qube.service

[Service]
ExecStart=-/usr/bin/qvm-start sys-usb
Type=oneshot

Start the listener and make it the default at boot time:

systemctl enable --now always-on-qube.path
4 Likes