33.7. Practical Lab: Recovering a Clustered File Service

The final exercise combines the ownership rules from the first sections with a real clustered service. Two nodes replicate a block device with DRBD, Pacemaker owns the DRBD promotion, the filesystem mount, the NFS export, and a virtual address as one group, and an independent client mounts the virtual address. The client writes while a link fails, then reconnects after the resource group moves, and the service is restored from a backup taken on the client.

Chapter 31 explains DRBD replication and Chapter 32 builds the Corosync/Pacemaker cluster and the same NFS resource pattern in more detail. This lab assumes that cluster is running and concentrates on the storage behavior under failure.

33.7.1. Preparing Cluster Nodes, a Witness, Independent File Clients, and Disposable Data Devices

The storage nodes are storage2 and storage3. Each has a disposable 1 GiB virtio disk at /dev/vdb for DRBD and a 2 GiB disk at /dev/vdc for the Ceph OSD; the DRBD exercise never touches /dev/vdc. storage1 is a Corosync member and the quorum tiebreaker; it does not run the NFS resource. client1 is the independent NFS client, and witness1 runs the Corosync QDevice service. With three voting nodes the cluster already keeps quorum with one node down; the witness matters when the cluster is reduced to two nodes or when a two-node pair needs a tiebreaker.

Install the packages on storage2 and storage3, as root:

# apt install drbd-utils pacemaker corosync crmsh resource-agents nfs-kernel-server nftables

On storage2, as john, the DRBD tools recorded on the node are:

$ dpkg-query -W drbd-utils
drbd-utils  9.22.0-1.1

The rest of the stack is the one inventoried in section 33.2.1 and section 33.3.2: pacemaker 3.0.0-2, corosync 3.1.9-2+deb13u1, crmsh 5.0.0~rc1-1, nfs-kernel-server 1:2.8.3-1, and nftables 1.1.3-1.

DRBD's kernel module loads on the first drbdadm operation. The cluster membership, QDevice, and fencing configuration are the ones from Chapter 32. On storage1, as john, confirm the cluster is healthy before adding storage resources: sudo crm status must show all three nodes online, a designated coordinator, and partition with quorum, as in the status captures of Chapter 32; only the node names differ here. If a node is offline, fix membership before creating the DRBD resource; a cluster without quorum is not a safe place to test storage failover.

A fresh cluster has no resources. If you are re-running this lab on hosts that still carry the previous run's configuration, stop its resources and erase that configuration first: crm configure refuses to create p_drbd, ms_drbd, and g_nfs again, and the erase itself is refused while a resource is running. On storage1, as john, stop the group and the DRBD clone:

$ sudo crm resource stop g_nfs

The command normally prints nothing. Stop the clone as well:

$ sudo crm resource stop ms_drbd

It also prints nothing. A stop asks Pacemaker to bring the resource down wherever it runs: the group unmounts /srv/nfs, removes the export and the virtual address, and the clone demotes DRBD and takes it down. Give the stops a few seconds, then confirm that nothing is left running before erasing:

$ sudo crm status
Cluster Summary:
  * Stack: corosync (Pacemaker is running)
  * Current DC: storage1 (version 3.0.0-3.0.0) - partition with quorum
  * 3 nodes configured
  * 5 resource instances configured (5 DISABLED)

Node List:
  * Online: [ storage1 storage2 storage3 ]

Full List of Resources:
  * Clone Set: ms_drbd [p_drbd] (promotable, disabled):
    * Stopped (disabled): [ storage1 storage2 storage3 ]
  * Resource Group: g_nfs (disabled):
    * p_nfsfs   (ocf:heartbeat:Filesystem):  Stopped (disabled)
    * p_export  (ocf:heartbeat:exportfs):    Stopped (disabled)
    * p_nfsip   (ocf:heartbeat:IPaddr2):     Stopped (disabled)

Selected output; the timestamps and status details are omitted. The (disabled) marker is crmsh's name for the target-role value Pacemaker sets when you stop a resource; it disappears with the configuration in the next step. Save the following as ~/debian-handbook/shared-storage/reset-cib.txt on storage1:

erase
property stonith-enabled=false
commit
quit

