Distributed Replicated Block Device (DRBD)

I cannot be more explicit than the documentation.  But I like to report my own experience:) with DRBD.

If you’re looking for something to copy blindly your partition blocs and synchronize it with another partition without caring about the filesystem and data details, go for DRBD. it’s very cool, easy to implement, just get your disks and your gigabyte ethernet card ready :D.

DRBD stands between the filesystem and I/O scheduler layer of the operating system, thus didn’t care about high level layers like the filesystem. That’s why I said, it copies blindly xd xd.


Depending on your linux distribution, you’ll get DRBD on your server. I did it on CentOS 6.

After having set my ressources, and started DRBD. I faced some difficulties mainly because I didn’t understand how DRBD works!!!

The idea was so simple but look at me, I was so hesitating kinda of couldn’t figure out some so very simple things like:

  • Do not know what to mount: device or disk? /dev/drbd1 or /dev/sda2?

When I needed to mount  my DRBD partition named as in the following configuration code,

resource r0 {
  on node1 {
    device    /dev/drbd1;
    disk      /dev/sda2;
    meta-disk internal;
  on node2 {
    device    /dev/drbd1;
    disk      /dev/sda7;
    meta-disk internal;

I tried:

mount /dev/sda2

Which is so stupid. Wanna know why? We only mount a filesystem to a point of the whole filesystem. Let’s
look at how DRBD sees /dev/sda2. in fact, filesystem or no filesystem on the partition is viewed by DRBD
as just an information about data on the partition. Plus, DRBD needs to store some meta data about the
replicated partition. By defaults, DRBD uses the same partition to save these metadata. So trying to mount
/dev/sda2 is something like mounting [metada format+filesystem] which is nonesense. That’s explain why
one needs to zero out a partition so that DRBD can use it. After that, you can create your file system
on the DRBD device /dev/drbd1 and mount it if you like to.

  • Couldn’t restart my server:

I needed that my DRBD partition be mounted on OS startup. So, as always, I jumped to the /etc/fstab, added joyfully this line:

/dev/sda2       /mountpoint           ext3    defaults        0       2

Restarting my server, boot process stopped at fsck checks of the DRBD partition and didn’t start.No,No,

The only thing I could do is restarting my server at rescue mode with a live CD, everything was ok, though
my system won’t start. Why?

Look at my /etc/fstab line:

The option is defaults which implicitly means mount at boot,
The sixth fied is 2, which tells fsck to check filesystem of my partition at boot time;

So the thing was that the DRBD partition:/dev/sda2 is mounted at boot time. Thus couldn’t start my server
because it hanged out trying to mount a partition that contains no recognizable filesystem.

And even if, I used noauto option, I couldn’t start it because it hanged out while fsck checked a
non-coherent filesystem!!!!

So the solution was to use noauto option with 0 at the sixth field preventing any fsck checks at boot

DRBD is cool and fun, you can use drbdadm utility to manage it and with cat /proc/drbd, you can see the
status of the replication and nodes. I actually used it to write a script monitoring DRBD 8.4 by following
the documentation and doing some logic for cases to monitor;
I also found a good article describing how to use DRBD to do MySQL replication. It’s cool compared to the
master/slave replication done in high level of the O/S, just think to include your mysql configuration
files in the partition to be replicated.

This is in brief, how was my first contact with DRBD. I can also add that DRBD guys at IRC were very
generous and ready to answer every question, thank you guys :).

Post a comment or leave a trackback: Trackback URL.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: