Blame SOURCES/rear-bz2048454.patch

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