On storage1, as john, load it:

$ sudo crm configure < ~/debian-handbook/shared-storage/reset-cib.txt
INFO: modified colocation:c_nfs_on_drbd from ms_drbd to p_drbd
INFO: modified order:o_drbd_then_nfs from ms_drbd to p_drbd
INFO: modified location:l_drbd_not_st1 from ms_drbd to p_drbd
(unpack_config)     warning: Blind faith: not fencing unseen nodes

The INFO lines are printed while the erase removes the constraints that referenced the clone; crmsh colors them green on a color terminal, and the same one-line style appears for other crm status messages. The warning is the fencing compromise discussed in section 33.1.3, which the property line restores. The erase is immediate and there is no undo: a sudo crm status afterwards reports 0 resource instances configured and no resources, and the cluster is ready for the lab again.

The DRBD resource file is shared content, with only the node name, device, disk, and address changing per host. Put /etc/drbd.d/nfsdata.res on both storage nodes:

resource nfsdata {
    protocol C;

    startup {
        wfc-timeout 15;
        degr-wfc-timeout 15;
    }

    disk {
        on-io-error detach;
        resync-rate 100M;
    }

    net {
        cram-hmac-alg sha256;
        shared-secret "handbook-nfs-secret";
        after-sb-0pri discard-zero-changes;
        after-sb-1pri discard-secondary;
        after-sb-2pri disconnect;
    }

    on storage2 {
        device /dev/drbd0;
        disk /dev/vdb;
        address 192.168.235.12:7789;
        meta-disk internal;
    }

    on storage3 {
        device /dev/drbd0;
        disk /dev/vdb;
        address 192.168.235.13:7789;
        meta-disk internal;
    }
}

The on blocks are the per-node values. protocol C waits for the peer's write acknowledgment before acknowledging the application, which is the strongest and slowest mode. cram-hmac-alg and shared-secret authenticate the peers; the secret must match and must be protected. The split-brain policies are a deliberate choice: discard changes only when one side is known to be empty, discard the secondary when there is a clear primary, and disconnect otherwise. Section 31.4 explains the alternatives.

33.7.2. Deploying the DRBD and Pacemaker NFS Reference Configuration

Initialize the metadata on the disposable disks. --force is required here because the practice disks may contain old signatures; in production, verify that the device is the intended one before forcing. On storage2, as root:

# drbdadm create-md --force nfsdata
md_offset 1073737728
al_offset 1073704960
bm_offset 1073672192

Found some data

 ==> This might destroy existing data! <==
initializing activity log
Writing meta data...
New drbd meta data block successfully created.


Do you want to proceed?
*** confirmation forced via --force option ***
initializing bitmap (32 KB) to all zero

The offsets show where DRBD places its internal metadata, at the end of the backing device. --force answers the confirmation prompt. On storage2, as root, bring up the resource:

# drbdadm up nfsdata

The command normally prints nothing. Check the resource:

# drbdadm status nfsdata
nfsdata role:Secondary
  disk:Inconsistent
  peer connection:Connecting

The resource is Secondary with an Inconsistent disk because no initial synchronization has run yet, and the peer connection is still Connecting because storage3 has not brought the resource up. Run the same metadata initialization on storage3, as root:

# drbdadm create-md --force nfsdata
md_offset 1073737728
al_offset 1073704960
bm_offset 1073672192

Found some data

 ==> This might destroy existing data! <==
initializing activity log
Writing meta data...
New drbd meta data block successfully created.


Do you want to proceed?
*** confirmation forced via --force option ***
initializing bitmap (32 KB) to all zero

In this run storage3's disk reported the same "Found some data" as storage2's. What the probe reports depends on what the device last held: on a re-used practice disk that still carries an old filesystem signature and DRBD metadata, create-md instead reports both, warns that a metadata block appears to be already in place, and asks for confirmation twice. Read those questions literally on a production disk and stop if the reported contents are unexpected. Then bring the resource up on storage3, as root:

# drbdadm up nfsdata

The command normally prints nothing. The two peers now connect on TCP 7789 and form a replication pair; both sides remain Secondary, and the connection stays in an unfinished state until the first promotion runs the initial synchronization. On storage2, as root, promote one side, create the filesystem once, and return it to secondary so Pacemaker can control promotion:

