Network/Procedures/Convert a normal logical volume to a DRBD

From Makers Local 256
Jump to: navigation, search

Adapted from [1]. This is useful for migrating from an LVM-based VM host to a more robust DRBD-on-LVM setup.

Start on the source box.

  • lvextend -L +128m kratos/backup (where "kratos" is the volume group and "backup" is the volume name)
  • Create /etc/drbd.d/backup_disk.res (for example) and make it look like this:

resource backup_disk {
       protocol C;
       meta-disk internal;
       device /dev/drbd_backup_disk minor 7; #dev and minor must be unique per disk
       syncer {
               verify-alg sha1;
               rate 5M;
       }
       net {
               allow-two-primaries;# yes;
               cram-hmac-alg sha1;
               shared-secret "backup_disk";
       }
       on kratos {
               disk /dev/kratos/backup;
               address 10.56.0.2:7795; #port must be unique per disk
       }
       on vm2 {
               disk /dev/vm2_storage/backup_disk;
               address 10.56.0.20:7795;
       }
} 

Then, scp this file to the other box's /etc/drbd.d/ directory, too.

  • fdisk -l /dev/kratos/backup | head -n 2 and make a note of the size, in bytes, of the volume.
  • drbdadm create-md backup_disk (it'll tell you it might nuke something by writing metadata, but we extended the volume 128MB to accommodate this, so accept that)
  • At this point you are going to want to bring down your VM and point it to /dev/drbd_backup_disk (or whatever) instead of its old disk. Don't start it though.
  • drbdadm attach backup_disk
  • drbdadm -- --overwrite-data-of-peer primary backup_disk (Force this machine to come up as the "gold copy" of the data, and clobber the secondary we will attach later)
  • cat /proc/drbd (your volume status will be Primary/Unknown)
  • At this point you can boot the VM again.

Now, on the replication target (new box):

  • lvcreate --name backup_disk --size 74222403584B vm2_storage (where "backup_disk" is the name of your logical volume, "74222403584B" is the size from when you ran fdisk -l earlier, and "vm2_storage" is the volume group)
  • drbdadm create-md backup_disk (you shouldn't have to confirm anything if this is a blank disk)
  • drbdadm adjust backup_disk (The connection won't happen just yet)

Now, finally, back on your primary box:

  • drbdadm adjust backup_disk

Now you can watch cat /proc/drbd on either box and you should watch your volume synch!