#2107 PR merged: adding 640_verify_lvm_conf.sh script

Labels: enhancement, fixed / solved / done

gdha opened issue at 2019-04-03 15:39:

Signed-off-by: Gratien D'haese gratien.dhaese@gmail.com

  • Type: Enhancement

  • Impact: Low

  • Reference to related issue (URL): #2044

  • How was this pull request tested? via automated testing

  • Brief description of the changes in this pull request:

jsmeix commented at 2019-04-04 08:28:

I think enforcing use_lvmetad = 0 in $ROOTFS_DIR/etc/lvm/lvm.conf
could lead to arbitrary LVM errors in the ReaR recovery system
for older LVM versions that do not support use_lvmetad,
cf. https://github.com/rear/rear/issues/2044#issuecomment-477532482

jsmeix commented at 2019-04-04 08:54:

On my SLES15-like openSUSE Leap 15.0 system I have

# lvmconfig | grep 'use_lvmetad' && echo Y || echo N
        use_lvmetad=1
Y

but on my SLES11 system I do not have lvmconfig
there I have only lvm dumpconfig (i.e. no lvm config on SLES11):

# lvm dumpconfig | grep 'use_lvmetad' && echo Y || echo N
N

which also works on my SLES15-like openSUSE Leap 15.0 system

# lvm dumpconfig | grep 'use_lvmetad' && echo Y || echo N
        use_lvmetad=1
Y

but according to man lvmconfig on my openSUSE Leap 15.0 system

DESCRIPTION
  lvmconfig,
  lvm config, lvm dumpconfig (for compatibility reasons, to be phased out)
  produce formatted output from the LVM configuration tree.
  The sources of the configuration data include lvm.conf(5)
  and command line settings from --config.

at some later time lvm dumpconfig can no longer be used
or perhaps some Linux distributions have already dropped lvm dumpconfig
so we need some fail-safe testing code like

# build/GNU/Linux/640_verify_lvm_conf.sh
# Purpose is to turn off the
# "WARNING: Failed to connect to lvmetad. Falling back to device scanning"
# in the output during the 'rear recover' process - see issue
# https://github.com/rear/rear/issues/2044 for more details

# Nothing to do when there is no $ROOTFS_DIR/etc/lvm/lvm.conf file:
test -f $ROOTFS_DIR/etc/lvm/lvm.conf || return 0

# Determine whether or not lvmetad is in use:
local use_lvmetad_active=""

# First try the older traditional 'lvm dumpconfig':
lvm dumpconfig | grep -q 'use_lvmetad=1' && use_lvmetad_active="yes"

# If 'lvm dumpconfig' did not work use the newer 'lvmconfig':
if ! test "$use_lvmetad_active" ; then
    lvmconfig | grep -q 'use_lvmetad=1' && use_lvmetad_active="yes"
fi

# As fallback try 'lvm version':
if ! test "$use_lvmetad_active" ; then
    lvm version | grep -q -- '--enable-lvmetad' && use_lvmetad_active="yes"
fi

# Skip enforcing 'use_lvmetad = 0' in $ROOTFS_DIR/etc/lvm/lvm.conf
# if lvmetad is not in use:
is_true "$use_lvmetad_active" || return 0

# Enforce 'use_lvmetad = 0' in $ROOTFS_DIR/etc/lvm/lvm.conf
sed -i -e 's/.*use_lvmetad =.*/# &/' -e '/global {/ a use_lvmetad = 0' $ROOTFS_DIR/etc/lvm/lvm.conf

[Export of Github issue for rear/rear.]