# drbdadm primary --force nfsdata

The promotion normally prints nothing; it also starts the initial synchronization from storage2's disk to the empty peer. Create the filesystem once:

# mkfs.ext4 -F -L nfsdata /dev/drbd0
Discarding device blocks:      0/262127             done                            
Creating filesystem with 262127 4k blocks and 65536 inodes
Filesystem UUID: 63bf77c3-6a25-4f1b-9beb-6e41e9e7e9ae
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376

Allocating group tables: 0/8       done                            
Writing inode tables: 0/8       done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: 0/8   done

The command also prints the mke2fs 1.47.2 (1-Jan-2025) version banner on standard error before the progress output. The device has 262127 blocks rather than the backing disk's 262144 because DRBD reserves the end of the device for its internal metadata. The label nfsdata is the only filesystem-level identity the service needs. Return the resource to secondary:

# drbdadm secondary nfsdata

The demotion normally prints nothing. The resource is ready but unmounted, and the initial synchronization continues in the background; the status capture after the link-failure test in section 33.7.3 shows the pair with both disks UpToDate. On storage2 and storage3, as root, create /srv/nfs and start the NFS server:

# mkdir -p /srv/nfs

The command normally prints nothing. Start and enable the NFS server:

# systemctl enable --now nfs-server

On a host where the unit was not enabled before, systemctl creates and prints the multi-user.target symlink for the service; on the practice hosts the unit was already enabled, so the command printed nothing. Either way the NFS server is running afterwards.

The Pacemaker configuration is a single resource group with a promotable DRBD clone. The group contains the filesystem, the export, and the virtual address; the colocation and order constraints make the group start only on the promoted DRBD node, in the right sequence. Save this as a file and load it with crm configure:

property stonith-enabled=false
primitive p_drbd ocf:linbit:drbd params drbd_resource=nfsdata op monitor interval=15 timeout=30 role=Promoted op monitor interval=30 timeout=30 role=Unpromoted
clone ms_drbd p_drbd meta promotable=true promoted-max=1 promoted-node-max=1 clone-max=2 clone-node-max=1 notify=true
primitive p_nfsfs ocf:heartbeat:Filesystem params device=/dev/drbd0 directory=/srv/nfs fstype=ext4 op monitor interval=20 timeout=60
primitive p_export ocf:heartbeat:exportfs params clientspec=192.168.234.0/24 options=rw,sync,no_subtree_check,no_root_squash,fsid=0 directory=/srv/nfs
primitive p_nfsip ocf:heartbeat:IPaddr2 params ip=192.168.234.100 cidr_netmask=24 nic=eth1
group g_nfs p_nfsfs p_export p_nfsip
colocation c_nfs_on_drbd inf: g_nfs ms_drbd:Promoted
order o_drbd_then_nfs inf: ms_drbd:promote g_nfs:start
location l_drbd_not_st1 ms_drbd -inf: storage1
commit
quit

Create the file as ~/debian-handbook/shared-storage/nfs-crm.txt on storage1. stonith-enabled=false is the lab compromise discussed in section 33.1.3. A production version replaces it with a real fencing device and removes the location constraint if storage1 is a valid storage node. The location constraint keeps the DRBD clone off the quorum-only node, which has no /dev/vdb for this resource.

On storage1, as john, load the configuration:

$ sudo crm configure < ~/debian-handbook/shared-storage/nfs-crm.txt
(unpack_config)     warning: Blind faith: not fencing unseen nodes

The warning is the fencing compromise from section 33.1.3, printed when Pacemaker commits a configuration with STONITH disabled; crmsh colors it like the messages in section 33.7.1, and the configuration is committed anyway. On storage1, as john, check the group:

$ sudo crm status
Cluster Summary:
  * Stack: unknown (Pacemaker is running)
  * Current DC: storage1 (version unknown) - partition with quorum
  * 3 nodes configured
  * 5 resource instances configured

Node List:
  * Online: [ storage1 storage2 storage3 ]

