|
|
6f74ef |
diff --git a/usr/share/rear/layout/prepare/GNU/Linux/110_include_lvm_code.sh b/usr/share/rear/layout/prepare/GNU/Linux/110_include_lvm_code.sh
|
|
|
6f74ef |
index 7cfdfcf2..1be17ba8 100644
|
|
|
6f74ef |
--- a/usr/share/rear/layout/prepare/GNU/Linux/110_include_lvm_code.sh
|
|
|
6f74ef |
+++ b/usr/share/rear/layout/prepare/GNU/Linux/110_include_lvm_code.sh
|
|
|
6f74ef |
@@ -68,9 +68,9 @@ create_lvmgrp() {
|
|
|
6f74ef |
local vg=${vgrp#/dev/}
|
|
|
6f74ef |
|
|
|
6f74ef |
cat >> "$LAYOUT_CODE" <
|
|
|
6f74ef |
-create_volume_group=1
|
|
|
6f74ef |
-create_logical_volumes=1
|
|
|
6f74ef |
-create_thin_volumes_only=0
|
|
|
6f74ef |
+create_volume_group+=( "$vg" )
|
|
|
6f74ef |
+create_logical_volumes+=( "$vg" )
|
|
|
6f74ef |
+create_thin_volumes_only=( \$( RmInArray "$vg" "\${create_thin_volumes_only[@]}" ) )
|
|
|
6f74ef |
|
|
|
6f74ef |
EOF
|
|
|
6f74ef |
|
|
|
6f74ef |
@@ -83,7 +83,7 @@ EOF
|
|
|
6f74ef |
# '--mirrorlog', etc.
|
|
|
6f74ef |
# Also, we likely do not support every layout yet (e.g. 'cachepool').
|
|
|
6f74ef |
|
|
|
6f74ef |
- if ! is_true "$MIGRATION_MODE" ; then
|
|
|
6f74ef |
+ if ! is_true "$MIGRATION_MODE" && lvmgrp_supports_vgcfgrestore "$vgrp" ; then
|
|
|
6f74ef |
cat >> "$LAYOUT_CODE" <
|
|
|
6f74ef |
LogPrint "Restoring LVM VG '$vg'"
|
|
|
6f74ef |
if [ -e "$vgrp" ] ; then
|
|
|
6f74ef |
@@ -97,9 +97,12 @@ if lvm vgcfgrestore -f "$VAR_DIR/layout/lvm/${vg}.cfg" $vg >&2 ; then
|
|
|
6f74ef |
|
|
|
6f74ef |
LogPrint "Sleeping 3 seconds to let udev or systemd-udevd create their devices..."
|
|
|
6f74ef |
sleep 3 >&2
|
|
|
6f74ef |
- create_volume_group=0
|
|
|
6f74ef |
- create_logical_volumes=0
|
|
|
6f74ef |
+ create_volume_group=( \$( RmInArray "$vg" "\${create_volume_group[@]}" ) )
|
|
|
6f74ef |
+ create_logical_volumes=( \$( RmInArray "$vg" "\${create_logical_volumes[@]}" ) )
|
|
|
6f74ef |
|
|
|
6f74ef |
+EOF
|
|
|
6f74ef |
+ if is_true "${FORCE_VGCFGRESTORE-no}"; then
|
|
|
6f74ef |
+ cat >> "$LAYOUT_CODE" <
|
|
|
6f74ef |
#
|
|
|
6f74ef |
# It failed ... restore layout using 'vgcfgrestore --force', but then remove Thin volumes, they are broken
|
|
|
6f74ef |
#
|
|
|
6f74ef |
@@ -121,9 +124,12 @@ elif lvm vgcfgrestore --force -f "$VAR_DIR/layout/lvm/${vg}.cfg" $vg >&2 ; then
|
|
|
6f74ef |
sleep 3 >&2
|
|
|
6f74ef |
|
|
|
6f74ef |
# All logical volumes have been created, except Thin volumes and pools
|
|
|
6f74ef |
- create_volume_group=0
|
|
|
6f74ef |
- create_thin_volumes_only=1
|
|
|
6f74ef |
+ create_volume_group=( \$( RmInArray "$vg" "\${create_volume_group[@]}" ) )
|
|
|
6f74ef |
+ create_thin_volumes_only+=( "$vg" )
|
|
|
6f74ef |
|
|
|
6f74ef |
+EOF
|
|
|
6f74ef |
+ fi
|
|
|
6f74ef |
+ cat >> "$LAYOUT_CODE" <
|
|
|
6f74ef |
#
|
|
|
6f74ef |
# It failed also ... restore using 'vgcreate/lvcreate' commands
|
|
|
6f74ef |
#
|
|
|
6f74ef |
@@ -138,7 +144,7 @@ EOF
|
|
|
6f74ef |
local -a devices=($(awk "\$1 == \"lvmdev\" && \$2 == \"$vgrp\" { print \$3 }" "$LAYOUT_FILE"))
|
|
|
6f74ef |
|
|
|
6f74ef |
cat >> "$LAYOUT_CODE" <
|
|
|
6f74ef |
-if [ \$create_volume_group -eq 1 ] ; then
|
|
|
6f74ef |
+if IsInArray $vg "\${create_volume_group[@]}" ; then
|
|
|
6f74ef |
LogPrint "Creating LVM VG '$vg'; Warning: some properties may not be preserved..."
|
|
|
6f74ef |
if [ -e "$vgrp" ] ; then
|
|
|
6f74ef |
rm -rf "$vgrp"
|
|
|
6f74ef |
@@ -240,9 +246,9 @@ create_lvmvol() {
|
|
|
6f74ef |
local warnraidline
|
|
|
6f74ef |
|
|
|
6f74ef |
if [ $is_thin -eq 0 ] ; then
|
|
|
6f74ef |
- ifline="if [ \"\$create_logical_volumes\" -eq 1 ] && [ \"\$create_thin_volumes_only\" -eq 0 ] ; then"
|
|
|
6f74ef |
+ ifline="if IsInArray $vg \"\${create_logical_volumes[@]}\" && ! \$IsInArray $vg \"\${create_thin_volumes_only[@]}\" ; then"
|
|
|
6f74ef |
else
|
|
|
6f74ef |
- ifline="if [ \"\$create_logical_volumes\" -eq 1 ] ; then"
|
|
|
6f74ef |
+ ifline="if IsInArray $vg \"\${create_logical_volumes[@]}\" ; then"
|
|
|
6f74ef |
fi
|
|
|
6f74ef |
|
|
|
6f74ef |
if [ $is_raidunknown -eq 1 ]; then
|
|
|
6f74ef |
diff --git a/usr/share/rear/lib/layout-functions.sh b/usr/share/rear/lib/layout-functions.sh
|
|
|
6f74ef |
index 54ddb50f..ae62d666 100644
|
|
|
6f74ef |
--- a/usr/share/rear/lib/layout-functions.sh
|
|
|
6f74ef |
+++ b/usr/share/rear/lib/layout-functions.sh
|
|
|
6f74ef |
@@ -1308,4 +1308,30 @@ delete_dummy_partitions_and_resize_real_ones() {
|
|
|
6f74ef |
last_partition_number=0
|
|
|
6f74ef |
}
|
|
|
6f74ef |
|
|
|
6f74ef |
+# vgcfgrestore can properly restore only volume groups that do not use
|
|
|
6f74ef |
+# any kernel metadata. All volume types except linear and striped use
|
|
|
6f74ef |
+# kernel metadata.
|
|
|
6f74ef |
+# Check whether a VG (given as /dev/<vgname> in the first argument)
|
|
|
6f74ef |
+# doesn't contain any LVs that use kernel metadata.
|
|
|
6f74ef |
+# If the function returns true, we can safely use vgcfgrestore to restore the VG.
|
|
|
6f74ef |
+function lvmgrp_supports_vgcfgrestore() {
|
|
|
6f74ef |
+ if is_true "${FORCE_VGCFGRESTORE-no}"; then
|
|
|
6f74ef |
+ # If we are willing to use vgcfgrestore --force and then remove broken volumes,
|
|
|
6f74ef |
+ # then everything can be considered supported. Don't do it by default though.
|
|
|
6f74ef |
+ return 0
|
|
|
6f74ef |
+ fi
|
|
|
6f74ef |
+
|
|
|
6f74ef |
+ local lvmvol vgrp lvname size layout kval
|
|
|
6f74ef |
+
|
|
|
6f74ef |
+ local supported_layouts=("linear" "striped")
|
|
|
6f74ef |
+
|
|
|
6f74ef |
+ while read lvmvol vgrp lvname size layout kval; do
|
|
|
6f74ef |
+ [ "$vgrp" == "$1" ] || BugError "vgrp '$vgrp' != '$1'"
|
|
|
6f74ef |
+ if ! IsInArray $layout "${supported_layouts[@]}"; then
|
|
|
6f74ef |
+ LogPrint "Layout '$layout' of LV '$lvname' in VG '$vgrp' not supported by vgcfgrestore"
|
|
|
6f74ef |
+ return 1
|
|
|
6f74ef |
+ fi
|
|
|
6f74ef |
+ done < <(grep "^lvmvol $1 " "$LAYOUT_FILE")
|
|
|
6f74ef |
+}
|
|
|
6f74ef |
+
|
|
|
6f74ef |
# vim: set et ts=4 sw=4:
|