It is possible, if slightly advanced, to both use Logical Volumes as backing devices for DRBD and at the same time use a DRBD device itself as a Physical Volume. To provide an example, consider the following configuration:
/dev/sda1
, and /dev/sdb1
, which we
intend to use as Physical Volumes.
local
.
r0
.
r0
, which corresponds to the device /dev/drbd0
.
replicated
.
foo
(4 GiB)
and bar
(6 GiB).
In order to enable this configuration, follow these steps:
Set an appropriate filter
option in your /etc/lvm/lvm.conf
:
filter = ["a|sd.*|", "a|drbd.*|", "r|.*|"]
This filter expression accepts PV signatures found on any SCSI and DRBD devices, while rejecting (ignoring) all others.
After modifying the lvm.conf
file, you must run the
vgscan
command so LVM
discards its configuration cache and re-scans devices for PV
signatures.
Disable the LVM cache by setting:
write_cache_state = 0
After disabling the LVM cache, make sure you remove any stale cache
entries by deleting /etc/lvm/cache/.cache
.
Now, you may initialize your two SCSI partitions as PVs:
# pvcreate /dev/sda1 Physical volume "/dev/sda1" successfully created # pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created
The next step is creating your low-level VG named local
,
consisting of the two PVs you just initialized:
# vgcreate local /dev/sda1 /dev/sda2 Volume group "local" successfully created
Now you may create your Logical Volume to be used as DRBD’s backing device:
# lvcreate --name r0 --size 10G local Logical volume "r0" created
Then, edit your /etc/drbd.conf
to create a new resource named r0
:
resource r0 { device /dev/drbd0; disk /dev/local/r0; meta-disk internal; on <host> { address <address>:<port>; } on <host> { address <address>:<port>; } }
After you have created your new resource configuration, be sure to
copy your drbd.conf
contents to the peer node.
Then, promote your resource (on one node):
# drbdadm primary r0
Now, on the node where you just promoted your resource, initialize your DRBD device as a new Physical Volume:
# pvcreate /dev/drbd0 Physical volume "/dev/drbd0" successfully created
Create your VG named replicated
, using the PV you just
initialized, on the same node:
# vgcreate replicated /dev/drbd0 Volume group "replicated" successfully created
Finally, create your new Logical Volumes within this newly-created
# lvcreate --name foo --size 4G replicated Logical volume "foo" created # lvcreate --name bar --size 6G replicated Logical volume "bar" created
The Logical Volumes foo
and bar
will now be available as
/dev/replicated/foo
and /dev/replicated/bar
on the local node.
To make them available on the other node, first issue the following sequence of commands on the primary node:
# vgchange -a n replicated 0 logical volume(s) in volume group "replicated" now active # drbdadm secondary r0
Then, issue these commands on the other (still secondary) node:
# drbdadm primary r0 # vgchange -a y replicated 2 logical volume(s) in volume group "replicated" now active
After this, the block devices /dev/replicated/foo
and
/dev/replicated/bar
will be available on the other (now primary) node.