31.1. Designing a Replicated Storage Pair

A two-node DRBD design starts with authority: which node may write, how many copies must acknowledge a write, and what happens when the nodes cannot see each other. Those choices determine the protocol, the network layout, and the recovery procedure. The installed kernel module then constrains which of the newer DRBD features are available, and the backup design must remain independent of the replica.

31.1.1. Block Replication, Primary and Secondary Roles, and Data Authority

DRBD is a block-device layer. It does not understand files, inodes, database pages, or NFS locks. It receives block writes from the layer above, writes them to its local backing device, and sends them to its peer. On the peer, the same blocks are written to that node's backing device. Because both nodes hold a complete copy of the block device, either node can present the filesystem after a role change, provided the copy is current and the old writer has stopped.

A DRBD resource has a role on each node. A Primary node may open the device for writing, create a filesystem on it, mount it, and export it. A Secondary node keeps the device available for replication but does not allow ordinary writers. In a two-node resource without dual-primary support, only one node may be primary at a time. The role is a runtime property, not a permanent property of the host: the same node can be primary for one resource and secondary for another, and a node can change roles after the administrator or cluster manager has prepared the transition.

The primary role carries data authority. When the two copies agree, either copy can become primary. When they disagree, promoting one node declares its blocks authoritative and discards the other copy's divergent blocks during the next resynchronization. That is why a normal promotion requires the peer's disk to be UpToDate, while the initial promotion of a new, empty pair requires an explicit choice. The one-time command

$ sudo drbdadm primary --force r0

The command normally prints nothing. It is appropriate when both nodes were just initialized and no filesystem exists yet, or when an administrator has deliberately chosen one copy after an incident. It is not a routine switchover command. On a healthy pair, use drbdadm primary r0 after demoting the old primary; DRBD then checks that the promotion is consistent with the peer's state.

A mounted filesystem makes the role choice consequential. Two nodes must never mount the same non-cluster filesystem at the same time, even if both DRBD devices are somehow primary. Ext4, XFS, and similar local filesystems assume a single writer and will corrupt metadata when two hosts update the same block device. DRBD's single-primary rule is a safety interlock, not a substitute for fencing a failed node. A node that has lost contact but still has the filesystem mounted can continue writing locally; the surviving node's administrator must ensure the old node is really stopped before promoting the peer.

Several storage designs can put data on a second host. They replicate at different layers and fail in different ways:

Approach Unit of replication Update and acknowledgment model Failover model Main failure domain Operational cost
DRBD Block device Synchronous block writes with protocol C; the peer's disk acknowledges Manual promotion or a cluster manager Both nodes, the replication link, shared power and site LVM or partitions, DRBD configuration, role management, cluster integration for automation
ZFS send/receive Dataset or snapshot stream Asynchronous by default; snapshots are transferred on a schedule Restore or promote a copy manually; no block-device role Source pool, target pool, transfer schedule Snapshot retention, incremental transfer bookkeeping, separate target, OpenZFS packaging in contrib
Shared SAN or iSCSI LUN Single LUN on shared storage The array acknowledges; the host does not hold a second copy Multipath and cluster-managed LUN ownership Fabric, array, and both hosts' access paths Multipath, zoning, array dependency, fencing, and a single storage system to protect
Application-native replication Logical records or transactions The application's commit or replication protocol Application-specific promotion and recovery Application version, schema, lag, and failover logic Application expertise, consistency checks, and testing of promotion and rollback

DRBD is the appropriate choice here because the requirement is a movable block device with a full local copy on each node and a single-writer filesystem. ZFS send/receive is a better fit for scheduled dataset copies and retention, as described in Chapter 30. A shared LUN avoids copying but makes the array a single failure domain. Application-native replication can be more efficient and more consistent for a database, but it requires application-level promotion and lag handling. The comparison is not a ranking: the workload, recovery point objective, and operational skills decide the design.

31.1.2. Replication Protocols, Acknowledgments, and Failure Tradeoffs

The resource protocol determines when a write is acknowledged to the layer above. DRBD supports three protocols, selected with the protocol keyword in the resource file or with drbdsetup connect --protocol. The choice changes what a crash can lose, how long a write takes, and how sensitive the service is to network latency.

Protocol Write acknowledged after Typical durability Main tradeoff
A The local disk write and the local TCP send buffer The peer may be far behind; data still in flight or in the peer's memory can be lost Lowest write latency and least network sensitivity, but the weakest replication guarantee
B The local disk write and the peer's buffer cache The peer has the data in memory, but a peer power failure can lose recent writes A middle ground, still dependent on the peer's cache surviving
C The local disk write and the peer's disk write Both copies are on stable storage before the application sees completion Highest write latency and the most network sensitivity, but the strongest of the three

Protocol C is the normal choice for a two-node filesystem whose purpose is to survive the loss of one node. It is also the protocol used throughout this chapter. While the peer is connected and current, a write that the application has been told is complete exists on both backing devices, so a failover to that secondary does not silently lose the last acknowledged write. The cost is that every write waits for a network round trip and the peer's disk. On a low-latency link this is often acceptable; on a long-distance or congested link it can dominate application latency.

Protocol B acknowledges when the peer has accepted the write into its cache. That protects against the primary's disk failure but not against a simultaneous power loss on the peer before the cache is flushed. Protocol A acknowledges as soon as the write is on the local disk and in the local send buffer, so a primary disk failure can still lose writes that the peer never received. Use A or B only when the application or a higher layer has its own durability mechanism, or when the data is reproducible and latency matters more than the last few writes.

Write acknowledgment boundaries

Figure 31.2. The protocol selects the point at which the primary acknowledges a write. Protocol C waits for the peer's disk; protocols A and B stop earlier and therefore lose different amounts of data when a node or link fails.

Independently of the protocol, the backing device and its write cache matter. A disk that claims a write is durable before it reaches stable media weakens every protocol above it. DRBD normally uses flushes and barriers where the stack supports them; LVM and the underlying virtio or physical device must pass those operations through. During these procedures, /proc/drbd shows wo:f, meaning DRBD is using flushes. If a storage stack cannot honor flushes, the durability described by protocol C is not actually guaranteed, even though DRBD reports the link as healthy.

A DRBD resource needs a replication link between the two nodes. In the example, drbd1 listens on 192.168.231.11:7789 and drbd2 on 192.168.231.12:7789. Port 7789 is the conventional DRBD port, but any unused port can be configured. The link should be a dedicated network or a VLAN with predictable latency and enough bandwidth for both normal writes and resynchronization. Running replication over the same congested interface that serves clients makes a client burst compete with recovery traffic.

Clients normally do not touch DRBD directly. They reach a filesystem or a service on the current primary. In this example the primary exports /srv/drbd-data over NFSv4, and drbdclient mounts that export at /mnt/drbd. The client address does not move with the primary in this manual procedure; an administrator must unmount the old path, stop the service on the old node, and mount the new primary. A cluster manager can move a virtual IP and restart the service automatically, but the data path still has to be ordered correctly.

The failure domains are broader than the two disks. Both nodes may share a power feed, a switch, a rack, or a site. Replication protects against the loss of one node's storage or one node's operating system, but it does not protect against a failure that takes both nodes down, a logical deletion that is replicated to both copies, or a client whose own network path disappears. If both nodes are in the same room on the same uninterruptible power supply, a room-level event can still destroy both copies. An independent backup on separate media and, ideally, a separate site is part of the design, not an optional extra.

The replication link itself is a single point of failure for currentness. If it is down, the primary can often continue serving writes locally, but the secondary falls behind and a later failover may lose the writes made during the outage. A redundant link, a separate heartbeat path, and monitoring of the connection state reduce that risk. The example deliberately isolates the link in section 31.6.2 to show the difference between "the service is still running" and "the data is still replicated."

31.1.4. Installed DRBD Versions, Kernel Modules, and Userspace Compatibility

Debian 13 packages the DRBD userspace tools as drbd-utils and ships the DRBD kernel module in the kernel package. The userspace version and the kernel module version are not necessarily the same. Check both before writing a resource file, because the configuration syntax and the available features depend on the kernel module that is actually loaded. The checks in this section use the packages installed in section 31.2.2; on a system that does not have them yet, run that installation first. The package arranges for the module to load at the next boot through /usr/lib/modules-load.d/drbd.conf, and sudo modprobe drbd loads it immediately.

On drbd1, as john, the installed release and kernel are:

$ uname -r
6.12.86+deb13-amd64
$ cat /etc/debian_version
13.5

The installed drbd-utils, LVM, and NFS packages are:

$ dpkg-query -W drbd-utils lvm2 nfs-kernel-server
drbd-utils  9.22.0-1.1
lvm2    2.03.31-2
nfs-kernel-server   1:2.8.3-1

