Mesh VPN (Tailscale/headscale, NetBird planned) in the Debian initramfs, for remote unlocking of encrypted root filesystems. Debian trixie and sid/forky. Fork of darkrain42/tailscale-initramfs.
  • Shell 77.4%
  • Python 19.6%
  • Dockerfile 3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Ole-Morten Duesund bf441f39be
All checks were successful
CI / check (sid) (push) Successful in 2m15s
CI / check (trixie) (push) Successful in 2m7s
CI / release (push) Has been skipped
Update conversation log
Refs #7

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J4uXuVUu1P9jkJazw8qsjN
2026-11-13 17:16:52 +01:00
.claude Export Claude Code conversations to docs/conversations 2026-11-13 13:58:06 +01:00
.forgejo/workflows Add tests/run: set up containers and VMs and run all tests 2026-11-13 17:16:51 +01:00
conf-hooks.d Add NetBird support, with shared boot code for both VPNs 2026-11-13 16:01:41 +01:00
config Stop and log out in local-bottom, before dropbear takes the network down 2026-11-13 16:45:06 +01:00
debian Stop and log out in local-bottom, before dropbear takes the network down 2026-11-13 16:45:06 +01:00
docs/conversations Update conversation log 2026-11-13 17:16:52 +01:00
hooks Add NetBird support, with shared boot code for both VPNs 2026-11-13 16:01:41 +01:00
scripts Stop and log out in local-bottom, before dropbear takes the network down 2026-11-13 16:45:06 +01:00
tests Add tests/run: set up containers and VMs and run all tests 2026-11-13 17:16:51 +01:00
tools export-conversation: redact NetBird setup keys and access tokens 2026-11-13 15:46:51 +01:00
.gitignore Export Claude Code conversations to docs/conversations 2026-11-13 13:58:06 +01:00
LICENSE Add README, LICENSE, and .gitignore 2022-01-31 19:36:00 -08:00
README.md Add tests/run: set up containers and VMs and run all tests 2026-11-13 17:16:51 +01:00

vpn-initramfs

Run a mesh VPN client, Tailscale (or headscale) and/or NetBird (self-hosted or netbird.io), in a Debian initramfs, to provide access to the Linux system prior to unlocking an encrypted root filesystem. When combined with tailscale ssh or dropbear-initramfs, allows remote unlocking of an encrypted root filesystem from other machines on the VPN.

A fork of tailscale-initramfs by Paul Aurich, maintained for Debian trixie and sid/forky, with NetBird support added.

Each boot registers the initramfs as a new, ephemeral node with a key stored in the initramfs, and logs it out again when the boot moves on. Tag or group that key so the pre-boot environment only accepts connections and cannot make any; see Security.

Caution (Tailscale): The initramfs tailscale instance cannot log in your tailnet after the auth key expires, so the pre-boot environment won't be accessible from your tailnet. Tailscale auth keys are only valid for up to 90 days, configured when generating the auth key. To avoid losing access to the pre-boot environment, make sure you create a new auth key and update the initramfs before the old key expires. NetBird setup keys can be created without an expiry date.

Install

  1. Requires tailscale and/or netbird to be installed.

  2. Install the vpn-initramfs package from the Debian repository on kode.naiv.no. Use trixie for Debian 13, and forky or sid for testing/unstable; it is the same package.

# Step 1. Fetch the public key that signs the repository
sudo install -d -m 0755 /etc/apt/keyrings
curl -fsSL https://kode.naiv.no/api/packages/olemd/debian/repository.key \
    | sudo tee /etc/apt/keyrings/kode-naiv-no.asc >/dev/null

# Step 2. Add the repository
sudo tee /etc/apt/sources.list.d/vpn-initramfs.sources >/dev/null <<'SOURCES'
Types: deb
URIs: https://kode.naiv.no/api/packages/olemd/debian
Suites: trixie
Components: main
Signed-By: /etc/apt/keyrings/kode-naiv-no.asc
SOURCES

# Step 3. Install vpn-initramfs
sudo apt-get update && sudo apt-get install vpn-initramfs

Upgrading from tailscale-initramfs: vpn-initramfs replaces it. Move /etc/tailscale/initramfs/config to /etc/vpn-initramfs/config (and any auth key file it points at), then rebuild the initramfs.

  1. Add a Tailscale auth key (TAILSCALE_AUTHKEY), a NetBird setup key (NETBIRD_SETUP_KEY) or both in /etc/vpn-initramfs/config. Each VPN is only put into the initramfs when its key is set. Both accept file:/path/to/key, which keeps the key out of the config file; the key file is copied into the initramfs.

  2. Rebuild the initramfs

update-initramfs -c -k all

With tailscale ssh (on unless TAILSCALE_DISABLE_SSH is set), the hook generates SSH host keys once in /etc/vpn-initramfs/tailscale-ssh/ (this needs ssh-keygen from openssh-client) and copies them into the initramfs, so the host key stays the same across boots and known_hosts keeps working. Like dropbear-initramfs's keys, they are stored unencrypted in the initramfs.

With dropbear-initramfs

