DRBD (Distributed Replicated Block Device) is a kernel-level storage replication solution that mirrors a block device between two servers in real time, functioning as a network-based RAID 1. It is widely used as the shared-storage layer in high-availability clusters managed by Pacemaker and Corosync on RHEL 9. Unlike shared-disk solutions, DRBD requires no SAN or shared hardware — replication happens over a standard Ethernet interface. This tutorial walks through installing, configuring, initialising, and operating a DRBD resource on RHEL 9.

Prerequisites

  • Two RHEL 9 nodes (node1 and node2) that can reach each other over the network
  • A spare, unformatted block device on each node (e.g., /dev/sdb)
  • Root or sudo access on both nodes
  • RHEL 9 with the EPEL or ELRepo repository enabled for DRBD packages
  • Hostnames resolvable between nodes (via DNS or /etc/hosts)

Step 1 — Install DRBD

DRBD packages are available from ELRepo, which provides kernel modules compatible with the RHEL 9 kernel. Run the following on both nodes.

# Add ELRepo on both nodes
sudo rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
sudo dnf install -y https://www.elrepo.org/elrepo-release-9.el9.elrepo.noarch.rpm

# Install DRBD userspace tools and the kernel module
sudo dnf install -y drbd kmod-drbd

# Load the kernel module
sudo modprobe drbd

# Verify the module is loaded
lsmod | grep drbd

# Persist module loading across reboots
echo "drbd" | sudo tee /etc/modules-load.d/drbd.conf

Step 2 — Configure the DRBD Resource

DRBD resources are defined in /etc/drbd.d/. Create the same configuration file on both nodes. Replace the IP addresses with your actual node addresses.

# /etc/drbd.d/myresource.res
resource myresource {
    protocol C;          # Synchronous replication — safest

    net {
        verify-alg sha256;
    }

    on node1 {
        device    /dev/drbd0;
        disk      /dev/sdb;
        address   192.168.1.11:7789;
        meta-disk internal;
    }

    on node2 {
        device    /dev/drbd0;
        disk      /dev/sdb;
        address   192.168.1.12:7789;
        meta-disk internal;
    }
}

Protocol C means a write is acknowledged to the application only after the data has been written to disk on both nodes, guaranteeing zero data loss on failover. Protocol A (asynchronous) offers higher write throughput but may lose in-flight writes.

Step 3 — Initialise Metadata and Start DRBD

Metadata must be initialised on both nodes before the resource can be started. This writes DRBD’s internal bookkeeping area to the end of the disk.

# Run on BOTH nodes
sudo drbdadm create-md myresource

# Start the resource on both nodes
sudo drbdadm up myresource

# Enable DRBD service to start on boot
sudo systemctl enable --now drbd

Step 4 — Promote node1 to Primary and Force Initial Sync

Initially neither node is primary. Designate node1 as primary and instruct it to overwrite node2‘s data with its own (necessary because both disks start with unknown/random content).

# Run ONLY on node1
sudo drbdadm -- --overwrite-data-of-peer primary myresource

# Monitor sync progress (watch the sync percentage)
watch -n 2 cat /proc/drbd

# Example /proc/drbd output during sync:
# 1: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent
#    [=========>..........] sync'ed: 48.5% (52428/102400)K

Wait until the sync percentage reaches 100% and the disk state on both nodes shows UpToDate/UpToDate before creating a filesystem.

Step 5 — Create a Filesystem and Mount on the Primary

The DRBD device /dev/drbd0 is only writable on the primary node. Create the filesystem once and mount it.

# On node1 only — create the filesystem
sudo mkfs.xfs /dev/drbd0

# Mount the filesystem
sudo mkdir -p /mnt/drbd
sudo mount /dev/drbd0 /mnt/drbd

# Verify
df -h /mnt/drbd

Step 6 — Switch the Primary Role to node2

To simulate a failover or perform planned maintenance, demote node1 and promote node2. In a Pacemaker cluster this is automated; here it is done manually.

# On node1 — unmount and demote
sudo umount /mnt/drbd
sudo drbdadm secondary myresource

# On node2 — promote and mount
sudo drbdadm primary myresource
sudo mkdir -p /mnt/drbd
sudo mount /dev/drbd0 /mnt/drbd

# Confirm role change
cat /proc/drbd
# Expected: ro:Secondary/Primary on node1, ro:Primary/Secondary on node2

Conclusion

You have set up a fully functional DRBD replicated block device on RHEL 9, covering package installation, resource configuration, metadata initialisation, initial synchronisation, filesystem creation, and manual role switching. With protocol C replication, your data is protected against single-node failure with zero data loss. The logical next step is to integrate this DRBD resource into a Pacemaker/Corosync cluster so that role promotion and service failover happen automatically when a node becomes unavailable.

Next steps: How to Configure Pacemaker and Corosync on RHEL 9, How to Use Bacula for Enterprise Backup on RHEL 9, and How to Manage Disk Encryption with LUKS and cryptsetup on RHEL 9.