Blame SOURCES/rear-bz2048454.patch

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