I've read through the documentation provided at http://www.drbd.org/users-guide/ch-internals.html#s-meta-data-size to establish the DRBD meta size, but I'm struggling to correlate that to actual disk sizes and file system sizes.

Is there a way that I can retrieve the file system size in sectors (along with the block device), to get the right value for the meta data.

1 Answer 1


We use a script in-house for calculating DRBD meta sizes for LVM partitions.

This is a script that just takes the block device as an argument.

Eg. metacalc.sh /dev/vg1/root

This is the contents of the script ... (it also happens to give the command to resize the file system on the DRBD disk too).



which bc >/dev/null 2>&1
if [ ! $? -eq 0 ]; then
    echo "Error: bc is not installed"
    exit 1

if [ $# -lt 1 ]; then
    echo "Error: Please supply block device path"
    echo "Eg. /dev/vg1/backups"
    exit 1


SECTOR_SIZE=$( blockdev --getss $DEVICE )
SECTORS=$( blockdev --getsz $DEVICE )
MD_SIZE=$( echo "((($SECTORS + (2^18)-1) / 262144 * 8) + 72)" | bc )
FS_SIZE=$( echo "$SECTORS - $MD_SIZE" | bc )

MD_SIZE_MB=$( echo "($MD_SIZE / 4 / $SECTOR_SIZE) + 1" | bc )
FS_SIZE_MB=$( echo "($FS_SIZE / 4 / $SECTOR_SIZE)" | bc )

echo "Filesystem: $FS_SIZE_MB MiB"
echo "Filesystem: $FS_SIZE Sectors"
echo "Meta Data:  $MD_SIZE_MB MiB"
echo "Meta Data:  $MD_SIZE Sectors"
echo "--"
echo "Resize commands: resize2fs -p "$DEVICE $FS_SIZE_MB"M; drbdadm create-md res"

The only prerequisite is that bc is installed

  1. Centos - yum install bc
  2. Debian/Ubuntu - apt-get install bc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.