#1871 Issue closed: root_uuid variable may get duplicate UUID (with newline) when snapper is used on SLES

Labels: bug, fixed / solved / done

jsmeix opened issue at 2018-07-17 14:27:

We (i.e. SUSE) got the following issue plus the proposed fix
from a SUSE partner who tested SLES15:

  • ReaR version ("/usr/sbin/rear -V"):
    current GitHub master code

  • OS version ("cat /etc/rear/os.conf" or "lsb_release -a" or "cat /etc/os-release"):
    SLES 12 or 15 when snapper is enabled (the default at least with btrfs)

  • Brief description of the issue:
    Current code in usr/share/rear/lib/bootloader-functions.sh is

# SLES12 SP1 boot throw kernel panic without root= set
root_uuid=$(mount | grep -w 'on /' | awk '{print $1}' | xargs blkid -s UUID -o value)

cf. https://github.com/rear/rear/commit/b81693f27a41482ed89da36a9af664fe808f8186

On SLES with btrfs and snapper mount | grep -w 'on /' results two matches.
Here on my SLES15 test system (a SLES15 default installation):

# mount | grep -w 'on /'
/dev/sda2 on / type btrfs (rw,relatime,space_cache,subvolid=267,subvol=/@/.snapshots/1/snapshot)
/dev/sda2 on /.snapshots type btrfs (rw,relatime,space_cache,subvolid=266,subvol=/@/.snapshots)

# root_uuid=$(mount | grep -w 'on /' | awk '{print $1}' | xargs blkid -s UUID -o value)

# echo "'$root_uuid'"
'f075b5ff-ba88-41db-ae32-feb4a639bdcd
f075b5ff-ba88-41db-ae32-feb4a639bdcd'

That duplicate UUID (with newline) ends up in the menuentry
when booting the ReaR recovery system ISO image.

The reason is that /.snapshots is two words / and snapshots
split by the non-word constituent character . for grep -w, cf.
https://github.com/rear/rear/pull/1872#issuecomment-405842853
for example as in

# echo -e 'first\nfoo some.thing bar\nlast' | grep -w 'some'
foo some.thing bar
  • Work-around, if any:
    Replace grep -w 'on /' with grep ' on / ' (i.e. specify spaces as separators)
    which results on my SLES15 test system:
# mount | grep ' on / '
/dev/sda2 on / type btrfs (rw,relatime,space_cache,subvolid=267,subvol=/@/.snapshots/1/snapshot)

# root_uuid=$(mount | grep ' on / ' | awk '{print $1}' | xargs blkid -s UUID -o value)

# echo "'$root_uuid'"
'f075b5ff-ba88-41db-ae32-feb4a639bdcd'

jsmeix commented at 2018-07-18 07:54:

With https://github.com/rear/rear/pull/1872 merged
this issue is fixed.


[Export of Github issue for rear/rear.]