dropbear-initramfs works alongside, and is how you unlock over NetBird. The VPNs are stopped and logged out in local-bottom, right after the root is mounted, which is before dropbear's init-bottom script brings the network down; no setting is needed for that. (Up to 0.7, as tailscale-initramfs, logging out failed with dropbear: #8.)

NetBird

Create a setup key in the NetBird dashboard (Setup Keys) that is reusable, has ephemeral peers on, and auto-assigns a group, say initramfs. It can be made to never expire. Then, in /etc/vpn-initramfs/config:

NETBIRD_SETUP_KEY=file:/etc/vpn-initramfs/netbird.key
# For a self-hosted NetBird; leave out for netbird.io.
NETBIRD_MANAGEMENT_URL=https://netbird.example.com

and put the key in /etc/vpn-initramfs/netbird.key (mode 600). A private CA for a self-hosted server must be in the system's CA bundle (put it in /usr/local/share/ca-certificates and run update-ca-certificates); the bundle is copied into the initramfs.

Each boot registers a new ephemeral peer named <hostname>-initramfs, and deregisters it when the boot moves on (NETBIRD_LOGOUT, on by default); otherwise NetBird removes ephemeral peers 10 minutes after they go offline. To unlock the disk, connect to the peer's NetBird IP with dropbear-initramfs. (NetBird's own SSH server is not set up in the initramfs.)

In the initramfs NetBird runs with userspace WireGuard and its own packet filter, since there is no nftables or iptables there.

Size of the initramfs

The VPN clients are large Go programs, and Debian keeps one initramfs per installed kernel in /boot. Measured with Debian's defaults (MODULES=most, COMPRESS=zstd) on trixie:

initramfs size
without a VPN 34 MiB
with NetBird 48 MiB
with Tailscale 71 MiB
with both 84 MiB

(Tailscale ships two binaries, tailscale and tailscaled.) Before installing, check df -h /boot against the number of kernels you keep: if /boot runs full, update-initramfs fails in the middle of a kernel upgrade. MODULES=dep in /etc/initramfs-tools/initramfs.conf makes the initramfs much smaller, at the cost of only working with the current hardware.

Testing

tests/run runs everything on a developer machine with podman and QEMU: it builds the package and lints it in a container, builds Debian trixie and sid test systems, checks what goes into the initramfs, and boots it in QEMU against a local headscale and a self-hosted NetBird server, for both VPNs, with and without a root disk, network card and dropbear-initramfs. See tests/run --help and tests/README.md.

Security

If you're using full disk encryption (i.e. LUKS), the initramfs is typically unencrypted alongside the boot loader. The auth key or setup key you configure for this package is included in that initramfs in plaintext. Someone who can access the initramfs file can get a copy of the key and register new devices into the tailnet (or NetBird network) as long as the key is valid.

You can restrict what access such devices have by configuring Tailscale ACLs that prevent these devices from making any connections, and only accepting incoming connections. With NetBird, give the setup key its own auto-assigned group and add no access policy with that group as source; a policy from your admins' group to it (TCP 22 for dropbear) is all the initramfs needs.

The same goes for impersonation: whoever can read the initramfs can also register a node that looks like this machine and wait for you to type your disk passphrase into it. The VPN key does not protect against that; only measured or TPM-bound boot does.

Example Tailscale ACLs

{
	"tagOwners": {
		"tag:initramfs": [],
	},
	"groups": {
		"group:sshadmins": ["user@example.com"],
	},
	"grants": [
		{
			"src": ["autogroup:member"],
			"dst": ["*"],
			"ip": ["*"],
		},
	],
	// Equivalent deprecated ACLs to the above grants
	// "acls": [
	//     {"action": "accept", "src": ["autogroup:member"], "dst": ["*:*"]},
	// ],
	"tests": [
		// initramfs tag cannot make any outbound connections
		{
			"src":  "tag:initramfs",
			"deny": ["100.101.102.103:22", "192.0.2.1:22", "[2001:db8::feed]:22"],
		},
		// but users can connect to the initramfs
		{
			"src":   "user@example.com",
			"allow": ["tag:initramfs:22"],
		},
	],
	"ssh": [
		{
			"action": "check",
			"src":    ["autogroup:member"],
			"dst":    ["autogroup:self"],
			"users":  ["autogroup:nonroot", "root"],
		},
		{
			"action": "check",
			"src":    ["group:sshadmins"],
			"dst":    ["tag:initramfs"],
			"users":  ["autogroup:nonroot", "root"],
		},
	],
	"sshTests": [
		// initramfs tag cannot SSH anywhere.
		{
			"src":  "tag:initramfs",
			"dst":  ["100.101.102.103", "192.0.2.1", "2001:db8::feed"],
			"deny": ["*"],
		},
		// but users (in group:sshadmins) can SSH to the initramfs tag
		{
			"src":   "user@example.com",
			"dst":   ["tag:initramfs"],
			"check": ["root", "otters"],
		},
	],
}

Alternatives

  • initramfs-tools-tailscale

    uses the tailscale state/data from the normal Linux install. This means that the initramfs will show up as the existing device on the tailnet, but means the private key material is stored in the initramfs (which is commonly unencrypted).

  • tailscale-initramfs by Lugoues

    Similar to this package, but registers the initrd as a tailscale device when you configure the package. The initrd device will be present in the tailnet all the time.