33.3. Clustered Filesystems and Distributed Locking
A cluster filesystem keeps the shared-block model but removes the single-writer assumption. Every node mounts the same filesystem, and a distributed lock manager decides which node may hold which lock. The filesystem is still backed by one LUN; what changes is that the LUN's metadata is protected by a protocol that all nodes participate in.
33.3.1. GFS2, DLM, and Cluster Membership Dependencies
GFS2 is the cluster filesystem in the Linux kernel that Debian configures with the Distributed Lock Manager (DLM). Its dependencies are not optional:
- Corosync provides cluster membership and messaging.
- DLM (
dlm_controld) runs the lockspace that GFS2 uses. - Pacemaker is not required to mount GFS2, but it is the usual way to order the mount after the cluster and to fence a failed node.
- Fencing is required for a production deployment. Without it, a node that stops responding may still hold locks and may still write when it recovers.
A GFS2 filesystem is formatted with a lock table name of the form
cluster:filesystem. The cluster part must match the Corosync cluster name,
and the filesystem part is a name chosen at format time. The lab's Corosync
cluster is named hacluster, so the lock table is hacluster:shared. A
mismatch is caught at mount time: the mount command fails, and the kernel log
shows dlm cluster name ... does not match the application cluster name ...
followed by a dlm_new_lockspace error, even though the block device and the
cluster are both healthy.
Each node that mounts the filesystem needs a journal. mkfs.gfs2 -j reserves
them at format time; adding a node later without a free journal requires
gfs2_jadd. Plan the journal count for the maximum number of simultaneous
mounts, not just the number of hosts currently installed.
33.3.2. Establishing Debian Package and Kernel Support for the Selected Stack
Install the filesystem utilities and the lock manager on every node that will mount the filesystem:
# apt install gfs2-utils dlm-controld
Corosync and Pacemaker come from the cluster stack described in
Chapter 32. On storage2, as john, the
initiator and filesystem stack recorded in the lab is:
$ dpkg-query -W gfs2-utils dlm-controld open-iscsi multipath-tools nfs-kernel-server
dlm-controld 4.3.0-3
gfs2-utils 3.6.1-1
multipath-tools 0.11.1-2
nfs-kernel-server 1:2.8.3-1
open-iscsi 2.1.11-1+deb13u2
The open-iscsi and multipath-tools entries are the initiator packages
from section 33.2; nfs-kernel-server is used by the clustered service in
section 33.7.
The kernel modules are gfs2 and dlm. Debian loads them on demand when the
filesystem is mounted and dlm_controld starts. If a custom kernel omits
them, the mount fails with "unknown filesystem type" or DLM cannot create the
lockspace; use the distribution kernel or enable the modules explicitly.
The lock manager's policy lives in /etc/dlm/dlm.conf. A production cluster
enables fencing and points DLM at the fencing agent used by Pacemaker. The
practice cluster has no out-of-band power control, so it disables fencing to
exercise the locking path without pretending that a failed node was safely
removed:
enable_fencing=0
enable_quorum_fencing=0
On storage2 and storage3, as root, restart DLM after changing the file:
# systemctl restart dlm
The restart normally prints nothing. On each node, confirm the service is active before formatting or mounting:
# systemctl is-active dlm
active
Do not copy this configuration to a production cluster. With fencing disabled,
a node that loses network access can continue writing while the surviving
nodes believe it is gone. The result is filesystem corruption that no amount
of fsck.gfs2 can reliably repair.
33.3.3. Creating and Mounting a Disposable Shared Filesystem
The second iSCSI LUN, /dev/mapper/cluster-lun, is the shared device. Create
a GFS2 filesystem on it from one node. The mkfs.gfs2 options used are:
| Option | Description |
|---|---|
-O |
answer the overwrite confirmation without prompting |
-p lock_dlm |
select the DLM locking protocol |
-t cluster:filesystem |
name the lock table |
-j 2 |
reserve two journals for the two mounting nodes |
On storage2, as root, create the filesystem:
# mkfs.gfs2 -O -p lock_dlm -t hacluster:shared -j 2 /dev/mapper/cluster-lun
/dev/mapper/cluster-lun is a symbolic link to /dev/dm-1
This will destroy any data on /dev/dm-1
Discarding device contents (may take a while on large devices): Done
Adding journals: Done
Building resource groups: Done
Creating quota file: Done
Writing superblock and syncing: Done
Device: /dev/mapper/cluster-lun
Block size: 4096
Device size: 1.00 GB (262144 blocks)
Filesystem size: 1.00 GB (262142 blocks)
Journals: 2
Journal size: 16MB
Resource groups: 6
Locking protocol: "lock_dlm"
Lock table: "hacluster:shared"
UUID: 2f6e4514-c50e-4dc4-940a-031384c58457
The output confirms the lock table and the journal count. The filesystem is
not mounted yet. On storage2, as root, mount it and inspect both the mount
and the DLM lockspace:
# mkdir -p /srv/shared
The command normally prints nothing. Mount the filesystem:
# mount -t gfs2 -o noatime /dev/mapper/cluster-lun /srv/shared
The mount normally prints nothing. Confirm it:
# findmnt /srv/shared
TARGET SOURCE FSTYPE OPTIONS
/srv/shared /dev/mapper/cluster-lun gfs2 rw,noatime,rgrplvb
Inspect the DLM lockspace:
# dlm_tool ls
dlm lockspaces
name shared
id 0xa98de676
flags 0x00000000
change member 1 joined 1 remove 0 failed 0 seq 1,1
members 2
dlm_tool ls shows the lockspace named shared (the part after the colon in
the lock table) and two members: the node that mounted and the other cluster
node that has joined the lockspace. The member count can reach two before the
second filesystem mount because DLM membership and filesystem mount are
separate steps.
On storage3, as root, mount the same filesystem on the second node:
# mkdir -p /srv/shared
The command normally prints nothing. Mount the filesystem:
# mount -t gfs2 -o noatime /dev/mapper/cluster-lun /srv/shared
The mount normally prints nothing. Confirm it:
# findmnt /srv/shared
TARGET SOURCE FSTYPE OPTIONS
/srv/shared /dev/mapper/cluster-lun gfs2 rw,noatime,rgrplvb
Both nodes now have the same filesystem mounted read-write. This is the point at which an ordinary ext4 filesystem would already be unsafe. GFS2 is safe only because DLM is running on both nodes and both mounts joined the same lockspace.
33.3.4. Concurrent Access, Lock Recovery, and Fencing Tests
A simple append test shows that both nodes can write the same file without
losing each other's data. On storage2, as root, create 100 lines:
# seq 1 100 | sed 's/^/storage2-/' >> /srv/shared/concurrent.txt
The pipeline normally prints nothing because it writes to the file. Count the lines:
# wc -l /srv/shared/concurrent.txt
100 /srv/shared/concurrent.txt
The pipeline has two stages: seq generates the numbers and sed prefixes
each line. The >> opens the file in append mode, so the writes go to the end
of the current file rather than replacing it. On storage3, as root, append
another 100 lines:
# seq 1 100 | sed 's/^/storage3-/' >> /srv/shared/concurrent.txt
The pipeline normally prints nothing. Count the lines from this node:
# wc -l /srv/shared/concurrent.txt
200 /srv/shared/concurrent.txt
On storage2, as root, count each prefix:
# grep -c storage2 /srv/shared/concurrent.txt
100
# grep -c storage3 /srv/shared/concurrent.txt
100
Both sets are intact. This demonstrates that the locks serialized the appends for this workload; it is not a claim that every multi-block write is atomic. Applications that need transactional semantics still need their own locking or a database.
GFS2 also carries POSIX advisory locks across nodes. On storage2, as root,
hold a lock in one shell:
# flock /srv/shared/gfs2.lock sleep 300
The command blocks until the sleep ends or you press Ctrl-C; the lock is held
for that whole time. In a second root shell on storage3, try a non-blocking
lock:
# flock -n /srv/shared/gfs2.lock echo acquired-on-storage3
The command prints nothing and exits with status 1 because the lock is held by
the other node. flock without -n would wait. This is the behavior an
application expects from a local filesystem, extended across the cluster by
DLM.
A graceful leave is the safe way to remove a node. On storage3, as root,
unmount the filesystem and stop DLM:
# umount /srv/shared
The command normally prints nothing. Stop DLM:
# systemctl stop dlm
The unmount releases the node's locks and journals cleanly. On storage2, as
root, the surviving node can continue writing:
# echo after-storage3-left >> /srv/shared/concurrent.txt
The write normally prints nothing. Read the last line:
# tail -1 /srv/shared/concurrent.txt
after-storage3-left
Start DLM and mount again on storage3; the data written while it was away is
visible:
# systemctl start dlm
The start normally prints nothing. Mount the filesystem again:
# mount -t gfs2 -o noatime /dev/mapper/cluster-lun /srv/shared
The mount normally prints nothing. Read the last line:
# tail -1 /srv/shared/concurrent.txt
after-storage3-left
A crash is not a graceful leave. If storage3 had failed while holding locks,
the cluster would have to fence it before storage2 could recover those locks.
Without fencing, the surviving node cannot distinguish a dead peer from a
partitioned one, and the safe action is to stop rather than risk two writers.
This is why section 33.3.2 insists on fencing for production.
33.3.5. OCFS2 Architecture, Availability, and Selection Tradeoffs
OCFS2 is the other cluster filesystem available for Debian. It was originally
developed for Oracle workloads but is a general-purpose cluster filesystem.
Its default cluster stack is o2cb, an in-kernel stack with a node manager
(o2nm), a disk heartbeat agent (o2hb), a network agent (o2net), and a
distributed lock manager (o2dlm). Configuration lives in
/etc/ocfs2/cluster.conf, and the cluster is brought online with the o2cb
service. OCFS2 can also use Pacemaker as its cluster stack, but the o2cb path
is self-contained and does not require Corosync.
On storage1, as john, the Debian package is available:
$ apt-cache policy ocfs2-tools
ocfs2-tools:
Installed: (none)
Candidate: 1.8.8-3
Version table:
1.8.8-3 500
500 https://deb.debian.org/debian trixie/main amd64 Packages
mkfs.ocfs2 creates the filesystem, o2cb manages the cluster, and
mount.ocfs2 mounts it. On one node, as root, a reference format command
(not run in this walkthrough) names the cluster stack, the cluster, and the
number of node slots:
# mkfs.ocfs2 --cluster-stack=o2cb --cluster-name=hacluster \
--fs-feature-level=max-features -N 2 /dev/mapper/cluster-lun
The -N value reserves node slots; like GFS2 journals, they must be planned
before the cluster grows. OCFS2's heartbeat is on-disk by default, which keeps
the setup simple for a small number of mounts; global heartbeat is recommended
when a host mounts many OCFS2 filesystems.
| Criterion | GFS2 | OCFS2 |
|---|---|---|
| Cluster and lock stack | Corosync plus DLM, usually Pacemaker-managed | o2cb by default (o2nm, o2hb, o2net, o2dlm); Pacemaker optional |
| Debian packages | gfs2-utils, dlm-controld |
ocfs2-tools |
| Format and mount tools | mkfs.gfs2, mount -t gfs2 |
mkfs.ocfs2, mount -t ocfs2 |
| Node slots | one journal per mounting node; add with gfs2_jadd |
node slots reserved at format time with -N |
| Online growth | gfs2_grow on a mounted filesystem |
tunefs.ocfs2 -S on a mounted filesystem |
| Failure detection | DLM plus cluster quorum and fencing | o2cb heartbeat plus fencing, or Pacemaker |
| Operational fit | natural companion to the Corosync/Pacemaker stack in this book | self-contained cluster stack; common in Oracle estates |
| Main tradeoff | one more stack to integrate with Pacemaker, but consistent with Chapters 31 and 32 | fewer moving parts outside Pacemaker, but a separate cluster configuration to learn and maintain |
Neither filesystem is a general replacement for Ceph or NFS. Both require a shared LUN, both need fencing, and both put lock traffic on the network. Choose GFS2 when the cluster already runs Corosync and Pacemaker and you want one membership model; choose OCFS2 when the o2cb stack is already established or an application is certified for it. For a new Debian deployment without an existing OCFS2 estate, GFS2 is the simpler operational match for the rest of this book's cluster tooling.