Increasing mobility and availability of laptop data with DRBD

I tried this out recently as an experiment and fun home project. I wanted to be able to seamlessly switch between my mobile workstation that my employer had given me, and my desktop workstation that I preferred to use at home.

I was able to create an exact replica of my laptop data, its environment, account- and application-specific settings that would sync automatically with my desktop workstation when connected to my home network.

This was really useful for me, since I could just close my laptop and be completely set up with my entire work environment when I sat down at my desktop. On top of that, it provided a backup copy of all my latest work, so that if one machine were to fail, I’d suffer no downtime or data loss. It tickled my cluster-admin side to see yet another single point of failure eliminated.

Hence, this is purely for fun and not recommended for everyone…

DRBD Setup
1. First, install DRBD.

2. Create two identical data volumes. These will be replicated between laptop -> desktop. In my case, I just created a new LV on my system VG and copied my data to it. It was the most simple/straightforward approach for my setup. Alternatively, you can use your existing home partition/volume and shrink it by 128MB to make room for the DRBD metadata.

3. Configure whatever global options you prefer in /etc/drbd.d/global_common.conf.

Then, create a template that will be used for resource configuration.

cat /etc/drbd.d/template
resource home {
  protocol C;
  disk {
        resync-rate 90M;
  on tori {
    device    /dev/drbd1;
    disk /dev/Raid/shared_home;    
    address;   # my static desktop machine
    meta-disk internal;
  on yuki {
    device    /dev/drbd1;
    disk      /dev/System/shared_home;   
    address   MYADDRESS:7789;   # laptop. keep 'MYADDRESS' here
    meta-disk internal;

Setting up Dynamic Resource Configuration
Your laptop, being a mobile device, likely has an ever-changing IP address. To accommodate this, you’ll need to make your DRBD config dynamic too.

To automatically generate your DRBD config on bootup, you can create a little shell script like this one. Note: replace ’em1′ with your interface!

# a script to write a DRBD resource file based on current IP
current_ip=`ip addr show em1 | grep -w inet | cut -f 1 -d / | awk {'print $2'}`

# use a template file to create the DRBD resource file
sed "s/MYADDRESS/$current_ip/" /etc/drbd.d/template > /etc/drbd.d/home.res

# start up the resource and mount it
/sbin/drbdadm up home
/sbin/drbdadm primary home
mount /dev/drbd1 /home

Give the script execute permissions and append the full path to /etc/rc.local.

chmod 700 dyn_drbd.bash
echo /root/scripts/dyn_drbd.bash >> /etc/rc.local

Now test it out!
Give it a try manually by making the resource primary on the box that contains your /home data. Mount up /dev/drbd1, copy the contents of your home dir to it (make sure to preserve permissions!), and try logging in. It could take a little adjusting here and there, but that’s just part of the challenge that makes this project fun 😉

Leave a reply

Your email address will not be published.

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>