31.4. Handling Link and Node Failures
DRBD distinguishes a lost peer from a lost local disk. A lost peer leaves the primary serving local writes while the bitmap records what must be resent; a lost local disk can leave the node diskless even though the process and network are healthy. Split brain is the case in which both nodes wrote without a link, and it requires an explicit authority decision. The available recovery tools depend on whether the kernel implements the 8.4 or 9.x feature set.
31.4.1. Observing a Disconnected Peer and Following Resynchronization
A node can disappear because it is rebooted, its network fails, or the DRBD
service is stopped. On the surviving primary, the resource keeps serving local
writes if the backing device is healthy, but the peer is no longer current. In
the example, drbd2 is primary and drbd1 is secondary. Restore the NFS service on
drbd2 and remount the export on the client before testing the client path.
On drbd2, as john:
$ sudo systemctl start nfs-server
On drbdclient, as john:
$ sudo mount -t nfs drbd2:/srv/drbd-data /mnt/drbd
Both commands normally print nothing. Now take the secondary down:
$ sudo drbdadm down r0
The command normally prints nothing. On drbd2, as john, inspect the resource:
$ sudo drbdadm status r0
r0 role:Primary
disk:UpToDate
peer connection:Connecting
The primary still has a current local disk. The peer section has no role or disk state because the peer is not answering; only the connection attempt is reported. This is not the same as a healthy secondary. If the primary also fails now, the latest writes exist on only one node.
A client can continue writing while the peer is down:
$ printf "during-failure 4\n" >> /mnt/drbd/records.txt
The append normally prints nothing. Read the client's file:
$ cat /mnt/drbd/records.txt
alpha 1
beta 2
client 3
during-failure 4
The write is on the primary's local disk. It has not reached the peer. Bring the secondary back:
$ sudo drbdadm up r0
The command normally prints nothing. On drbd1, inspect the resource after it reconnects:
$ sudo drbdadm status r0
r0 role:Secondary
disk:UpToDate
peer role:Primary
replication:Established peer-disk:UpToDate
When the secondary reconnects, DRBD consults the bitmap that was recorded while
the link was down and resends only the blocks marked dirty. On this small
device the catch-up can finish before a status sample is taken, so the first
Established output may already show UpToDate. On a larger or busier device,
/proc/drbd shows cs:SyncTarget or cs:SyncSource and a nonzero oos
count until the dirty blocks have been copied. The peer now reports
UpToDate, so the missed line has been sent according to the bitmap. If the
primary had failed before the resync completed, that line would have existed
on only one copy.
31.4.2. Dirty Bitmaps, Full Synchronization, and Recovery Traffic
DRBD tracks writes in a bitmap so that a returning peer does not need a complete
copy of the device. Each bit covers a region of the backing device. When the
link is down, the primary sets bits for the regions it writes. On reconnect,
the peer receives those regions and clears the corresponding bits. The activity
log records in-flight writes around a crash so that the bitmap itself remains
consistent. The bitmap is part of DRBD's metadata; it is why the initial
create-md reports a 16 KB or 24 KB bitmap rather than a fixed reserve.
A partial resynchronization uses the bitmap and copies only marked regions.
It is the normal recovery after a short link outage, a secondary reboot, or a
temporary network failure. A full synchronization copies the entire device.
It is required when the peer has no usable bitmap, when the metadata says the
local copy is inconsistent, or when a new backing device is initialized with
create-md. The replacement procedure in section 31.4.5 is a full sync.
The oos field in /proc/drbd is the number of kilobytes still out of sync.
The resync-rate option caps background recovery traffic. This example sets
resync-rate 100M; the observed initial copy ran at about
43,688 KiB/s, and the replacement sample in section 31.4.5 reported
38,912 KiB/s at the point shown. Those numbers describe these small
qcow2-backed virtio disks at that moment; they are not a benchmark of DRBD or
of the network. On production hardware, the limit should leave enough
bandwidth for client writes and should be tested under the expected load. A
resynchronization that saturates the replication link can starve protocol C
writes and turn a recovery into a second outage.
The recovery commands have different meanings:
| Command | Effect |
|---|---|
drbdadm connect r0 |
Re-establish the link and use the bitmap for a partial sync |
drbdadm up r0 |
Attach the backing device and connect |
drbdadm invalidate r0 |
Mark the local copy invalid and force a full sync from the peer |
drbdadm invalidate-remote r0 |
Mark the peer's copy invalid and force a full sync to it |
drbdadm -- --discard-my-data connect r0 |
On the losing node, discard local data and resync from the peer |
drbdadm resize r0 |
Adopt a grown backing device and synchronize the new space |
invalidate and invalidate-remote are destructive to the copy they mark.
They are appropriate after a known-good copy has been chosen, not as a first
response to a connection problem. The --discard-my-data form is specifically
for split-brain resolution and is covered next.
31.4.3. Split Brain, Choosing an Authoritative Copy, and Preserving Divergent Data
Split brain means both nodes believed they were allowed to write while the link was down. Each node accepted local writes, so the two copies no longer share a single history. DRBD cannot merge them. It detects the divergence when the nodes reconnect and refuses to choose a winner automatically when the resource is configured with the manual policies used here.
Warning: the following exercise deliberately creates divergent data and then discards one copy. Do it only on a disposable test system. On a production system, preserve both copies before resolving anything, and do not mount the same filesystem on both nodes at the same time. In this exercise the writes are made one node at a time, with an unmount between them; the two primaries are disconnected, which is what makes the histories diverge.
Start with the client and service stopped and the filesystem unmounted. On
drbdclient:
$ sudo umount /mnt/drbd
The client unmount normally prints nothing. On the old primary drbd2, as
john:
$ sudo systemctl stop nfs-server
$ sudo umount /srv/drbd-data
$ sudo drbdadm secondary r0
The service stop, unmount, and demotion normally print nothing. Disconnect both nodes so that neither can see the other's writes:
$ sudo drbdadm disconnect r0
Run the same disconnect on drbd1:
$ sudo drbdadm disconnect r0
Both commands normally print nothing. Each node is now StandAlone at the link
level. Force-promote drbd2, mount it, and write a divergent line:
$ sudo drbdadm primary --force r0
$ sudo mount /dev/drbd0 /srv/drbd-data
$ printf "divergent-bravo\n" >> /srv/drbd-data/records.txt
The force-promotion, mount, and append normally print nothing; the append writes to a redirected file. Preserve that copy outside the DRBD device before doing anything else:
$ cp /srv/drbd-data/records.txt ~/debian-handbook/drbd/divergent-records.txt
The copy normally prints nothing. Verify the preserved file:
$ sha256sum ~/debian-handbook/drbd/divergent-records.txt
d9693d8aee633d3c1b2ff5fc252a73a8a0c2de9bc15e8f6877c52dd2da148585 /home/john/debian-handbook/drbd/divergent-records.txt
Unmount drbd2. On drbd1, force-promote, mount, and write a different
divergent line:
$ sudo umount /srv/drbd-data
The unmount normally prints nothing. On drbd1, as john:
$ sudo drbdadm primary --force r0
$ sudo mount /dev/drbd0 /srv/drbd-data
$ printf "authoritative-alpha\n" >> /srv/drbd-data/records.txt
The promotion, mount, and append normally print nothing. Preserve the copy:
$ cp /srv/drbd-data/records.txt ~/debian-handbook/drbd/authoritative-records.txt
The copy normally prints nothing. Verify it:
$ sha256sum ~/debian-handbook/drbd/authoritative-records.txt
7052ff059e6c1bc09da6d8eda815823b0a07df12d7aa4357274db889e354fb07 /home/john/debian-handbook/drbd/authoritative-records.txt
Unmount drbd1, then reconnect both nodes normally:
$ sudo umount /srv/drbd-data
$ sudo drbdadm connect r0
On drbd2, run the same connect:
$ sudo drbdadm connect r0
Both commands normally print nothing. The nodes exchange metadata and discover
that both copies were primary without a common current state. On drbd2, the
kernel state is:
$ cat /proc/drbd
version: 8.4.11 (api:1/proto:86-101)
srcversion: C95F202D36359D5A59245EB
0: cs:StandAlone ro:Primary/Unknown ds:UpToDate/DUnknown r-----
ns:0 nr:0 dw:1090137 dr:6423 al:19 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:1060
The connection is StandAlone again, and the peer state is unknown. The oos
count is small, but the number does not matter: two different histories cannot
be reconciled by counting blocks. The kernel log on drbd1 records the detection; the -i option makes the
grep match case-insensitive:
$ sudo dmesg | grep -i "Split-Brain"
[ 470.880314] drbd r0/0 drbd0: helper command: /sbin/drbdadm initial-split-brain minor-0
[ 470.885735] drbd r0/0 drbd0: helper command: /sbin/drbdadm initial-split-brain minor-0 exit code 0 (0x0)
[ 470.886079] drbd r0/0 drbd0: Split-Brain detected but unresolved, dropping connection!
[ 470.886556] drbd r0/0 drbd0: helper command: /sbin/drbdadm split-brain minor-0
[ 470.892838] drbd r0/0 drbd0: helper command: /sbin/drbdadm split-brain minor-0 exit code 0 (0x0)
The after-sb-0pri, after-sb-1pri, and after-sb-2pri policies are set to
disconnect, so the helper reports the condition and drops the connection.
DRBD does not pick the newer copy. An administrator must choose which copy is
authoritative, preserve the other copy if it contains information worth
keeping, and then explicitly discard the losing copy.
In this exercise, drbd1 is chosen as authoritative because
authoritative-alpha is the line we want to keep. On the losing node drbd2,
demote it and reconnect with the discard option:
$ sudo drbdadm secondary r0
$ sudo drbdadm -- --discard-my-data connect r0
Both commands normally print nothing. The first removes the primary role; the second tells DRBD to discard this node's copy.
On drbd1, connect the winner:
$ sudo drbdadm connect r0
$ sudo drbdadm status r0
r0 role:Primary
disk:UpToDate
peer role:Secondary
replication:Established peer-disk:UpToDate
The status shows the winning node as primary and the rebuilt peer as secondary.
--discard-my-data tells DRBD that the local copy is the one to lose. It is a
confirmation, not a merge. The peer's divergent blocks are overwritten by the
chosen copy. The preserved file in john's home directory is outside the
resource and remains available for inspection.
To confirm what the surviving copy contains, demote drbd1, promote drbd2,
and mount it:
$ sudo drbdadm secondary r0
On drbd2, as john:
$ sudo drbdadm primary r0
$ sudo mount /dev/drbd0 /srv/drbd-data
These commands normally print nothing. Read the surviving file:
$ cat /srv/drbd-data/records.txt
alpha 1
beta 2
client 3
during-failure 4
authoritative-alpha
The surviving file contains the line written on drbd1, not the line written on
drbd2. The divergent copy is still available separately:
$ cat ~/debian-handbook/drbd/divergent-records.txt
alpha 1
beta 2
client 3
during-failure 4
divergent-bravo
This is the practical meaning of choosing an authoritative copy. The two histories are not combined, and no tool can decide which line a user meant to keep. A real incident needs an application-level reconciliation after the block-level authority has been restored.
Figure 31.4. Planned switchover, peer loss, split brain, and recovery. A planned role change moves from secondary/secondary through one primary. A peer loss leaves the primary writing locally. Split brain requires an explicit choice; the losing copy is preserved outside DRBD and then discarded.
31.4.4. Version-Specific Quorum and Diskless Tiebreaker Capabilities
DRBD 9 adds quorum concepts that are not present in the 8.4 kernel module
shipped by Debian 13. In a 9.x resource, quorum can require that a minimum
number of nodes or a minimum redundancy is available before the resource
remains usable. quorum-minimum-redundancy can require at least one complete
copy besides the local one, and on-no-quorum can choose whether to suspend
I/O, stop the resource, or continue in a degraded mode. A diskless tiebreaker
node can participate in quorum decisions without holding a copy of the data.
None of those kernel features is available with the in-tree 8.4.11 module.
The userspace manual describes them, but drbdsetup connect --help on this
system lists only --tentative and --discard-my-data; there is no quorum
option to enable. A resource file that uses the 9.x multi-volume/peer layout or
quorum directives will not produce the intended behavior on this kernel. This
is a version boundary, not a configuration mistake.
| Capability | DRBD 8.4.11 in Debian 13 | DRBD 9.x kernel | Consequence for this example |
|---|---|---|---|
Two-node resource/on model |
Yes | Yes, with additional volume/peer structure | This example uses the 8.4 layout |
| Protocol A/B/C | Yes | Yes | Protocol C is used and tested |
| Internal metadata | Yes | Yes | Metadata lives at the end of each LV |
Quorum and quorum-minimum-redundancy |
No | Yes | A two-node pair cannot use DRBD-level quorum here |
on-no-quorum policy |
No | Yes | I/O suspension decisions need the cluster manager |
| Diskless tiebreaker node | No | Yes | A third node cannot act as a DRBD tiebreaker with this module |
| Multiple volumes per resource | Limited by the 8.4 model | Yes | One volume per resource in this chapter |
A two-node cluster has a well-known quorum problem even with a newer DRBD: if the nodes lose contact, each side may believe the other is dead. DRBD's single-primary rule prevents ordinary dual writes while connected, but it does not stop an administrator or an unmanaged script from force-promoting both disconnected nodes. The cluster layer must provide membership and fencing. Corosync can use a quorum device on a third host, and Pacemaker can use fencing to ensure the old node is stopped before the new one is promoted. Those are cluster-manager features, not DRBD 8.4 features. Chapter 32 covers them in detail.
If a deployment genuinely requires DRBD 9 quorum or a diskless tiebreaker,
treat the kernel module as a separate supported component. Install a module
that matches the running kernel, confirm drbdadm --version and
/sys/module/drbd/version, and test quorum loss, tiebreaker loss, and recovery
before putting data on it. Do not assume that the 9.22 userspace tools imply
9.x kernel behavior.
31.4.5. Replacing a Failed Backing Device or Peer
A failed backing device can be replaced without rebuilding the whole node. The
surviving node must have a current copy, the failed node's resource must be
stopped, and the new device must be at least as large as the resource's current
size. In this example, drbd2 replaces /dev/vdb with the spare /dev/vdc. The
old /dev/vdb is left unused after the procedure.
Warning: the following commands remove the volume group and the physical
volume label on drbd2's old disk. Any data still on that disk that is not on
the peer will be lost. Confirm the resource is secondary and unmounted before
starting, and confirm that the peer is UpToDate.
On drbd2, stop writers by unmounting the filesystem, demote, and take the
resource down:
$ sudo umount /srv/drbd-data
$ sudo drbdadm secondary r0
$ sudo drbdadm down r0
Each command normally prints nothing. Deactivate and remove the old volume group, then remove the PV label from the failed disk:
$ sudo vgchange -an vgdrbd
0 logical volume(s) in volume group "vgdrbd" now active
$ sudo vgremove -f vgdrbd
Logical volume "data" successfully removed.
Volume group "vgdrbd" successfully removed
$ sudo pvremove -ff /dev/vdb
Labels on physical volume "/dev/vdb" successfully wiped.
Create a new volume group and logical volume on /dev/vdc. The new LV must be
the same size as the resource that the peer is serving; here that is 768 MiB
after the growth exercise:
$ sudo vgcreate vgdrbd /dev/vdc
Physical volume "/dev/vdc" successfully created.
Volume group "vgdrbd" successfully created
$ sudo lvcreate -L 768M -n data vgdrbd
Logical volume "data" created.
Initialize fresh DRBD metadata on the new LV. The command's standard output is:
$ sudo drbdadm create-md r0
initializing activity log
Writing meta data...
New drbd meta data block successfully created.
The command also reports initializing bitmap (24 KB) to all zero on standard
error. The 24 KB bitmap corresponds to the larger 768 MiB device. Bring the
resource up:
$ sudo drbdadm up r0
The command normally prints nothing. Because the new device is Inconsistent
and the peer is UpToDate, DRBD starts a full synchronization from the peer.
The kernel state during the copy is:
$ cat /proc/drbd
version: 8.4.11 (api:1/proto:86-101)
srcversion: C95F202D36359D5A59245EB
0: cs:SyncTarget ro:Secondary/Secondary ds:Inconsistent/UpToDate C r-----
ns:0 nr:233472 dw:233472 dr:0 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:552900
[=====>..............] sync'ed: 30.3% (552900/786372)K
finish: 0:00:14 speed: 38,912 (38,912) want: 50,240 K/sec
cs:SyncTarget identifies this node as the receiver. Its local disk is
Inconsistent and the peer is UpToDate. The nr and dw counters show
network receive and disk write activity. The synchronization rate here is
around 38,912 KiB/s and the estimate is about 14 seconds, but the actual
duration depends on the device and the resync-rate cap.
Wait until the copy has completed and the status shows both disks current:
$ sudo drbdadm status r0
r0 role:Secondary
disk:UpToDate
peer role:Secondary
replication:Established peer-disk:UpToDate
Both disks are now UpToDate and replication is Established. This is the
safe point to promote. A status line that still reports Inconsistent or
SyncTarget is not a success; keep polling until it changes, as explained in
section 31.2.4. On a larger device the copy can take much longer than the
estimate printed during the transfer. Only then move the role. On drbd1, as
john, demote the peer; the command is a safeguard that succeeds without
change if the peer is already secondary:
$ sudo drbdadm secondary r0
On drbd2, as john, promote the rebuilt node and mount it:
$ sudo drbdadm primary r0
$ sudo mount /dev/drbd0 /srv/drbd-data
These commands normally print nothing. Read the file and compare its checksum with the authoritative copy recorded earlier:
$ cat /srv/drbd-data/records.txt
alpha 1
beta 2
client 3
during-failure 4
authoritative-alpha
$ sha256sum /srv/drbd-data/records.txt
7052ff059e6c1bc09da6d8eda815823b0a07df12d7aa4357274db889e354fb07 /srv/drbd-data/records.txt
The rebuilt device now contains the same authoritative content as the peer. The
old /dev/vdb is no longer part of the stack:
$ lsblk -o NAME,SIZE,TYPE,MOUNTPOINT /dev/vdb /dev/vdc
NAME SIZE TYPE MOUNTPOINT
vdb 1G disk
vdc 1G disk
└─vgdrbd-data 768M lvm
└─drbd0 767.9M disk /srv/drbd-data
Replacing a whole peer follows the same idea: bring the surviving node's
resource to a known primary or secondary state, rebuild the failed node's
storage and configuration, run create-md on the new backing device, and let it
synchronize. If the failed node also held the only copy of the filesystem, the
procedure becomes a restore, not a resynchronization. That is why the
independent backup is tested separately.