Blame SOURCES/rear-bz2048454.patch

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