OpenWrt package for Headscale (an open-source, self-hosted implementation of the Tailscale control server).
Companion Web UI: For full LuCI web management (Overview, Settings, Nodes, Users, Pre-Auth Keys, ACL Policy, Live Logs, Client Onboarding Guide, and Flash Protection status), install
luci-app-headscalealongside this package.
- Native OpenWrt Lifecycle: Managed by OpenWrt
procd(START=90,STOP=10) and standard UCI configuration (/etc/config/headscale). - Dynamic Runtime Configuration: Generates
/var/etc/headscale/config.yamland captures daemon logs in/var/log/headscale/headscale.log(both intmpfsRAM) with an/etc/headscale/config.yamlsymlink for seamlessheadscaleCLI usage. - Smart Storage Media Auto-Detection & Flash Protection: Automatically probes the hardware storage backing
database.sqlite_pathand switches between Aggressive RAM Mode (for raw flash / SD cards) and Direct Disk I/O Mode (for eMMC / USB / SSD / HDD). - Sysupgrade Persistence: Preserves
/etc/config/headscale, ACL policies, SQLite database, and private keys (noise_private.key,derp_server_private.key) viaconffiles.
Headscale continuously updates its SQLite database (last_seen node heartbeats, ephemeral timeouts, WAL frames). On routers without hardware wear-leveling, frequent synchronous writes can accelerate flash degradation.
/usr/share/headscale/headscale.sh automatically resolves the real physical storage device behind headscale.database.sqlite_path (traversing OpenWrt overlayfs upperdir mounts and /dev/loop* backing files via /proc/mounts and /sys/block) and applies the appropriate strategy when storage_mode is set to auto (default):
| Detected Storage Media | Detection Signals | Default (auto) Behavior |
|---|---|---|
| Embedded Raw Flash | ubifs, jffs2, /dev/ubi*, /dev/mtdblock*, sysfs /mtd/ or /ubi/ |
Aggressive RAM Mode |
| TF / SD Card | /dev/mmcblk* with device/type == SD |
Aggressive RAM Mode |
| RAM Disk | tmpfs, ramfs |
Aggressive RAM Mode |
| Built-in eMMC | /dev/mmcblk* with device/type == MMC |
Direct Disk I/O Mode |
| USB Storage | /dev/sd* backed by a /usb sysfs path |
Direct Disk I/O Mode |
| HDD / SSD / NVMe / VM Disk | nvme*, non-USB sd*, vd*, hd*, xvd* |
Direct Disk I/O Mode |
- Zero Everyday Flash Writes: On startup, the persistent database (
sqlite_path, default/etc/headscale/db.sqlite) is staged into/tmp/headscale/db.sqlite(tmpfs), and Headscale runs strictly against the in-memory database. - Atomic Persistence with
.bakSnapshot:- On clean stop, restart, or reboot (
service_stopped()waits untilprocd_killfinishes shutting down Headscale and checkpointing SQLite WAL),/tmp/headscale/db.sqliteis hashed/compared (cmp -s), written to${sqlite_path}.tmp, synced, rotated over${sqlite_path}.bak, and atomically moved intosqlite_path. Unchanged databases perform zero flash writes. - Manual or admin-triggered snapshots via
/etc/init.d/headscale sync_dbusesqlite3 .backupwhensqlite3is installed, or perform a fast clean WAL-checkpoint quiesce cycle whensqlite3is absent. - When paired with
luci-app-headscale, administrative mutations (creating/deleting users, pre-auth keys, or modifying/deleting nodes) automatically triggersync_dbso structural changes survive sudden power loss.
- On clean stop, restart, or reboot (
luci-app-headscale (+headscale) builds directly on top of this package:
- Calls
/usr/share/headscale/headscale.sh probeto display live detected storage media, active mode, and sync state in the Overview and Settings → Database & Storage views. - Calls
/etc/init.d/headscale sync_dbfor one-click manual sync and automatic post-mutation persistence.
- Supported:
x86_64,aarch64_generic,aarch64_cortex-a53(OpenWrt 24.10.ipk& OpenWrt 25.12+.apkprebuilt in Releases). - Not Supported (
mips/mipsel, e.g.,mipsel_24kc/ MT7621): Upstream Headscale0.29.xrelies onmodernc.org/libc(pure-Go SQLite), which does not support 32-bitlinux/mipsle. Devices based onmips/mipselcannot compile or run this package.
-
Add both this package and
luci-app-headscale(optional Web UI) into your OpenWrt buildroot:cd /path/to/openwrt git clone https://github.com/permails/openwrt-headscale.git package/headscale git clone https://github.com/permails/luci-app-headscale.git package/luci-app-headscale -
Update feeds and install dependencies:
./scripts/feeds update -a ./scripts/feeds install -a
-
Select the package(s) in
menuconfig:Network -> VPN -> headscale(<*>)LuCI -> 3. Applications -> luci-app-headscale(<*>, if using the Web UI)
-
Compile:
make package/headscale/compile V=s
Configuration lives in /etc/config/headscale. Key database options:
config headscale 'database'
option type 'sqlite'
option storage_mode 'auto'
option sqlite_path '/etc/headscale/db.sqlite'
storage_mode:'auto'(hardware auto-detection),'ram'(force Aggressive RAM Mode), or'direct'(force Direct Disk I/O).sqlite_path: Persistent SQLite file path (e.g.,/etc/headscale/db.sqlite, or an external mount such as/mnt/sda1/headscale/db.sqlite).
Enable and start the service:
uci set headscale.server.enabled='1'
uci commit headscale
/etc/init.d/headscale enable
/etc/init.d/headscale startStorage helper & Headscale CLI commands:
# Inspect detected storage media and sync state (JSON)
/usr/share/headscale/headscale.sh probe
# Force-sync RAM database to persistent storage
/etc/init.d/headscale sync_db
# Standard Headscale CLI operations
headscale users create myuser
headscale preauthkeys create -u myuser --reusable --expiration 24h
headscale nodes listWhen exposing Headscale to WAN/external networks, ensure the HTTP listen port (default TCP 8080, or 8188 when configured via luci-app-headscale) and embedded DERP STUN port (default UDP 3478) are allowed in /etc/config/firewall.
- Maintainer: permails logo@permails.com
- Companion Web UI:
luci-app-headscale - License: BSD 3-Clause License