Full List of Resources:
  * Clone Set: ms_drbd [p_drbd] (promotable):
    * Promoted: [ storage2 ]
    * Unpromoted: [ storage3 ]
  * Resource Group: g_nfs:
    * p_nfsfs   (ocf:heartbeat:Filesystem):  Started storage2
    * p_export  (ocf:heartbeat:exportfs):    Started storage2
    * p_nfsip   (ocf:heartbeat:IPaddr2):     Started storage2

Selected output; the timestamps and status details are omitted. Pacemaker promoted storage2, mounted /dev/drbd0 on /srv/nfs, started the export, and brought up the virtual address. The order is visible in the resource list: the filesystem, then the export, then the address. On client1, as john, mount the virtual address, not either node's physical address:

$ sudo mkdir -p /mnt/nfs

The command normally prints nothing. Mount the virtual address:

$ sudo mount -t nfs 192.168.234.100:/ /mnt/nfs

The mount normally prints nothing. Write a file:

$ sudo sh -c 'echo nfs-client-data > /mnt/nfs/nfs-file.txt'

The write normally prints nothing. Read it back:

$ cat /mnt/nfs/nfs-file.txt
nfs-client-data

The kernel client negotiates NFSv4 over TCP and mounts hard by default; a findmnt /mnt/nfs on the client shows vers=4.2, proto=tcp, hard, timeo=600, and retrans=2. The hard behavior means the client retries indefinitely rather than returning an I/O error when the server stops answering; that is appropriate for a service that is expected to fail over, but it also means an application can hang if the service never returns. Use soft with a bounded timeo only when the application can handle I/O errors; the NFS mount options are covered in Chapter 21.

The first failure is a replication link loss. The client still talks to the promoted node over eth1; only the DRBD traffic on eth2 is dropped. Create the following script as ~/debian-handbook/shared-storage/block-drbd.sh on both storage nodes and make it executable with chmod +x; it installs the drop rules:

#!/bin/sh
# Block DRBD replication between the two storage nodes.
peer="$1"
nft add table inet drbdblock
nft 'add chain inet drbdblock input { type filter hook input priority 0; }'
nft 'add chain inet drbdblock output { type filter hook output priority 0; }'
nft add rule inet drbdblock input ip saddr "$peer" tcp dport 7789 drop
nft add rule inet drbdblock output ip daddr "$peer" tcp dport 7789 drop

The script takes the peer's cluster-network address as its only argument. On storage2, as root, run it with storage3's address; the absolute path matters because a root shell's ~ is not john's home directory:

# /home/john/debian-handbook/shared-storage/block-drbd.sh 192.168.235.13

The command normally prints nothing. On storage3, as root, run it with storage2's address:

# /home/john/debian-handbook/shared-storage/block-drbd.sh 192.168.235.12

The script creates a dedicated nft table, so the cleanup is a single nft delete table inet drbdblock and does not disturb other firewall rules. On storage2, as john, the DRBD resource on the primary reports a disconnected peer:

$ sudo drbdadm status nfsdata
nfsdata role:Primary
  disk:UpToDate
  peer connection:Connecting

The client is still writing through the primary's local disk. On client1, as john, the write succeeds because the NFS server does not need the peer to acknowledge while DRBD is in this state:

$ sudo sh -c 'echo during-link-failure >> /mnt/nfs/nfs-file.txt'

The write normally prints nothing. Read the last two lines:

$ tail -2 /mnt/nfs/nfs-file.txt
nfs-client-data
during-link-failure

The file shows both writes, including the one made while the replication link was down; only the replica fell behind, not the primary's service. On both storage nodes, as root, remove the rules:

# nft delete table inet drbdblock

The command normally prints nothing on each node. The peers reconnect and resynchronize. On storage2, as john, the primary reports Established again with both disks UpToDate:

$ sudo drbdadm status nfsdata
nfsdata role:Primary
  disk:UpToDate
  peer role:Secondary
    replication:Established peer-disk:UpToDate

The second failure is a planned node loss. On client1, as john, unmount the client while the virtual address moves, because the address disappears from the old owner and the client's NFS mount would otherwise wait on a dead server:

$ sudo umount /mnt/nfs

On storage1, as john, put storage2 in standby:

