How to setup a Network RAID aka Distributed Replicated Block Device [DRBD]

Tags: block devicedrbdhard diskslogical volumesmirroringpartitionsRAID devicesreplicationStorage

Published on: November 22, 2012 by Scott S

How to setup a Network RAID aka Distributed Replicated Block Device [DRBD]


Distributed Replicated Block Device (DRBD)  or network raid mirrors block devices between multiple hosts. A block device is the type of device used to represent storage in the Linux Kernel. All physical disk devices present a block device interface. DRBD mirrors a partition between two machines allowing only one of them to mount it at a time.  The replication is transparent to other applications on the host systems. Any block device hard disks, partitions, RAID devices, logical volumes, etc can be mirrored. DRBD currently supports all the major flavors of Linux and comes bundled in several major Linux distributions. DRBD is licensed under the GPL. DRBD is one of the most commonly used mirroring technique in industries\Organizations.

Here I’m configuring DRBD between two block devices /dev/sda1 and /dev/sda2 for two hosts with hostname and respectively having Ext4 file system. The partition size is not particularly relevant, but both partitions need to be the same size. To get started using DRBD, first, install the necessary packages on both hosts.

From a Linux terminal enter:

root@sage1:]# sudo apt-get install drbd8-utils
root@sage2:]# sudo apt-get install drbd8-utils

[Note that I’m installing drbd8-utils package on both the hosts]

If you are using the virtual kernel as part of a virtual machine you will need to manually compile the DRBD module. It will be easier to install the Linux-server package inside the virtual machine.


Make sure that the two hosts have name resolution configured either through DNS or the /etc/hosts file.

To configure DRBD, on the first host ( edit /etc/drbd.conf:

root@sage1:]# vi /etc/drbd.conf

include “drbd.d/global_common.conf”;
include “drbd.d/*.res”;

resource r0 {
protocol C;
startup {
wfc-timeout 15;
degr-wfc-timeout 60;
net {
cram-hmac-alg sha1;
shared-secret “secret”;
max-buffers 8000;
max-epoch-size 8000;
sndbuf-size 0;
on {
device /dev/drbd0;
disk /dev/sda1;
meta-disk internal;
on {
device /dev/drbd0;
disk /dev/sda2;
address 192.168.1.yyy:7788;
meta-disk internal;


As you can see in the above configuration that the mirroring is configured between the block device /dev/sda1 of and /dev/sda2 of Here, device file  /dev/drbd0 is the DRBD block device.

There are many other options/configurations in /etc/drbd.conf, but for this example their default values are fine.

Now copy /etc/drbd.conf to our second host sage2.supportsages:

root@sage1:]# scp /etc/drbd.conf root@192.168.1.yyy:/etc/

Now using the drbdadm utility initialize the meta data storage. On each server execute:

root@sage1:]# drbdadm create-md r0
root@sage2:]# drbdadm create-md r0

Next, on both hosts, start the drbd daemon:

root@sage1:]# /etc/init.d/drbd start
root@sage2:]# /etc/init.d/drbd start

On, or whichever host you wish to be the primary, enter the following:

root@sage1:]# drbdadm — –overwrite-data-of-peer primary all

After executing the above command, the data will start syncing with the secondary host. To watch the progress, on drbd02 enter the following:

root@sage1:]# watch -n1 cat /proc/drbd

To stop watching the output press Ctrl+c.

Now that we have a working DRBD. Its time we mount the DRBD block device to a partition and see if the mirroring is fine.

For that add a filesystem to /dev/drbd0 and mount it:
root@sage1:]# mkfs.ext4 /dev/drbd0
root@sage1:]# mount /dev/drbd0 /home


To test that the data is actually syncing between the hosts copy some files on the, the primary, to /home:

root@sage1:]# cp -r /etc/default /home

Next, unmount /home:

root@sage1:]# umount /home

Demote the primary server to the secondary role because DRBD mirrors a partition between two machines allowing only one of them to mount it at a time.

root@sage1:]# drbdadm secondary r0

Now on the secondary server( promote it to the primary role:

root@sage1:]# drbdadm primary r0

Lastly, mount the partition:

root@sage2:]# mount /dev/drbd0 /home

Using ls(list) command you should see /home/default copied from the former primary host to the current primary

For advanced building, installing and configuring DRBD follow .

Category : General, Howtos, Linux, Special Offers, VPS

[easy-social-share counters=0]
Scott S

Scott S

Scott follows his heart and enjoys design and implementation of advanced, sophisticated enterprise solutions. His never ending passion towards technological advancements, unyielding affinity to perfection and excitement in exploration of new areas, helps him to be on the top of everything he is involved with. This amateur bike stunting expert probably loves cars and bikes much more than his family. He currently spearheads the Enterprise Solutions and Infrastructure Consultancy wing of SupportSages.

You may also read:


Add new commentSIGN IN

Let's Connect


Your Cart

ZPanel migration support for webhosting accounts
Account Migration - ZPanel to ZPanel Migration
Qty: 1
Expert migration team to outsource your Non-Zpanel to ZPanel migrations.
Account Migration – Non-ZPanel to ZPanel
Qty: 1
ZPanel server migration through migration experts.
Server Migration - ZPanel to ZPanel
Qty: 1
server migrations to ZPanel Severs from non-zpanel servers
Server Migration - ZPanel to Non-Zpanel
Qty: 1
Qty: 1
Live Chat Support Team - Sales
Qty: 1
Live Chat Support Team - Billing
Qty: 1
24/7 Sales and Billing support through dedicated sales and billing team
Dedicated Team plan - Sales/Billing
Qty: 1
level2 dedicated night shift support
Dedicated Night Shift Support - Owls
Qty: 1
Shift support for level1 dedicated night shift support
Dedicated Night Shift Support - NightJars
Qty: 1
Four member level3 semi-dedicated technical support team for advanced helpdesk and server adminsitration requirements.
Semi-dedicated Team - Technical - Masters
Qty: 1
level2 semi-dedicated technical support team for dedicated 24/7 server administration and helpdesk support
Semi-dedicated Team- Technical - Abbots
Qty: 1
Choose the number of L1 Soldiers for your team
Qty: 1
Level3 dedicated technical support team for complete hosting support solutions
Dedicated Team - Technical- GrandMasters
Qty: 1
level1 dedicated technical support team
Dedicated Team - Technical -Monks
Qty: 1
Part time graphic designer availability for your custom design requirements
Hire a part time Graphic designer - (4 hours x 22 days)
Qty: 1
A dedicated graphic designer can help you with logo design, website design etc. with high level of professional competency and time bound delivery.
Dedicated Staff - Graphic Designer - (8 hours x 22 days)
Qty: 1
Get a dedicated level3 server administrator for your dedicated server management operations.rver administration and helpdesk support.
Dedicated Staff- Server Admin- Commander
Qty: 1
Dedicated level3E server administrator for escalation support.
Dedicated Staff- Server Admin - Zen Master
Qty: 1
dedicatd level2 server administrrator for sever administration and webhosting support
Dedicated Staff- Server Admin - Warrior
Qty: 1
level1 server administrator for dedicated server administration
Dedicated Staff - Server Admin - Soldier
Qty: 1
VPS node management plan for setting up of VPS node and virtualization assistance.
VPS - Node Management
Qty: 1
VPS live chat for the technical, sales and billing issues for the VPS node and the VPSes hosted on it.
Live Chat - VPS Node
Qty: 1