Skip to content
STIRUP

TECHNOLOGY INTELLIGENCE

Understand what's next.

Epochnbd: A Pure-Go Linux NBD Engine with Cloud Storage Support

Epochnbd is a pure-Go Linux Network Block Device (NBD) engine that provides a POSIX raw block device interface, backed by Google Cloud Storage, Google Drive, or a local directory, with features like sparse caching and crash-consistent data integrity.

Share
AI-generated conceptual illustration accompanying: Epochnbd: A Pure-Go Linux NBD Engine with Cloud Storage Support
AI-generated editorial illustration of the article topic; not a photograph, product screenshot or measured result.

Architecture and Design Features

Epochnbd is a pure-Go (CGO_ENABLED=0) Linux Network Block Device (NBD) engine that provides a true POSIX raw block device interface, accessible via /dev/nbdX or TCP NBD export. It is backed by Google Cloud Storage (gs://), Google Drive (gdrive://), or a local directory (file://), with features such as local sparse caching, a CRC32-verified Write-Ahead Log (WAL), and atomic Compare-And-Swap (CAS) epoch checkpoints [Hacker News Show]. Unlike FUSE-based object-storage mounts like gcsfuse or s3fs, epochnbd operates strictly at the raw block layer, ensuring full compatibility with POSIX and database systems. This includes support for mmap, flock/fcntl locks, fsync flush barriers, SQLite in WAL mode, Git repositories, and standard Linux filesystems such as ext4, xfs, and btrfs [Hacker News Show]. Additionally, users can implement Bring Your Own Encryption (Zero-Knowledge Cloud Storage) by stacking standard Linux encryption solutions like LUKS2 (dm-crypt) or VeraCrypt on top of /dev/nbd0, or choose to run unencrypted when needed [Hacker News Show].

Data Integrity and Crash Recovery

Epochnbd ensures data integrity through crash-consistent mechanisms that prevent torn cloud checkpoints. Dirty chunks are uploaded to immutable, epoch-tagged objects (e.g., chunks/000042_e7.bin), and the manifest.json advances atomically via GCS generation preconditions (ifGenerationMatch) only after every dirty chunk in the epoch succeeds . In the event of a crash—such as a kill -9 or power loss—uncommitted writes from the prior session are replayed, compacted into a new immutable epoch, and committed via CAS before the block device becomes visible to the OS . However, users should be aware of potential risks associated with unbounded dirty cache, particularly during teardown or unmount. When detaching the volume or shutting down cleanly (epochnbd-vault.sh down), the daemon flushes all uncompacted dirty chunks into a final cloud epoch before disconnecting .

Encryption and Privacy

Epochnbd supports Bring Your Own Encryption (BYOE) through standard Linux LUKS2 (dm-crypt) or VeraCrypt, allowing users to apply encryption at the block layer on top of /dev/nbd0 or operate unencrypted when needed. When encryption is enabled, cloud storage services such as Google Cloud Storage (GCS) and Google Drive only see opaque, fixed-size ciphertext chunks—512 KiB by default on GCS/LocalFS and 4 MiB on Google Drive, as noted in the project’s documentation. This design ensures that the cloud provider does not gain access to plaintext data. Additionally, ephemeral session credentials are stored exclusively in tmpfs RAM, such as at /run/user/$UID/epochnbd/gcloud-nbd0 or /dev/shm/epochnbd-$UID/..., and are automatically revoked and deleted upon shutdown, as described in the project’s source materials.

Cache and Write-ahead Logging

Epochnbd employs a local cache directory (--cache-dir) to manage data efficiently. This directory contains a sparse raw disk image (cache.img), an append-only write-ahead log (wal.log), and metadata files such as state.meta and epochnbd.pid. The cache.img is created as a sparse file using Truncate(DiskSize), ensuring that disk space is only consumed for touched blocks. In --sync-mode=cloud-strict, remote WAL delta segments (wal/seq_%08d.seg) are uploaded on every fsync barrier before being compacted and deleted. Periodically, the compactor snapshots dirty chunks, uploads them in parallel, and updates manifest.json via atomic CAS. This process trims WAL records and garbage-collects outdated chunk versions, ensuring efficient storage and crash consistency.

Usage and Initialization

The init command sets up a new cloud vault by specifying parameters such as the backend storage location, cache directory, mount point, and vault size. It initiates a Google sign-in flow, which can be bypassed with the --no-browser flag for environments where a browser is not available. For recovery after a crash on a new machine, the recover command is used with an empty --cache-dir to avoid conflicts from a previous lease holder. In raw block device mode, the --mount-dir flag is omitted, allowing direct control over /dev/nbd0. This mode is useful for custom configurations, such as applying specific filesystems or encryption methods. For example, sudo mkfs.ext4 can be used with optimized flags to create a sparse-optimized filesystem, which is then mounted with performance-focused options like noatime and noinit_itable to reduce I/O overhead.

Sources and reporting notes

Based on published source material. No independent hands-on testing is claimed.

Read more