The userspace administration tool reports its own version, the backend API it uses, and the kernel version code. On the same node:

$ sudo drbdadm --version
DRBDADM_BUILDTAG=GIT-hash:\ 409097fe02187f83790b88ac3e0d94f3c167adab\ reproducible\ build\,\ 2024-07-17\ 17:22:06
DRBDADM_API_VERSION=1
DRBD_KERNEL_VERSION_CODE=0x08040b
DRBDADM_VERSION_CODE=0x091600
DRBDADM_VERSION=9.22.0

DRBDADM_VERSION=9.22.0 describes the command-line tools. The kernel code 0x08040b decodes to a DRBD 8.4.11 kernel module. The installed module confirms the same version. In the following command, the | sends the output of modinfo to grep, which keeps only the version and description lines:

$ sudo modinfo drbd | grep -E "^(version|description):"
version:        8.4.11
description:    drbd - Distributed Replicated Block Device v8.4.11
$ sudo cat /sys/module/drbd/version
8.4.11

This is an important boundary. The 9.22 userspace tools can drive the older 8.4 kernel API, but they cannot add kernel features that the module does not implement. The Debian archive for this release contains drbd-utils and drbd-doc, not a drbd-dkms package that would build a newer module:

$ sudo apt-cache search drbd
collectd-core - statistics collection and monitoring daemon (core system)
drbd-doc - RAID 1 over TCP/IP for Linux (user documentation)
drbd-utils - RAID 1 over TCP/IP for Linux (user utilities)
monitoring-plugins-contrib - Plugins for nagios compatible monitoring systems
prometheus-hacluster-exporter - Prometheus exporter for HA cluster services
golang-github-linbit-golinstor-dev - golang bindings for linstor (library)

The practical consequences are covered in section 31.4.4: DRBD 9 quorum, quorum-minimum-redundancy, on-no-quorum, diskless tiebreakers, and the newer multi-volume peer model are not available with the in-tree 8.4.11 module. The resource file in this chapter therefore uses the two-node 8.4 layout with resource, on <host>, device, disk, address, and meta-disk internal.

The userspace drbdsetup connect --help in this installation shows the backend options that the loaded module accepts. It lists no quorum option:

$ sudo drbdsetup connect --help
drbdsetup connect - Attempt to (re)establish a replication link to a peer host.

USAGE: drbdsetup connect {resource} {peer_node_id}
    [--tentative={yes|no}] [--discard-my-data={yes|no}]

That is not a defect in the userspace tools. It reflects the kernel API. A reader who requires 9.x features must install and support a matching out-of-tree kernel module, verify that the module loads on the running kernel, and check the kernel/userspace combination before relying on the feature. That path is outside the stock Debian 13 package set.

Component Installed version What it determines
Debian release 13.5 Package versions and the supported kernel
Running kernel 6.12.86+deb13-amd64 In-tree drbd module
DRBD kernel module 8.4.11 Kernel features and resource model
drbdadm/drbdsetup 9.22.0 Command syntax and configuration parser
Kernel API 1 Backend compatibility reported by drbdadm

31.1.5. Why Replication Is Not Backup or Automatic Failover

DRBD gives a second copy of the current block device. It does not give a history of the device. If a file is deleted, the deletion is a block update that replicates to the peer. If a filesystem is corrupted, both copies receive the corrupted blocks. If an application writes a bad record and commits it, both nodes hold the bad record. A replicated database is not a backup; it is a highly available copy of the current mistakes.

A backup must be independent in time and location. It should be possible to restore an earlier version after an accidental deletion, a bad upgrade, or malware. In this chapter the independent copy is the records file copied from the NFS mount to /home/john/debian-handbook/drbd/backup-records.txt on the client's own disk; a real backup would use snapshot retention, a separate backup server, or offline media. Chapter 30 covers ZFS snapshots and zfs send streams, which provide a different point-in-time model. Neither a DRBD secondary nor a ZFS snapshot on the same pool is a substitute for an offline or off-site copy.

DRBD also does not promote a node by itself. Debian's drbd.service starts a configured resource in the secondary role and leaves promotion to an explicit command or a cluster manager. A reboot does not make a node primary because it happened to boot first. That is deliberate: an automatic promotion based only on "I am alive" could create two writers. A cluster manager adds health checks, quorum, and fencing, but the manager must be configured and tested. If those pieces are missing, the administrator is the failover controller, and the runbook must include stopping the old writer before promoting the new one.