$ sudo crm node standby storage2
INFO: standby node storage2

The one-line confirmation is the crmsh status style from section 33.7.1. Pacemaker demotes the DRBD resource, promotes storage3, mounts the filesystem there, starts the export, and moves the virtual address. On storage1, as john, check the result:

$ sudo crm status
Cluster Summary:
  * Stack: corosync (Pacemaker is running)
  * Current DC: storage1 (version 3.0.0-3.0.0) - partition with quorum
  * 3 nodes configured
  * 5 resource instances configured

Node List:
  * Node storage2: standby
  * Online: [ storage1 storage3 ]

Full List of Resources:
  * Clone Set: ms_drbd [p_drbd] (promotable):
    * Promoted: [ storage3 ]
    * Stopped: [ storage1 storage2 ]
  * Resource Group: g_nfs:
    * p_nfsfs   (ocf:heartbeat:Filesystem):  Started storage3
    * p_export  (ocf:heartbeat:exportfs):    Started storage3
    * p_nfsip   (ocf:heartbeat:IPaddr2):     Started storage3

Selected output; the timestamps and status details are omitted. On client1, as john, mount the client again at the same address and continue writing:

$ sudo mount -t nfs 192.168.234.100:/ /mnt/nfs

The mount normally prints nothing. Read the last line written by the old owner:

$ tail -1 /mnt/nfs/nfs-file.txt
during-link-failure

Write a new line:

$ sudo sh -c 'echo after-failover >> /mnt/nfs/nfs-file.txt'

The write normally prints nothing. Read the last two lines:

$ tail -2 /mnt/nfs/nfs-file.txt
during-link-failure
after-failover

NFS resource failover

Figure 33.5. The DRBD promotion, filesystem mount, export, and virtual address move as one ordered resource group. The client remounts the same address; it does not need to know which storage node owns the data.

The new owner served the file written by the old owner, including the write made during the link failure. That is the DRBD resynchronization working: the new primary had the data before it was promoted. If the old primary had been unreachable rather than gracefully demoted, the cluster would need fencing before allowing the promotion; otherwise the two primaries could both accept writes.

Locks explain the client policy. This lab's export uses the exportfs agent with fsid=0: the export identity is stable whichever node serves it, but the agent does not mask the NFSv4 server-owner string, which is derived from the node's hostname. A client that held NFSv4 state (open files or locks) through the move would therefore face a server that looks like a different machine, and its state would not be reclaimable. That is why the walkthrough unmounts before the move and remounts after it, rather than waiting on the old address: the design trades in-place state recovery for a simpler agent. Applications that must keep NFSv4 locks across a failover need the server-scope design and grace-period behavior covered in Chapter 32.

On storage1, as john, bring storage2 back online:

$ sudo crm node online storage2
INFO: online node storage2

The one-line status message is the same crmsh style as the erase output in section 33.7.1. The resource group does not automatically move back because no failback rule is configured; that is usually the right choice for a storage service, where repeated moves cost more than they gain.

33.7.4. Checking Exclusive Ownership, File Integrity, Metadata, and Recovery Time

Exclusive ownership has two observable parts: Pacemaker reports exactly one promoted DRBD node, and exactly one node has the filesystem mounted. On storage3, as john, check the DRBD role after storage2 has come back online:

$ sudo drbdadm status nfsdata
nfsdata role:Primary
  disk:UpToDate
  peer connection:Connecting

storage3 still holds the Primary role it received during the failover, and the returned storage2 is Secondary; exactly one node may serve the filesystem. The Connecting state was captured seconds after storage2 came back online: the peers are still establishing their connection, and once it is up DRBD resynchronizes the regions that changed while the node was away, using the bitmap the primary kept while it was alone. Those rejoin states (SyncSource/SyncTarget and the bitmap waits) are covered in Chapter 31, and the primary keeps serving I/O while they run. If both nodes ever report Primary, stop and investigate before mounting anything; that is a split brain, not a failover.

On client1, as john, record the file's checksum before any further change:

$ sha256sum /mnt/nfs/nfs-file.txt
4d2c30b35b0e0c9e59c51dc0b76dbfe95be784b027dec2f367f5dce83be8748c  /mnt/nfs/nfs-file.txt

