Blame SOURCES/rear-bz2048454.patch

f88787
diff --git a/usr/share/rear/layout/save/GNU/Linux/220_lvm_layout.sh b/usr/share/rear/layout/save/GNU/Linux/220_lvm_layout.sh
f88787
index 35be1721..d3c9ae86 100644
f88787
--- a/usr/share/rear/layout/save/GNU/Linux/220_lvm_layout.sh
f88787
+++ b/usr/share/rear/layout/save/GNU/Linux/220_lvm_layout.sh
f88787
@@ -103,12 +103,7 @@ local lvs_exit_code
f88787
         pdev=$( get_device_name $pdev )
f88787
 
f88787
         # Output lvmdev entry to DISKLAYOUT_FILE:
f88787
-        # With the above example the output is:
f88787
-        # lvmdev /dev/system /dev/sda1 7wwpcO-KmNN-qsTE-7sp7-JBJS-vBdC-Zyt1W7 41940992
f88787
-        echo "lvmdev /dev/$vgrp $pdev $uuid $size"
f88787
-
f88787
-        # After the 'lvmdev' line was written to disklayout.conf so that the user can inspect it
f88787
-        # check that the required positional parameters in the 'lvmdev' line are non-empty
f88787
+        # Check that the required positional parameters in the 'lvmdev' line are non-empty
f88787
         # because an empty positional parameter would result an invalid 'lvmdev' line
f88787
         # which would cause invalid parameters are 'read' as input during "rear recover"
f88787
         # cf. "Verifying ... 'lvm...' entries" in layout/save/default/950_verify_disklayout_file.sh
f88787
@@ -117,13 +112,24 @@ local lvs_exit_code
f88787
         # so that this also checks that the variables do not contain blanks or more than one word
f88787
         # because blanks (actually $IFS characters) are used as field separators in disklayout.conf
f88787
         # which means the positional parameter values must be exactly one non-empty word.
f88787
-        # Two separated simple 'test $vgrp && test $pdev' commands are used here because
f88787
-        # 'test $vgrp -a $pdev' does not work when $vgrp is empty or only blanks
f88787
-        # because '-a' has two different meanings: "EXPR1 -a EXPR2" and "-a FILE" (see "help test")
f88787
-        # so that when $vgrp is empty 'test $vgrp -a $pdev' tests if file $pdev exists
f88787
-        # which is usually true because $pdev is usually a partition device node (e.g. /dev/sda1)
f88787
-        # so that when $vgrp is empty 'test $vgrp -a $pdev' would falsely succeed:
f88787
-        test $vgrp && test $pdev || Error "LVM 'lvmdev' entry in $DISKLAYOUT_FILE where volume_group or device is empty or more than one word"
f88787
+        test $pdev || Error "Cannot make 'lvmdev' entry in disklayout.conf (PV device '$pdev' empty or more than one word)"
f88787
+        if ! test $vgrp ; then
f88787
+            # Valid $pdev but invalid $vgrp (empty or more than one word):
f88787
+            # When $vgrp is empty it means it is a PV that is not part of a VG so the PV exists but it is not used.
f88787
+            # PVs that are not part of a VG are documented as comment in disklayout.conf but they are not recreated
f88787
+            # because they were not used on the original system so there is no need to recreate them by "rear recover"
f88787
+            # (the user can manually recreate them later in his recreated system when needed)
f88787
+            # cf. https://github.com/rear/rear/issues/2596
f88787
+            DebugPrint "Skipping PV $pdev that is not part of a valid VG (VG '$vgrp' empty or more than one word)"
f88787
+            echo "# Skipping PV $pdev that is not part of a valid VG (VG '$vgrp' empty or more than one word):"
f88787
+            contains_visible_char "$vgrp" || vgrp='<missing_VG>'
f88787
+            echo "# lvmdev /dev/$vgrp $pdev $uuid $size"
f88787
+            # Continue with the next line in the output of "lvm pvdisplay -c"
f88787
+            continue
f88787
+        fi
f88787
+        # With the above example the output is:
f88787
+        # lvmdev /dev/system /dev/sda1 7wwpcO-KmNN-qsTE-7sp7-JBJS-vBdC-Zyt1W7 41940992
f88787
+        echo "lvmdev /dev/$vgrp $pdev $uuid $size"
f88787
 
f88787
     done
f88787
     # Check the exit code of "lvm pvdisplay -c"
f88787
@@ -161,8 +167,15 @@ local lvs_exit_code
f88787
         # lvmgrp /dev/system 4096 5119 20967424
f88787
         echo "lvmgrp /dev/$vgrp $extentsize $nrextents $size"
f88787
 
f88787
-        # Check that the required positional parameters in the 'lvmgrp' line are non-empty
f88787
-        # cf. the code above to "check that the required positional parameters in the 'lvmdev' line are non-empty":
f88787
+        # Check that the required positional parameters in the 'lvmgrp' line are non-empty.
f88787
+        # The tested variables are intentionally not quoted here, cf. the code above to
f88787
+        # "check that the required positional parameters in the 'lvmdev' line are non-empty".
f88787
+        # Two separated simple 'test $vgrp && test $extentsize' commands are used here because
f88787
+        # 'test $vgrp -a $extentsize' does not work when $vgrp is empty or only blanks
f88787
+        # because '-a' has two different meanings: "EXPR1 -a EXPR2" and "-a FILE" (see "help test")
f88787
+        # so with empty $vgrp it becomes 'test -a $extentsize' that tests if a file $extentsize exists
f88787
+        # which is unlikely to be true but it is not impossible that a file $extentsize exists
f88787
+        # so when $vgrp is empty (or blanks) 'test $vgrp -a $extentsize' might falsely succeed:
f88787
         test $vgrp && test $extentsize || Error "LVM 'lvmgrp' entry in $DISKLAYOUT_FILE where volume_group or extentsize is empty or more than one word"
f88787
 
f88787
     done
f88787
@@ -305,7 +318,8 @@ local lvs_exit_code
f88787
             fi
f88787
             already_processed_lvs+=( "$vg/$lv" )
f88787
             # Check that the required positional parameters in the 'lvmvol' line are non-empty
f88787
-            # cf. the code above to "check that the required positional parameters in the 'lvmdev' line are non-empty":
f88787
+            # cf. the code above to "check that the required positional parameters in the 'lvmdev' line are non-empty"
f88787
+            # and the code above to "check that the required positional parameters in the 'lvmgrp' line are non-empty":
f88787
             test $vg && test $lv && test $size && test $layout || Error "LVM 'lvmvol' entry in $DISKLAYOUT_FILE where volume_group or name or size or layout is empty or more than one word"
f88787
         fi
f88787