9 Using LVM With DRBD
9 Using LVM With DRBD
If you happen to be unfamiliar with these terms to begin with, LVM primer may serve as your LVM
starting point — although you are always encouraged, of course, to familiarize yourself with LVM in
some more detail than this section provides.
When working with LVM, it is important to understand its most basic concepts:
The partition type “Linux LVM” (signature 0x8E) can be used to identify partitions for
exclusive use by LVM. This, however, is not required — LVM recognizes PVs by way of a
signature written to the device upon PV initialization.
This example assumes that a Volume Group named foo already exists on both nodes of on your
LVM-enabled system, and that you wish to create a DRBD resource named r0 using a Logical
Volume in that Volume Group.
Of course, you must complete this command on both nodes of your DRBD cluster. After this, you
should have a block device named /dev/foo/bar on either node.
Then, you can simply enter the newly-created volumes in your resource configuration:
resource r0 {
...
on alice {
device /dev/drbd0;
disk /dev/foo/bar;
...
on bob {
device /dev/drbd0;
disk /dev/foo/bar;
...
}
Now you can continue to bring your resource up, just as you would if you were using non-LVM block
devices.
When serving DRBD off an LVM Logical Volume, you can mitigate this problem by creating an
automated snapshot when synchronization starts, and automatically removing that same snapshot
once synchronization has completed successfully.
In order to enable automated snapshotting during resynchronization, add the following lines to your
resource configuration:
resource r0 {
handlers {
before-resync-target "/usr/lib/drbd/snapshot-resync-target-lvm.sh";
after-resync-target "/usr/lib/drbd/unsnapshot-resync-target-lvm.sh";
The two scripts parse the $DRBD_RESOURCE environment variable which DRBD automatically
passes to any handler it invokes. The snapshot-resync-target-lvm.sh script then creates an LVM
snapshot for any volume the resource contains, then synchronization kicks off. In case the script
fails, the synchronization does not commence.
You should review dangling snapshots as soon as possible. A full snapshot causes both the
snapshot itself and its origin volume to fail.
If at any time your SyncSource does fail beyond repair and you decide to revert to your latest
snapshot on the peer, you may do so by issuing the lvconvert -M command.
# pvcreate /dev/drbdX
or
# pvcreate /dev/drbd/by-res/<resource>/0
Now, it is necessary to include this device in the list of devices LVM scans for PV signatures. In
order to do this, you must edit the LVM configuration file, normally named /etc/lvm/lvm.conf Find
the line in the devices section that contains the filter keyword and edit it accordingly. If all your PVs
are to be stored on DRBD devices, the following is an appropriate filter option:
This filter expression accepts PV signatures found on any DRBD devices, while rejecting (ignoring)
all others.
By default, LVM scans all block devices found in /dev for PV signatures. This is equivalent to
filter = [ "a|.*|" ].
If you want to use stacked resources as LVM PVs, then you will need a more explicit filter
configuration. You need to make sure that LVM detects PV signatures on stacked resources, while
ignoring them on the corresponding lower-level resources and backing devices. This example
assumes that your lower-level DRBD resources use device minors 0 through 9, whereas your
stacked resources are using device minors from 10 upwards:
This filter expression accepts PV signatures found only on the DRBD devices /dev/drbd10 through
/dev/drbd19, 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.
You may of course use a different filter configuration to match your particular system
configuration. What is important to remember, however, is that you need to
write_cache_state = 0
After disabling the LVM cache, make sure you remove any stale cache entries by deleting
/etc/lvm/cache/.cache.
You must repeat the above steps on the peer nodes, too.
If your system has its root filesystem on LVM, Volume Groups will be activated from your
initial ramdisk (initrd) during boot. In doing so, the LVM tools will evaluate an lvm.conf file
included in the initrd image. Thus, after you make any changes to your lvm.conf, you should
be certain to update your initrd with the utility appropriate for your distribution (mkinitrd,
update-initramfs etc.).
When you have configured your new PV, you may proceed to add it to a Volume Group, or create a
new Volume Group from it. The DRBD resource must, of course, be in the primary role while doing
so.
While it is possible to mix DRBD and non-DRBD Physical Volumes within the same Volume
Group, doing so is not recommended and unlikely to be of any practical value.
When you have created your VG, you may start carving Logical Volumes out of it, using the
lvcreate command (as with a non-DRBD-backed Volume Group).
if your LVM volume group is managed by Pacemaker as explained in Highly available LVM
with Pacemaker, it is imperative to place the cluster in maintenance mode prior to making
changes to the DRBD configuration.
Extend your resource configuration to include an additional volume, as in the following example:
resource r0 {
volume 0 {
device /dev/drbd1;
disk /dev/sda7;
meta-disk internal;
volume 1 {
device /dev/drbd2;
disk /dev/sda8;
meta-disk internal;
on alice {
address 10.1.1.31:7789;
on bob {
address 10.1.1.32:7789;
Make sure your DRBD configuration is identical across nodes, then issue:
# drbdadm adjust r0
This will implicitly call drbdsetup new-minor r0 1 to enable the new volume 1 in the resource r0.
Once the new volume has been added to the replication stream, you may initialize and add it to the
volume group:
# pvcreate /dev/drbd/by-res/<resource>/1
This will add the new PV /dev/drbd/by-res//1 to the VG, preserving write fidelity across the entire
VG.
We have two partitions, named /dev/sda1, and /dev/sdb1, which we intend to use as
Physical Volumes.
Both of these PVs are to become part of a Volume Group named local.
We want to create a 10-GiB Logical Volume in this VG, to be named r0.
This LV will become the local backing device for our DRBD resource, also named r0, which
corresponds to the device /dev/drbd0.
This device will be the sole PV for another Volume Group, named replicated.
This VG is to contain two more logical volumes named foo(4 GiB) and bar(6 GiB).
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.
write_cache_state = 0
After disabling the LVM cache, make sure you remove any stale cache entries by deleting
/etc/lvm/cache/.cache.
# pvcreate /dev/sda1
# pvcreate /dev/sdb1
The next step is creating your low-level VG named local, consisting of the two PVs you just
initialized:
Now you may create your Logical Volume to be used as DRBD’s backing device:
resource r0 {
device /dev/drbd0;
disk /dev/local/r0;
meta-disk internal;
After you have created your new resource configuration, be sure to copy your drbd.conf contents to
the peer node.
After this, initialize your resource as described in Enabling your resource for the first time
(on both nodes).
# 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
Create your VG named replicated, using the PV you just initialized, on the same node:
Finally, create your new Logical Volumes within this newly-created VG via
The Logical Volumes foo and bar will now be available as /dev/replicated/foo and
/dev/replicated/bar on the local node.
# drbdadm secondary r0
# drbdadm primary r0
# vgchange -a y replicated
After this, the block devices /dev/replicated/foo and /dev/replicated/bar will be available on the
other (now primary) node.
In order to put an existing, DRBD-backed volume group under Pacemaker management, run the
following commands in the crm shell:
params drbd_resource="r0" \
ms ms_drbd_r0 p_drbd_r0 \
clone-max="2" clone-node-max="1" \
notify="true"
params volgrpname="r0"
commit
After you have committed this configuration, Pacemaker will automatically make the r0 volume
group available on whichever node currently has the Primary (Master) role for the DRBD resource.
Revision #2
Created 7 September 2021 07:14:53 by chuanzhi.dai
Updated 12 October 2021 05:30:25 by chaoyue.shan