Automatically Mount a DRBD Device at Boot

There might be occasions where it is required to mount the DRBD® device at boot outside of a cluster resource manager (CRM) such as Pacemaker or DRBD Reactor. You can accomplish this using systemd.

In this example you will mount the DRBD resource r0 with a device path of /dev/drbd0 at the mount point /mnt/drbd/r0 at boot.

Use the templated systemd unit file to enable the r0 resource to start at boot:

systemctl enable drbd@r0.target

It is usually a good idea to wait for DRBD to connect to its peers before promoting a resource to primary status on a node. To do this, you should also enable the templated drbd-wait-promotable systemd unit for the r0 resource.

systemctl enable drbd-wait-promotable@r0.service

Create a systemd unit file named /etc/systemd/system/mnt-drbd-r0.mount. You must name the unit file with the mount path as the name, substituting dashes for slashes. The contents of this unit file should look similar to the example below:

[Unit]
Description=Mount DRBD device
After=network.target
After=drbd@r0.target

[Mount]
What=/dev/drbd0
Where=/mnt/drbd/r0
Type=xfs
Options=defaults


[Install]
WantedBy=multi-user.target

Lastly, verify that you have enabled DRBD and this custom systemd unit at boot.

 # systemctl daemon-reload # systemctl enable mnt-drbd-r0.mount
Using an fstab Entry to Mount a DRBD Device

Rather than using systemd to mount the /dev/drbd0 device on /mnt/drbd/r0, you can instead use /etc/fstab. An example /etc/fstab entry should look similar to this:

/dev/drbd1000 /mnt/drbd/r0 ext4 defaults,_netdev,x-systemd.requires=drbd@r0.target 0 0

Reviewed 2024/06/11 – MDK