The exact digest depends on the lines written in your run. The point is to record it before the restore and compare after. Note the metadata as well: the file is owned by root with mode 644 because it was created by a root shell through the NFS export with no_root_squash, and section 33.7.5 compares both values after the restore. no_root_squash is appropriate only for an export that trusted clients may administer. For ordinary users, remove it and let the NFS server map root to nobody; then the file ownership reflects the client user.

Recovery time is measured from the moment the standby command is issued to the moment the resource group is started on the new node. Poll crm status and watch the DRBD promotion, filesystem mount, and export start in the Pacemaker transition. In the recorded run, the group was started on storage3 about 14 seconds after the standby command. That number belongs to a planned standby with fencing disabled and a 1 GiB device; a power-loss failover adds the fencing device's own delay, and a larger filesystem or a colder cache changes the mount step. Record the time for the service you operate, not a generic number. The client's remount time is separate from the cluster's resource start time, because the client must notice the old address is gone and retry.

33.7.5. Restoring the File Service from an Independent Backup and Extending to Clustered SMB

The backup is taken on the client, not on the storage nodes. A tar archive of the mounted export is independent of the DRBD volume and survives the loss of both storage nodes:

$ sudo tar -C /mnt/nfs -czf ~/debian-handbook/shared-storage/nfs-backup.tar.gz .

The archive command normally prints nothing. Give the archive to john:

$ sudo chown john:john ~/debian-handbook/shared-storage/nfs-backup.tar.gz

The command normally prints nothing. List the archive's first entries:

$ tar -tzf ~/debian-handbook/shared-storage/nfs-backup.tar.gz | head
./
./nfs-file.txt
./.rmtab
./lost+found/

The tar command's -C changes directory before reading, so the archive contains relative paths and can be restored into any mount point. -c creates, -z compresses with gzip, and -f names the archive. The listing confirms the file is present. On the active node (storage3 after the failover), as root, simulate a data loss:

# rm -f /srv/nfs/nfs-file.txt

The remove normally prints nothing. On client1, as john, confirm that the export no longer shows the file:

$ test ! -e /mnt/nfs/nfs-file.txt && echo file-removed
file-removed

The test ! -e succeeds only when the path does not exist; the && operator runs the echo only in that case, so the printed file-removed confirms the loss. With the file still present, the command prints nothing and exits nonzero instead. Restore from the archive on client1, as john:

$ sudo tar -C /mnt/nfs -xzf ~/debian-handbook/shared-storage/nfs-backup.tar.gz

The restore normally prints nothing. Verify the checksum:

$ sha256sum /mnt/nfs/nfs-file.txt
4d2c30b35b0e0c9e59c51dc0b76dbfe95be784b027dec2f367f5dce83be8748c  /mnt/nfs/nfs-file.txt

Verify the metadata:

$ stat -c '%U %G %a %s' /mnt/nfs/nfs-file.txt
root root 644 51

The checksum matches the value recorded before the loss, and the metadata is the expected root root 644 51 from section 33.7.4. The file was restored through the NFS export, so it lives on the DRBD volume again and will replicate to the peer. A real backup procedure also verifies the archive on independent storage and records which snapshot or point in time it represents.

Clustered SMB uses the same ownership pattern with a different service layer. Samba exports the filesystem, and CTDB provides a clustered TDB database, public address management, and service monitoring. CTDB needs a shared filesystem that supports locking and coherent metadata (GFS2 or OCFS2), a set of public addresses it can move between nodes, and a locking or fencing mechanism that prevents two nodes from serving the same public address at once. The DRBD plus Pacemaker group in this lab is not the usual CTDB design: CTDB expects to manage its own public addresses and a shared filesystem mounted on every node, whereas the NFS group mounts the filesystem on one node at a time. Use the CTDB walkthrough in Chapter 32 when the service must be active-active; use the single-owner NFS group here when a single writer is acceptable and simpler to operate.

The recovery checks are the same in either case: confirm that exactly one owner serves each address, read a known file from an independent client, write and read a new file, and compare a checksum or application-level consistency check before returning the service to normal use.