This post records my experience using templates in Qubes OS 4.3 to organize and maintain a daily working environment, evolving from manual configuration to Salt management. The advanced part uses my own qubes-salt-config repository as an example.
What Is Qubes OS
Qubes OS is an operating system built on the principle of security through isolation. It uses Xen virtualization to create and manage multiple independent virtual machines (called qubes), following a “security by isolation” design.
This post is based on Qubes OS 4.3, with Debian 13 and Fedora 44 as the base templates, and covers project development, daily use and security research.
Structure:
- Part 1: Core concepts and architecture of Qubes OS
- Part 2: Manual template management in practice
- Part 3: Salt automation with
qubes-salt-config
Core Concepts
Template (template VM)
A template is a special type of VM in Qubes OS that contains an operating system’s root filesystem. Templates are mainly used to:
- Install and update system packages
- Serve as the base image for App Qubes
- Manage software dependencies centrally
According to the official documentation, the template design brings these advantages:
- Security: an App Qube has read-only access to its base template, so even if an App Qube is compromised, it can’t infect the template or other qubes based on it
- Storage efficiency: template-based qubes only store user data, saving a lot of disk space
- Fast creation: because the root filesystem already exists in the template, creating a new App Qube is quick
- Central updates: after updating the template, every qube based on it uses the update automatically after a restart
App Qube (application VM)
An App Qube is a VM created from a template and used to run everyday applications. Its characteristics:
- Inherits the template’s root filesystem (read-only)
- Has its own user directory (
/home) and persistent storage (/rw) - Any changes to the root filesystem are lost on shutdown
- Changes in
/home,/usr/localand/rw/configpersist
Disposable (disposable VM)
A Disposable is a temporary VM whose data is destroyed on shutdown. It’s suited to untrusted operations such as opening suspicious email attachments or browsing untrusted websites.
Dom0 (admin domain)
Dom0 is Qubes OS’s admin domain, running the Xen hypervisor and the Qubes management tools. Dom0 has no network access to maximize security.
Qubes OS Architecture
graph TB
Dom0["<b>Dom0 (admin domain)</b><br/>Xen Hypervisor + Qubes Manager"]
Dom0 --> SysNet["sys-net<br/>(NetVM)"]
Dom0 --> SysFirewall["sys-firewall<br/>(ProxyVM)"]
Dom0 --> SysUSB["sys-usb<br/>(USB VM)"]
Dom0 --> Templates["Templates<br/>(template VMs)"]
SysNet --> SysFirewall
SysFirewall --> AppQubes
Templates -->|read-only inheritance| AppQubes["<b>App Qubes (work domains)</b>"]
AppQubes -.-> Work["work"]
AppQubes -.-> Personal["personal"]
AppQubes -.-> Banking["banking"]
AppQubes -.-> Dev["dev"]
AppQubes -.-> Social["social"]
style Dom0 fill:#c92a2a,stroke:#ff6b6b,stroke-width:3px,color:#fff
style Templates fill:#1971c2,stroke:#4dabf7,stroke-width:2px,color:#fff
style AppQubes fill:#2f9e44,stroke:#51cf66,stroke-width:2px,color:#fff
style SysNet fill:#f59f00,stroke:#ffd43b,stroke-width:2px,color:#000
style SysFirewall fill:#f59f00,stroke:#ffd43b,stroke-width:2px,color:#000
style SysUSB fill:#f59f00,stroke:#ffd43b,stroke-width:2px,color:#000
Data Flow and Trust Boundaries
graph TB
subgraph High["High trust zone (Banking, Vault)"]
Banking["Banking"]
Vault["Vault"]
end
subgraph Medium["Medium trust zone (Work, Personal)"]
Work["Work"]
Personal["Personal"]
end
subgraph Low["Low trust zone (Random, Untrusted)"]
Random["Random"]
Untrusted["Untrusted"]
end
subgraph Network["Network zone (sys-net, sys-firewall)"]
SysNet["sys-net"]
SysFirewall["sys-firewall"]
end
Network <-->|strictly limited| Low
Low <-->|controlled data flow| Medium
Medium <-->|controlled data flow| High
SysNet --> SysFirewall
style High fill:#862e9c,stroke:#be4bdb,stroke-width:2px,color:#fff
style Medium fill:#1864ab,stroke:#339af0,stroke-width:2px,color:#fff
style Low fill:#d9480f,stroke:#ff6b6b,stroke-width:2px,color:#fff
style Network fill:#2f9e44,stroke:#51cf66,stroke-width:2px,color:#fff
Part 1: Template System Basics
Why Use Templates
On Qubes OS 4.3 I need to support several different work scenarios: project development, everyday entertainment and security research. The advantages of templates:
Centralized Management
- Package installation and updates happen once in the template
- Less duplicated configuration: set it up once, use it in many places
- Simpler maintenance and fewer mistakes
Security Isolation
- App Qubes for different purposes use different templates
- Limit the attack surface and prevent cross-infection
- Isolate working environments at different trust levels
Fast Deployment
- Create new App Qubes quickly from a configured template
- No need to install and configure software from scratch each time
- Good for testing and temporary tasks
Storage Efficiency
- Multiple App Qubes share the same template root filesystem
- Saves significant disk space
- Makes managing multiple work environments easier
Template Categories
Based on use case and security requirements, I split templates into these categories:
network-vpn Template
Purpose: Networking and VPN toolkit
Installed software:
- Tailscale: zero-config VPN built on the WireGuard protocol
- WireGuard: a modern, high-performance VPN protocol
- OpenVPN: the traditional VPN solution
- Network diagnostic tools such as tcpdump and wireshark
Base template: fedora-44
Why this base: Fedora ships NetworkManager, which makes managing OpenVPN, WireGuard and other VPN configurations easy; you can import and switch VPN profiles from the GUI or the command line
Security notes: This type of template is mainly for network isolation and encrypted communication; avoid unnecessary software to reduce the attack surface
dev Template
Purpose: Software development environment
Installed software:
- VSCode: Microsoft’s code editor
- Emacs: the extensible text editor
- Git: version control
- Compilers and development toolchains
- Docker CLI (if needed)
- Fcitx5: input method framework for Chinese, with Pinyin, Wubi and other input methods
Base template: debian-13
Why this base: Debian is stable and its package management is straightforward, making it a good base for development. Its repositories are comprehensive and dependencies are clear, which makes it well suited to building a reliable development environment
Security notes: A development environment may run third-party code; consider a separate App Qube per project
social Template
Purpose: Social and messaging apps
Installed software:
- Telegram Desktop: messaging app
- WeeChat: terminal IRC client
- Signal Desktop: end-to-end encrypted messaging
- Email client
- Fcitx5: Chinese input method framework for typing Chinese in chats
Base template: fedora-44
Security notes: Social apps receive untrusted content, so restrict their filesystem access strictly
gpg Template
Purpose: Encryption and key management (with Split GPG)
Installed software:
- GnuPG 2: OpenPGP encryption and signing tools
- Pinentry: passphrase entry dialog
- Key management tools
Base template: debian-13-minimal
Security notes: This is one of the most sensitive templates; keep it minimal and include only required components. Use Qubes Split GPG and keep private keys in an isolated Vault VM
tools Template
Purpose: Everyday tools and multimedia
Installed software:
- GIMP: image editor
- Inkscape: vector graphics editor
- LibreOffice: office suite
- Media players
Base template: fedora-44
Security notes: Multimedia software may process untrusted files; open files of unknown origin in an isolated App Qube
Part 2: Manual Template Management
Template Initialization
1. Install the Base Templates
Install the base templates you need in Dom0 with qvm-template:
# List available templates
qvm-template list --available
# Install the Fedora 44 templates
qvm-template install fedora-44
qvm-template install fedora-44-minimal
# Install the Debian 13 templates
qvm-template install debian-13
qvm-template install debian-13-minimal
2. Clone the Base Templates
To avoid modifying the official templates directly, clone them first:
# Clone Debian 13 as the development template
qvm-clone debian-13 tpl-dev
# Clone Fedora 44 as the network/VPN template
qvm-clone fedora-44 tpl-network-vpn
3. Configure the Template
Start the Template
qvm-start tpl-dev
Install Software in the Template
Using the dev template as an example:
# Open a terminal in the template from Dom0 (use whatever terminal the template has if xterm isn't installed)
qvm-run -u root tpl-dev -- xterm
Inside the template terminal:
# Update the system
sudo apt update && sudo apt upgrade -y
# Install development tools
sudo apt install -y git build-essential cmake emacs vim
# Install VSCode (Microsoft's official apt repository)
sudo apt install -y wget gpg
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | \
gpg --dearmor > /usr/share/keyrings/microsoft.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/microsoft.gpg] https://packages.microsoft.com/repos/code stable main" \
> /etc/apt/sources.list.d/vscode.list
sudo apt update
sudo apt install -y code
Clean Up and Shut Down
# Clean the package cache
sudo apt clean
# Shut down the template
qvm-shutdown tpl-dev
4. Create App Qubes from the Template
# Create the development App Qube
qvm-create -t tpl-dev -l blue dev-work
# Create the social App Qube
qvm-create -t tpl-social -l green social-personal
# Set up networking (through sys-firewall)
qvm-prefs dev-work netvm sys-firewall
5. Configure App Qube Settings
# Give the App Qube more memory
qvm-prefs dev-work memory 4096
qvm-prefs dev-work maxmem 4096
# Enable autostart
qvm-prefs dev-work autostart true
# Make it provide networking to other qubes (e.g. a VPN ProxyVM)
qvm-prefs vpn-proxy provides_network true
Template Updates and Maintenance
Routine Updates
Update All Templates
# Run in Dom0
qubes-update-gui
Or from the command line:
# Update the Debian templates
qvm-run -u root tpl-dev -- apt update && apt upgrade -y
qvm-run -u root debian-13 -- apt update && apt upgrade -y
# Update the Fedora templates
qvm-run -u root tpl-network-vpn -- dnf update -y
Template Upgrades
When a new template version is available:
# Install the new version (use the actual version number)
qvm-template install debian-13
# Clone the new template
qvm-clone debian-13 tpl-dev-new
# Reinstall software in the new template
# (see step 3 of the initialization flow)
# After testing, switch the App Qube to the new template
qvm-prefs dev-work template tpl-dev-new
# Restart the App Qube to apply the change
qvm-shutdown dev-work
qvm-start dev-work
# Once everything checks out, remove the old template
qvm-remove tpl-dev
Backing Up Template Configuration
Templates installed via RPM are “system managed” and can’t be backed up with Qubes’ built-in backup tool. Suggestions:
- Record the list of installed packages
- Back up configuration files
- Maintain a template configuration script
Example script:
#!/bin/bash
# save-template-config.sh
TEMPLATE_NAME="tpl-dev"
BACKUP_DIR="$HOME/template-configs"
mkdir -p "$BACKUP_DIR/$TEMPLATE_NAME"
# Export the list of installed packages
qvm-run -u root $TEMPLATE_NAME -- dpkg-query -W > "$BACKUP_DIR/$TEMPLATE_NAME/packages.txt"
# Back up important configuration files
qvm-run -u root $TEMPLATE_NAME -- tar czf /tmp/configs.tar.gz /etc/apt/sources.list.d /etc/profile.d
qvm-run $TEMPLATE_NAME -- cat /tmp/configs.tar.gz > "$BACKUP_DIR/$TEMPLATE_NAME/configs.tar.gz"
Part 3: Managing Templates with Salt
From Manual Management to a Repository
Managing a few templates with qvm-clone and qvm-prefs is fine, but it gets repetitive as templates multiply: every new environment means cloning, installing packages, changing prefs and configuring appmenus again, and upgrades repeat the whole thing. Qubes ships with Salt, which is a good fit for writing these steps as state files.
Salt in Qubes differs from regular SaltStack, though:
- dom0 is a minion with no master, so you use
qubesctlrather thansaltday to day. - Applying states to DomUs requires
--skip-dom0 --targets=<qube>; Qubes starts a temporary management DispVM to run them. - Custom pillars are fragile on dom0: Qubes’
topd/_topsmechanism may not pick up atop.slsyou put inpillar_root, and in bad cases it breaks pillar loading for the whole dom0.
I collected my template configuration into a repository: qubes-salt-config. It follows qusal’s layout, doesn’t use pillar, and keeps all non-sensitive configuration in salt/config.jinja. The rest of this section uses that repository as the example for moving template management onto Salt.
Salt Basics
| Concept | Meaning in Qubes |
|---|---|
| state | Describes what state a qube should be in: whether it exists, which template it uses, which packages are installed |
| SLS | Salt State file; usually one .sls file per state |
| top | Binds states to targets, e.g. “run templates.dev.create on dom0” |
qubesctl |
Qubes’ wrapper around Salt, replacing salt-call --local |
| management DispVM | A qube created temporarily to apply DomU states and destroyed afterwards |
A few common commands:
# Show what the state would do without applying it
sudo qubesctl state.apply templates.dev.create test=True
# Apply on dom0
sudo qubesctl state.apply templates.dev.create
# Apply on the given DomU
sudo qubesctl --skip-dom0 --targets=tpl-dev state.apply templates.dev.install
# Show the expanded contents of an SLS
sudo qubesctl state.show_sls templates.dev.create
Repository Layout
qubes-salt-config/
├── docs/ # install, deploy-checklist, dev-deploy, mirror
├── minion.d/slchris.conf # dom0 file_roots, pointing at /srv/salt/slchris
├── salt/
│ ├── config.jinja # single configuration entry point (no pillar)
│ ├── config.local.jinja.example
│ ├── debian-minimal/ # clone/create for the Debian base template
│ ├── fedora-minimal/ # Fedora base template
│ ├── templates/
│ │ ├── dev/ # development: tpl-dev, dvm-dev, dev
│ │ ├── media/ # multimedia
│ │ ├── im/ # instant messaging
│ │ ├── tools/ # common tools
│ │ ├── gpg/ # offline GPG
│ │ ├── vault/ # offline password vault
│ │ ├── vpn/ # VPN gateway
│ │ ├── project-net/ # per-project WireGuard gateways
│ │ └── gentoo-dev/ # Gentoo development environment
│ ├── mgmt/ # management DispVM, mirrors, remote-debug
│ └── utils/macros/ # clone_template, sync_appmenus, policy
├── scripts/
│ ├── setup.sh # deploy salt/ and minion.d/ to dom0
│ ├── package.sh # build the deployment tarball
│ ├── lint.sh # yamllint + salt-lint
│ └── check_top_pairing.py # check that .sls and .top files are paired
└── .github/workflows/ # lint, upstream version pin checks, magpie bump
Installation
Clone the repository in a networked DomU first, then pass it into dom0 with qvm-run --pass-io. Don’t copy files of unknown origin straight into dom0.
# DomU
git clone https://github.com/slchris/qubes-salt-config.git ~/qubes-salt-config
# dom0: stream the repository out of the qube
qube="YOUR_QUBE"
mkdir -p ~/QubesIncoming/"${qube}"
qvm-run --no-gui --pass-io -- "${qube}" "tar -cf - -C ~ qubes-salt-config" | \
tar -xf - -C ~/QubesIncoming/"${qube}"
cd ~/QubesIncoming/"${qube}"/qubes-salt-config
sudo ./scripts/setup.sh
setup.sh does three things:
- Copies
minion.d/slchris.confto/etc/salt/minion.d/and adds/srv/salt/slchristofile_roots. - Copies
salt/to/srv/salt/slchris/. - Removes any
/srv/pillar/slchrisleft by an older version, then runssaltutil.sync_all.
After installing, confirm the config is there:
ls /srv/salt/slchris/config.jinja
Next install the base templates. Check that the minimal templates exist first — the order matters because later templates depend on them:
# dom0: check the base templates and install any that are missing
qvm-check debian-13-minimal || sudo qubes-dom0-update --clean qubes-template-debian-13-minimal
qvm-check fedora-44-minimal || sudo qubes-dom0-update --clean qubes-template-fedora-44-minimal
sudo qubesctl state.apply debian-minimal.clone
sudo qubesctl state.apply fedora-minimal.clone
sudo qubesctl state.apply debian-minimal.create
sudo qubesctl state.apply fedora-minimal.create
Then install the management environment. Without this step, qubesctl --skip-dom0 --targets=... fails:
sudo qubesctl state.apply mgmt.create
sudo qubesctl --skip-dom0 --targets=tpl-mgmt state.apply mgmt.install
Configuration: Why No Pillar
Regular Salt usually keeps configuration in pillars, but this repository deliberately doesn’t. The reasons are in the comments of minion.d/slchris.conf and config.jinja:
Qubes dom0’s support for custom pillars isn’t reliable. A plain
top.slsplaced in a custompillar_rootmay not be registered by Qubes’topd/_topsmechanism, and in bad cases it breaks pillar loading for the whole dom0.
So all non-sensitive configuration lives in salt/config.jinja, and state files import it directly:
{% from 'config.jinja' import cfg with context %}
{{ cfg.qvm.debian.version }}
{{ cfg.mirror.enabled }}
Common settings:
cfg.qvm.debian.version/cfg.qvm.fedora.version: base template versions; change them when upgrading.cfg.mirror.enabled: whether to point Qubes template downloads at a mirror.cfg.remote_debug.*: the qube, SSH port, allowed subnets and public keys used for remote debugging.cfg.mgmt.*: settings for the management DispVM.
Machine-specific configuration goes in salt/config.local.jinja; this file is ignored by .gitignore and package.sh doesn’t include it. Example:
{% set _ = cfg['hotspot'].update({'password': ''}) %}
Don’t put tokens or passwords for AppVMs in
config.jinja. That file is rendered in dom0, so anything you write there is plaintext on dom0. Application-side secrets belong in a separate sops repository and are decrypted inside the AppVM;config.jinjaonly holds configuration dom0 needs to know.
After changing the configuration, redeploy and sync:
sudo ./scripts/setup.sh
sudo qubesctl saltutil.sync_all
Template Examples
Templates already provided in the repository:
| Template | Base | Qubes created | Notes |
|---|---|---|---|
dev |
debian-13-minimal | tpl-dev, dvm-dev, dev | Development environment |
media |
debian-13-minimal | tpl-media, dvm-media | Multimedia playback |
im |
debian-13-minimal | tpl-im, im | Instant messaging |
tools |
debian-13-minimal | tpl-tools, dvm-tools | Common tools |
gpg |
debian-13-minimal | tpl-gpg, gpg | Offline GPG |
vault |
debian-13-minimal | tpl-vault, vault | Offline password vault |
vpn |
fedora-44-minimal | tpl-vpn, sys-vpn | VPN gateway |
project-net |
debian-13-minimal | tpl-project-net, sys-project-net | Per-project WireGuard gateway |
gentoo-dev |
gentoo-xfce | tpl-gentoo-dev, gentoo-dev | Gentoo development |
The dev template in the manual example above uses Fedora; the repository’s
devis based on Debian 13-minimal and installs packages withapt. You can change the base template to suit your habits; the state structure stays the same.
Create the development environment:
sudo qubesctl state.apply templates.dev.create
sudo qubesctl --skip-dom0 --targets=tpl-dev state.apply templates.dev.install
sudo qubesctl --skip-dom0 --targets=dev state.apply templates.dev.configure
GPG and vault are offline, so their states set netvm to empty:
sudo qubesctl state.apply templates.gpg.create
sudo qubesctl --skip-dom0 --targets=tpl-gpg state.apply templates.gpg.install
sudo qubesctl state.apply templates.vault.create
sudo qubesctl --skip-dom0 --targets=tpl-vault state.apply templates.vault.install
VPN gateway:
sudo qubesctl state.apply templates.vpn.create
sudo qubesctl --skip-dom0 --targets=tpl-vpn state.apply templates.vpn.install
sudo qubesctl --skip-dom0 --targets=sys-vpn state.apply templates.vpn.configure
Writing Your Own Template
Using templates/dev as an example, the directory usually contains these files:
salt/templates/dev/
├── clone.sls # clone tpl-dev from debian-minimal
├── create.sls # create tpl-dev, dvm-dev, dev
├── create.top # bind create.sls to dom0
├── install.sls # install packages in tpl-dev
├── install.top # bind install.sls to tpl-dev
├── configure.sls # configure dev/dvm-dev
└── configure.top
clone.sls uses the clone_template macro to clone the base template as tpl-dev:
{% from 'utils/macros/clone-template.sls' import clone_template -%}
{% set name = slsdotpath.split('.')[-1] -%}
{{ clone_template('debian-minimal', name) }}
create.sls uses slsdotpath and load_yaml to generate qubes. slsdotpath is the path of the current state — here templates.dev — so taking the last segment for name gives dev:
{%- from "qvm/template.jinja" import load -%}
{% set name = slsdotpath.split('.')[-1] %}
{% load_yaml as defaults -%}
name: tpl-{{ name }}
force: True
require:
- sls: {{ slsdotpath }}.clone
prefs:
- label: green
- vcpus: 4
- memory: 400
- maxmem: 8000
{%- endload %}
{{ load(defaults) }}
create.top binds the state to dom0:
base:
'dom0':
- match: nodegroup
- templates.dev.create
install.top binds it to the template:
base:
'tpl-dev':
- templates.dev.install
To add a template, copy a directory, change the name, base template, package list and prefs, then run the repository’s checks:
./scripts/lint.sh
python3 scripts/check_top_pairing.py
Development and Updates
You don’t need to git clone every time you change configuration. The repository offers two workflows:
Edit in a DomU and push to dom0: suited to releases; docs/install.md has the full steps.
Local development loop: edit on your development machine, package with scripts/package.sh, serve over LAN HTTP to a transfer qube, then copy into dom0. docs/dev-deploy.md has the details:
# development machine
./scripts/package.sh dev
cd dist && python3 -m http.server 8000
# transfer qube
wget http://<dev-ip>:8000/qubes-salt-config-dev.tar.gz
tar -xzf qubes-salt-config-dev.tar.gz
# dom0
qvm-run --no-gui --pass-io -- "dev" "tar -cf - -C ~ qubes-salt-config" | \
tar -xf - -C ~/QubesIncoming/dev
cd ~/QubesIncoming/dev/qubes-salt-config
sudo ./scripts/setup.sh
When updating templates, change the version in salt/config.jinja first, then re-run the corresponding create state. Rename the old template with an -old suffix first, and delete it once the new one checks out:
sudo qubesctl state.apply templates.dev.create
sudo qubesctl --skip-dom0 --targets=tpl-dev state.apply templates.dev.install
The complete upgrade steps are in the Template Upgrade section of docs/install.md.
Troubleshooting
state.apply can’t find the state: make sure setup.sh has run and the matching .sls exists under /srv/salt/slchris/. minion.d/slchris.conf only adds /srv/salt/slchris to file_roots, so you don’t need the slchris. prefix when calling states.
--skip-dom0 fails: confirm that mgmt.create and mgmt.install on tpl-mgmt have both run. Qubes needs the management DispVM to apply states inside a DomU.
Pillar-related errors: this repository doesn’t use pillar. If you’re upgrading from an older version, setup.sh removes /srv/pillar/slchris; don’t manually create another top.sls there.
Slow template downloads: docs/mirror.md explains how to point Qubes template downloads at a mirror, and you can also use scripts/qubes-mirror.sh. This is optional and doesn’t affect Salt itself.
Preview what a state will do:
sudo qubesctl state.apply templates.dev.create test=True
sudo qubesctl state.show_sls templates.dev.create
sudo qubesctl --skip-dom0 --targets=tpl-dev state.apply templates.dev.install test=True
Summary
Qubes OS’s template system separates the “root filesystem” from “user data”: templates are read-only, App Qubes writable. That’s the foundation of isolation and fast creation. Managing a few templates manually is fine, but once you have many, Salt is the way.
The path in this post:
- Understand how templates, App Qubes, Disposables and Dom0 relate.
- Plan templates by purpose and trust level; don’t mix development, social and GPG in one template.
- Get one template working manually with
qvm-cloneandqvm-prefs, and confirm the software and configuration are right. - Write the same steps as Salt states; as templates grow, manage them as a repository like
qubes-salt-config, with configuration, templates, policy and deployment scripts all in Git. - When upgrading, change the version in the config, re-run the states, and verify the new template before deleting the old one.
Comments