diskdrbd

Replacing a failed drive in DRBD ()


How to correctly set the size of the disk, when replacing, if I want to use the original disk size?

The volume of the new disk is 4 Gb, but I want to use only the volume that was used before and is used on the disk of another node (2 Gb).

Resource:

resource res-vdb {

  device drbd_res_vdb1 minor 1;
  disk /dev/vdb;   
  meta-disk internal;

  protocol C;

  on node01 {
    address 192.168.0.1:7005;
  }

  on node02 {
    address 192.168.0.2:7005;
  }
}

Do I understand correctly that I can take the size from lsblck or from /sys/block/drbd1/size and set in res config before drbdadm create-md and drbdadm attach?

i.e. config:

resource res-vdb {

  device drbd_res_vdb1 minor 1;
  disk /dev/vdb;   
  meta-disk internal;

  protocol C;

  disk {
        size 2097052K;      <==== 2GB
    }
  on node01 {
    address 192.168.0.1:7005;
  }

  on node02 {
    address 192.168.0.2:7005;
  }
}

Solution

  • You're correct in that you can set the size in the DRBD res file before you create-md and attach in order to explicitly set the size of the DRBD device.

    As you've also suggested, you can retrieve the exact size of the DRBD device in various ways, including using lsblk or inspecting the kernel settings with cat /sys/block/drbd1/size, run from the peer node.

    However, when you use lsblk, it's going to do some rounding. DRBD's parser doesn't seem to accept bytes (B) as a valid unit (with drbd-utils version 9.13.1 seems to only like KB, MB, and GB), so you might be better off setting the size in sectors (s).

    The size you find in /sys/block/drbd1/size is already in sectors, so an example would be:

    # cat /sys/block/drbd1/size 
    27262072
    
    # cat /etc/drbd.d/r1.res 
    resource res-vdb {
        protocol C;
        disk /dev/vdb;
        device minor 1;
        disk {
            size 27262072s;
        }
        on centos7-a {
            address 172.16.7.100:7779;
        }
        on centos7-b {
            address 172.16.7.101:7779;
        }
    }
    

    All that said, because DRBD auto-negotiates the device size among it's peers, you could simply, drbdadm create-md res-vdb, drbdadm up res-vdb, and it should just work.