Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding 640_verify_lvm_conf.sh script #2107

Merged
merged 2 commits into from Apr 5, 2019
Merged

adding 640_verify_lvm_conf.sh script #2107

merged 2 commits into from Apr 5, 2019

Conversation

gdha
Copy link
Member

@gdha gdha commented Apr 3, 2019

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

Signed-off-by: Gratien D'haese <gratien.dhaese@gmail.com>
@gdha gdha added the enhancement Adaptions and new features label Apr 3, 2019
@gdha gdha added this to the ReaR v2.5 milestone Apr 3, 2019
@gdha gdha self-assigned this Apr 3, 2019
Copy link
Member

@jsmeix jsmeix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current sed command does nothing
if use_lvmetad = is in a comment like

# Set 'use_lvmetad = 1' to cache metadata

e.g.

$ echo "# Set 'use_lvmetad = 1' to cache metadata" | sed 's/use_lvmetad =.*/use_lvmetad = 0/'
# Set 'use_lvmetad = 0

cf. #2070
so I suggest to change the sed command similar as in
https://github.com/rear/rear/pull/2070/files
to enforce use_lvmetad = 0 is actually active
in $ROOTFS_DIR/etc/lvm/lvm.conf

The problem with /etc/lvm/lvm.conf is that use_lvmetad = 0
cannot be simply appended to the end of the file as in
https://github.com/rear/rear/pull/2070/files
because use_lvmetad = 0 must be set within the global
section in /etc/lvm/lvm.conf so that I suggest to append
use_lvmetad = 0 after the global { line like

sed -e 's/.*use_lvmetad =.*/\t#&/' -e '/global {/ a \\tuse_lvmetad = 0'

which intends to even keep the tabs as in my /etc/lvm/lvm.conf
but because man lvm.conf reads on my SLES systems (even down to SLES11)

SYNTAX
  This section describes the configuration file syntax.
  Whitespace is not significant unless it is within quotes.
  This provides a wide choice of acceptable indentation styles.
  Comments begin with # and continue to the end of  the line.
  They are treated as whitespace.

we can use a simpler (and hopefully more robust and fail-safe)
sed command for example like

sed -e 's/.*use_lvmetad =.*/# &/' -e '/global {/ a use_lvmetad = 0'

A remaining possible point of failure is that a global { line must exist
with exactly that syntax but it could be different like

        global        {

because whitespace is not significant in /etc/lvm/lvm.conf

@jsmeix
Copy link
Member

jsmeix commented Apr 4, 2019

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. #2044 (comment)

@jsmeix
Copy link
Member

jsmeix commented Apr 4, 2019

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

Signed-off-by: Gratien D'haese <gratien.dhaese@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Adaptions and new features fixed / solved / done
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants