Blame SOURCES/s390-no-clobber-disks.patch

428f4d
diff --git a/usr/share/rear/conf/default.conf b/usr/share/rear/conf/default.conf
428f4d
index 23a83b71..0d13b487 100644
428f4d
--- a/usr/share/rear/conf/default.conf
428f4d
+++ b/usr/share/rear/conf/default.conf
428f4d
@@ -416,6 +416,18 @@ test "$RECOVERY_UPDATE_URL" || RECOVERY_UPDATE_URL=""
428f4d
 #   export MIGRATION_MODE='true'
428f4d
 # directly before he calls "rear recover":
428f4d
 test "$MIGRATION_MODE" || MIGRATION_MODE=''
428f4d
+####
428f4d
+
428f4d
+####
428f4d
+# Formatting DASDs (S/390 specific)
428f4d
+# DASD (Direct Access Storage Device) denotes a disk drive on the S/390 architecture.
428f4d
+# DASDs need to be formatted before use (even before creating a partition table on them).
428f4d
+# By default ReaR will format the DASDs that are going to be used to recreate the system
428f4d
+# (are referenced in disklayout.conf) before recreating the disk layout.
428f4d
+# This can be suppressed by setting FORMAT_DASDS="false". It can be useful when one intends
428f4d
+# to use already formatted DASDs as recovery target.
428f4d
+FORMAT_DASDS=""
428f4d
+####
428f4d
 
428f4d
 ##
428f4d
 # Resizing partitions in MIGRATION_MODE during "rear recover"
428f4d
diff --git a/usr/share/rear/layout/prep-for-mount/Linux-s390/205_s390_enable_disk.sh b/usr/share/rear/layout/prep-for-mount/Linux-s390/205_s390_enable_disk.sh
428f4d
new file mode 120000
428f4d
index 00000000..5f7a2ac0
428f4d
--- /dev/null
428f4d
+++ b/usr/share/rear/layout/prep-for-mount/Linux-s390/205_s390_enable_disk.sh
428f4d
@@ -0,0 +1 @@
428f4d
+../../prepare/Linux-s390/205_s390_enable_disk.sh
428f4d
\ No newline at end of file
428f4d
diff --git a/usr/share/rear/layout/prepare/GNU/Linux/100_include_partition_code.sh b/usr/share/rear/layout/prepare/GNU/Linux/100_include_partition_code.sh
428f4d
index 13c69ce8..2a2bc33f 100644
428f4d
--- a/usr/share/rear/layout/prepare/GNU/Linux/100_include_partition_code.sh
428f4d
+++ b/usr/share/rear/layout/prepare/GNU/Linux/100_include_partition_code.sh
428f4d
@@ -24,6 +24,7 @@ fi
428f4d
 ### Prepare a disk for partitioning/general usage.
428f4d
 create_disk() {
428f4d
     local component disk size label junk
428f4d
+    local blocksize layout dasdtype dasdcyls junk2
428f4d
     read component disk size label junk < <(grep "^disk $1 " "$LAYOUT_FILE")
428f4d
 
428f4d
     ### Disks should be block devices.
428f4d
@@ -67,7 +68,8 @@ sync
428f4d
 
428f4d
 EOF
428f4d
 
428f4d
-    create_partitions "$disk" "$label"
428f4d
+    # $junk can contain useful DASD-specific fields
428f4d
+    create_partitions "$disk" "$label" "$junk"
428f4d
 
428f4d
     cat >> "$LAYOUT_CODE" <
428f4d
 # Make sure device nodes are visible (eg. in RHEL4)
428f4d
@@ -93,6 +95,11 @@ create_partitions() {
428f4d
     ### List partition types/names to detect disk label type.
428f4d
     local -a names=()
428f4d
     local part disk size pstart name junk
428f4d
+    local orig_block_size layout dasdtype dasdcyls junk2
428f4d
+    if [ "$label" == dasd ]; then
428f4d
+        # dasd has more fields - junk is not junk anymore
428f4d
+        read orig_block_size layout dasdtype dasdcyls junk2 <<<$3
428f4d
+    fi
428f4d
     while read part disk size pstart name junk ; do
428f4d
         names+=( $name )
428f4d
         case $name in
428f4d
@@ -227,10 +234,12 @@ EOF
428f4d
             if [[ "$end" ]] ; then
428f4d
                 end=$( mathlib_calculate "$end - 1" )
428f4d
             fi
428f4d
-            if [[ "$ARCH" == "Linux-s390" ]] ; then
428f4d
-                # if dasd disk is LDL formated, then do not partition it, because it is partitioned and can take only partition
428f4d
-                if [[ ! "${listDasdLdl[@]}" =~ "$device" ]] ; then
428f4d
-                    echo "not LDL dasd formated disk, create a partition"
428f4d
+            if [[ "$ARCH" == "Linux-s390" && "$label" == dasd ]] ; then
428f4d
+                # LDL formatted disks are already partitioned and should not be partitioned with parted or fdasd , it will fail
428f4d
+                if [ "$layout" == LDL ]; then
428f4d
+                    Debug "$device: LDL formatted DASD, do not create a partition"
428f4d
+                else
428f4d
+                    Debug "$device: ${layout} formatted DASD, create a partition"
428f4d
                     cat >> "$LAYOUT_CODE" <
428f4d
 create_disk_partition "$device" "$name" $number $start $end
428f4d
 EOF
428f4d
diff --git a/usr/share/rear/layout/prepare/Linux-s390/090_include_dasd_code.sh b/usr/share/rear/layout/prepare/Linux-s390/090_include_dasd_code.sh
428f4d
new file mode 100644
428f4d
index 00000000..fc5be463
428f4d
--- /dev/null
428f4d
+++ b/usr/share/rear/layout/prepare/Linux-s390/090_include_dasd_code.sh
428f4d
@@ -0,0 +1,17 @@
428f4d
+# Generate code for low-level formatting of a DASD
428f4d
+
428f4d
+dasd_format_code() {
428f4d
+    local device size blocksize layout dasdtype dasdcyls
428f4d
+
428f4d
+    device="$1"
428f4d
+    size="$2"
428f4d
+    blocksize="$3"
428f4d
+    layout="$4"
428f4d
+    dasdtype="$5"
428f4d
+    dasdcyls="$6"
428f4d
+
428f4d
+    has_binary dasdfmt || Error "Cannot find 'dasdfmt' command"
428f4d
+
428f4d
+    LogPrint 'dasdfmt:' $device ', blocksize:' $blocksize ', layout:' $layout
428f4d
+    echo "dasdfmt -b $blocksize -d $layout -y $device"
428f4d
+}
428f4d
diff --git a/usr/share/rear/layout/prepare/Linux-s390/205_s390_enable_disk.sh b/usr/share/rear/layout/prepare/Linux-s390/205_s390_enable_disk.sh
428f4d
index c4037e02..0f6946a9 100644
428f4d
--- a/usr/share/rear/layout/prepare/Linux-s390/205_s390_enable_disk.sh
428f4d
+++ b/usr/share/rear/layout/prepare/Linux-s390/205_s390_enable_disk.sh
428f4d
@@ -2,45 +2,36 @@
428f4d
 # Before we can compare or map DASD devices we must enable them.
428f4d
 # This operation is only needed during "rear recover".
428f4d
 
428f4d
-format_s390_disk() {
428f4d
-    LogPrint "run dasdfmt"
428f4d
-    while read line ; do
428f4d
-        LogPrint 'dasdfmt:' "$line"
428f4d
-        # example format command: dasdfmt -b 4096 -d cdl -y /dev/dasda
428f4d
-        # where
428f4d
-        #  b is the block size
428f4d
-        #  d is the layout: 
428f4d
-        #   cdl - compatible disk layout (can be shared with zos and zvm apps)
428f4d
-        #   ldl - linux disk layout
428f4d
-        #  y - answer yes
428f4d
-        device=$( echo $line | awk '{ print $7 }' )
428f4d
-        blocksize=$( echo $line | awk '{ print $3 }' )
428f4d
-        layout=$( echo $line | awk '{ print tolower($5) }' )
428f4d
-        if [[ "$layout" == "ldl" ]] ; then
428f4d
-            # listDasdLdl contains devices such as /dev/dasdb that are formatted as LDL
428f4d
-            # LDL formatted disks are already partitioned and should not be partitioned with parted or fdasd , it will fail
428f4d
-            # this var, listDasdLdl, is used by 100_include_partition_code.sh to exclude writing partition code to diskrestore.sh for LDL disks
428f4d
-            listDasdLdl+=( $device )
428f4d
-            LogPrint "LDL disk added to listDasdLdl:" ${listDasdLdl[@]}
428f4d
-        fi
428f4d
-        LogPrint 'dasdfmt:' $device ', blocksize:' $blocksize ', layout:' $layout
428f4d
-        # dasd format
428f4d
-        dasdfmt -b $blocksize -d $layout -y $device
428f4d
-    done < <( grep "^dasdfmt " "$LAYOUT_FILE" )
428f4d
-}
428f4d
-
428f4d
+DISK_MAPPING_HINTS=()
428f4d
 
428f4d
 enable_s390_disk() {
428f4d
+    local keyword device bus len newname
428f4d
+
428f4d
     LogPrint "run chccwdev"
428f4d
-    while read line ; do
428f4d
-        LogPrint 'dasd channel:' "$line"
428f4d
-        device=$( echo $line | awk '{ print $4 }' )
428f4d
-        bus=$( echo $line | awk '{ print $2 }' )
428f4d
-        channel=$( echo $line | awk '{ print $5 }' )
428f4d
-        LogPrint 'chccwdev:' $device ', bus:' $bus ', channel:' $channel
428f4d
-        # dasd channel enable
428f4d
-        chccwdev -e $bus
428f4d
-    done < <( grep "^dasd_channel " "$LAYOUT_FILE" )
428f4d
+    while read len device bus ; do
428f4d
+        # this while loop must be outside the pipeline so that variables propagate outside
428f4d
+        # (pipelines run in subshells)
428f4d
+        LogPrint "Enabling DASD $device with virtual device number $bus"
428f4d
+        if chccwdev -e $bus ; then
428f4d
+            newname=$(lsdasd $bus | awk "/$bus/ { print \$3}" )
428f4d
+            if ! test $newname ; then
428f4d
+                LogPrintError "New device with virtual device number $bus not found among online DASDs"
428f4d
+                continue
428f4d
+            fi
428f4d
+            if [ "$newname" != "$device" ]; then
428f4d
+                LogPrint "original DASD '$device' changed name to '$newname'"
428f4d
+                test "$MIGRATION_MODE" || MIGRATION_MODE='true'
428f4d
+            fi
428f4d
+            DISK_MAPPING_HINTS+=( "/dev/$device /dev/$newname" )
428f4d
+        else
428f4d
+            LogPrintError "Failed to enable $bus"
428f4d
+        fi
428f4d
+    done < <( grep "^dasd_channel " "$LAYOUT_FILE" | while read keyword bus device; do
428f4d
+                  # add device name length, so that "dasdb" sorts properly before "dasdaa"
428f4d
+                  # we need to create devices in the same order as the kernel orders them (by minor number)
428f4d
+                  # - this increases the chance that they will get identical names
428f4d
+                  echo ${#device} $device $bus
428f4d
+                  done | sort -k1n -k2 )
428f4d
 }
428f4d
 
428f4d
 # May need to look at $OS_VENDOR also as DASD disk layout is distro specific:
428f4d
@@ -49,7 +40,6 @@ case $OS_MASTER_VENDOR in
428f4d
         # "Fedora" also handles Red Hat
428f4d
         # "Debian" also handles Ubuntu
428f4d
         enable_s390_disk
428f4d
-        format_s390_disk
428f4d
         ;;
428f4d
     (*)
428f4d
         LogPrintError "No code for DASD disk device enablement on $OS_MASTER_VENDOR"
428f4d
diff --git a/usr/share/rear/layout/prepare/Linux-s390/360_generate_dasd_format_code.sh b/usr/share/rear/layout/prepare/Linux-s390/360_generate_dasd_format_code.sh
428f4d
new file mode 100644
428f4d
index 00000000..14bb942d
428f4d
--- /dev/null
428f4d
+++ b/usr/share/rear/layout/prepare/Linux-s390/360_generate_dasd_format_code.sh
428f4d
@@ -0,0 +1,51 @@
428f4d
+# DASD_FORMAT_CODE is the script to recreate the dasd formatting (dasdformat.sh).
428f4d
+
428f4d
+local component disk size label junk
428f4d
+local blocksize layout dasdtype dasdcyls junk2
428f4d
+
428f4d
+
428f4d
+save_original_file "$DASD_FORMAT_CODE"
428f4d
+
428f4d
+# Initialize
428f4d
+
428f4d
+echo '#!/bin/bash' >"$DASD_FORMAT_CODE"
428f4d
+
428f4d
+# Show the current output of lsdasd, it can be useful for identifying disks
428f4d
+# (in particular it shows the Linux device name <-> virtual device number mapping,
428f4d
+# formatted / unformatted status and the number/size of blocks when formatted )
428f4d
+echo "# Current output of 'lsdasd':" >>"$DASD_FORMAT_CODE"
428f4d
+lsdasd | sed -e 's/^/# /' >>"$DASD_FORMAT_CODE"
428f4d
+
428f4d
+cat <<EOF >>"$DASD_FORMAT_CODE"
428f4d
+
428f4d
+LogPrint "Start DASD format restoration."
428f4d
+
428f4d
+set -e
428f4d
+set -x
428f4d
+
428f4d
+EOF
428f4d
+
428f4d
+while read component disk size label junk; do
428f4d
+    if [ "$label" == dasd ]; then
428f4d
+        # Ignore excluded components.
428f4d
+        # Normally they are removed in 520_exclude_components.sh,
428f4d
+        # but we run before it, so we must skip them here as well.
428f4d
+        if IsInArray "$disk" "${EXCLUDE_RECREATE[@]}" ; then
428f4d
+            Log "Excluding $disk from DASD reformatting."
428f4d
+            continue
428f4d
+        fi
428f4d
+        # dasd has more fields - junk is not junk anymore
428f4d
+        read blocksize layout dasdtype dasdcyls junk2 <<<$junk
428f4d
+        dasd_format_code "$disk" "$size" "$blocksize" "$layout" "$dasdtype" "$dasdcyls" >> "$DASD_FORMAT_CODE" || \
428f4d
+            LogPrintError "Error producing DASD format code for $disk"
428f4d
+    fi
428f4d
+done < <(grep "^disk " "$LAYOUT_FILE")
428f4d
+
428f4d
+cat <<EOF >>"$DASD_FORMAT_CODE"
428f4d
+
428f4d
+set +x
428f4d
+set +e
428f4d
+
428f4d
+LogPrint "DASD(s) formatted."
428f4d
+
428f4d
+EOF
428f4d
diff --git a/usr/share/rear/layout/prepare/Linux-s390/370_confirm_dasd_format_code.sh b/usr/share/rear/layout/prepare/Linux-s390/370_confirm_dasd_format_code.sh
428f4d
new file mode 100644
428f4d
index 00000000..5ba4edd5
428f4d
--- /dev/null
428f4d
+++ b/usr/share/rear/layout/prepare/Linux-s390/370_confirm_dasd_format_code.sh
428f4d
@@ -0,0 +1,69 @@
428f4d
+# adapted from 100_confirm_layout_code.sh
428f4d
+#
428f4d
+# Let the user confirm the
428f4d
+# DASD format code (dasdformat.sh) script.
428f4d
+#
428f4d
+
428f4d
+is_false "$FORMAT_DASDS" && return 0
428f4d
+
428f4d
+# Show the user confirmation dialog in any case but when not in migration mode
428f4d
+# automatically proceed with less timeout USER_INPUT_INTERRUPT_TIMEOUT (by default 10 seconds)
428f4d
+# to avoid longer delays (USER_INPUT_TIMEOUT is by default 300 seconds) in case of unattended recovery:
428f4d
+# (taken from 120_confirm_wipedisk_disks.sh)
428f4d
+local timeout="$USER_INPUT_TIMEOUT"
428f4d
+is_true "$MIGRATION_MODE" || timeout="$USER_INPUT_INTERRUPT_TIMEOUT"
428f4d
+
428f4d
+rear_workflow="rear $WORKFLOW"
428f4d
+original_disk_space_usage_file="$VAR_DIR/layout/config/df.txt"
428f4d
+rear_shell_history="$( echo -e "cd $VAR_DIR/layout/\nvi $DASD_FORMAT_CODE\nless $DASD_FORMAT_CODE" )"
428f4d
+unset choices
428f4d
+choices[0]="Confirm DASD format script and continue '$rear_workflow'"
428f4d
+choices[1]="Edit DASD format script ($DASD_FORMAT_CODE)"
428f4d
+choices[2]="View DASD format script ($DASD_FORMAT_CODE)"
428f4d
+choices[3]="View original disk space usage ($original_disk_space_usage_file)"
428f4d
+choices[4]="Confirm what is currently on the DASDs, skip formatting them and continue '$rear_workflow'"
428f4d
+choices[5]="Use Relax-and-Recover shell and return back to here"
428f4d
+choices[6]="Abort '$rear_workflow'"
428f4d
+prompt="Confirm or edit the DASD format script"
428f4d
+choice=""
428f4d
+wilful_input=""
428f4d
+# When USER_INPUT_DASD_FORMAT_CODE_CONFIRMATION has any 'true' value be liberal in what you accept and
428f4d
+# assume choices[0] 'Confirm DASD format' was actually meant:
428f4d
+is_true "$USER_INPUT_DASD_FORMAT_CODE_CONFIRMATION" && USER_INPUT_DASD_FORMAT_CODE_CONFIRMATION="${choices[0]}"
428f4d
+while true ; do
428f4d
+    choice="$( UserInput -I DASD_FORMAT_CODE_CONFIRMATION -t "$timeout" -p "$prompt" -D "${choices[0]}" "${choices[@]}" )" && wilful_input="yes" || wilful_input="no"
428f4d
+    case "$choice" in
428f4d
+        (${choices[0]})
428f4d
+            # Confirm DASD format file and continue:
428f4d
+            is_true "$wilful_input" && LogPrint "User confirmed DASD format script" || LogPrint "Continuing '$rear_workflow' by default"
428f4d
+            break
428f4d
+            ;;
428f4d
+        (${choices[1]})
428f4d
+            # Run 'vi' with the original STDIN STDOUT and STDERR when 'rear' was launched by the user:
428f4d
+            vi $DASD_FORMAT_CODE 0<&6 1>&7 2>&8
428f4d
+            ;;
428f4d
+        (${choices[2]})
428f4d
+            # Run 'less' with the original STDIN STDOUT and STDERR when 'rear' was launched by the user:
428f4d
+            less $DASD_FORMAT_CODE 0<&6 1>&7 2>&8
428f4d
+            ;;
428f4d
+        (${choices[3]})
428f4d
+            # Run 'less' with the original STDIN STDOUT and STDERR when 'rear' was launched by the user:
428f4d
+            less $original_disk_space_usage_file 0<&6 1>&7 2>&8
428f4d
+            ;;
428f4d
+        (${choices[4]})
428f4d
+            # Confirm what is on the disks and continue without formatting
428f4d
+            FORMAT_DASDS="false"
428f4d
+            ;;
428f4d
+        (${choices[5]})
428f4d
+            # rear_shell runs 'bash' with the original STDIN STDOUT and STDERR when 'rear' was launched by the user:
428f4d
+            rear_shell "" "$rear_shell_history"
428f4d
+            ;;
428f4d
+        (${choices[6]})
428f4d
+            abort_dasd_format
428f4d
+            Error "User chose to abort '$rear_workflow' in ${BASH_SOURCE[0]}"
428f4d
+            ;;
428f4d
+    esac
428f4d
+done
428f4d
+
428f4d
+chmod +x $DASD_FORMAT_CODE
428f4d
+
428f4d
diff --git a/usr/share/rear/layout/prepare/Linux-s390/400_run_dasd_format_code.sh b/usr/share/rear/layout/prepare/Linux-s390/400_run_dasd_format_code.sh
428f4d
new file mode 100644
428f4d
index 00000000..16451af6
428f4d
--- /dev/null
428f4d
+++ b/usr/share/rear/layout/prepare/Linux-s390/400_run_dasd_format_code.sh
428f4d
@@ -0,0 +1,185 @@
428f4d
+# adapted from 200_run_layout_code.sh
428f4d
+#
428f4d
+# Run the DASD format code (dasdformat.sh)
428f4d
+# again and again until it succeeds or the user aborts.
428f4d
+#
428f4d
+
428f4d
+# Skip DASD formatting when the user has explicitly specified to not format them
428f4d
+# or when the user selected "Confirm what is currently on the DASDs, skip formatting them"
428f4d
+# in 370_confirm_dasd_format_code.sh
428f4d
+
428f4d
+is_false "$FORMAT_DASDS" && return 0
428f4d
+
428f4d
+function lsdasd_output () {
428f4d
+    lsdasd 1>> >( tee -a "$RUNTIME_LOGFILE" 1>&7 )
428f4d
+}
428f4d
+
428f4d
+rear_workflow="rear $WORKFLOW"
428f4d
+original_disk_space_usage_file="$VAR_DIR/layout/config/df.txt"
428f4d
+rear_shell_history="$( echo -e "cd $VAR_DIR/layout/\nvi $DASD_FORMAT_CODE\nless $RUNTIME_LOGFILE" )"
428f4d
+wilful_input=""
428f4d
+
428f4d
+unset choices
428f4d
+choices[0]="Rerun DASD format script ($DASD_FORMAT_CODE)"
428f4d
+choices[1]="View '$rear_workflow' log file ($RUNTIME_LOGFILE)"
428f4d
+choices[2]="Edit DASD format script ($DASD_FORMAT_CODE)"
428f4d
+choices[3]="Show what is currently on the disks ('lsdasd' device list)"
428f4d
+choices[4]="View original disk space usage ($original_disk_space_usage_file)"
428f4d
+choices[5]="Use Relax-and-Recover shell and return back to here"
428f4d
+choices[6]="Confirm what is currently on the disks and continue '$rear_workflow'"
428f4d
+choices[7]="Abort '$rear_workflow'"
428f4d
+prompt="DASD format choices"
428f4d
+
428f4d
+choice=""
428f4d
+# When USER_INPUT_DASD_FORMAT_CODE_RUN has any 'true' value be liberal in what you accept and
428f4d
+# assume choices[0] 'Rerun DASD format script' was actually meant
428f4d
+# regardless that this likely lets 'rear recover' run an endless loop
428f4d
+# of failed DASD format attempts but ReaR must obey what the user specified
428f4d
+# (perhaps it is intended to let 'rear recover' loop here until an admin intervenes):
428f4d
+is_true "$USER_INPUT_DASD_FORMAT_CODE_RUN" && USER_INPUT_DASD_FORMAT_CODE_RUN="${choices[0]}"
428f4d
+
428f4d
+unset confirm_choices
428f4d
+confirm_choices[0]="Confirm recreated DASD format and continue '$rear_workflow'"
428f4d
+confirm_choices[1]="Go back one step to redo DASD format"
428f4d
+confirm_choices[2]="Use Relax-and-Recover shell and return back to here"
428f4d
+confirm_choices[3]="Abort '$rear_workflow'"
428f4d
+confirm_prompt="Confirm the recreated DASD format or go back one step"
428f4d
+confirm_choice=""
428f4d
+# When USER_INPUT_DASD_FORMAT_MIGRATED_CONFIRMATION has any 'true' value be liberal in what you accept and
428f4d
+# assume confirm_choices[0] 'Confirm recreated DASD format and continue' was actually meant:
428f4d
+is_true "$USER_INPUT_DASD_FORMAT_MIGRATED_CONFIRMATION" && USER_INPUT_DASD_FORMAT_MIGRATED_CONFIRMATION="${confirm_choices[0]}"
428f4d
+
428f4d
+# Run the DASD format code (dasdformat.sh)
428f4d
+# again and again until it succeeds or the user aborts
428f4d
+# or the user confirms to continue with what is currently on the disks
428f4d
+# (the user may have setup manually what he needs via the Relax-and-Recover shell):
428f4d
+while true ; do
428f4d
+    prompt="The DASD format had failed"
428f4d
+    # After switching to recreating with DASD format script
428f4d
+    # change choices[0] from "Run ..." to "Rerun ...":
428f4d
+    choices[0]="Rerun DASD format script ($DASD_FORMAT_CODE)"
428f4d
+    # Run DASD_FORMAT_CODE in a sub-shell because it sets 'set -e'
428f4d
+    # so that it exits the running shell in case of an error
428f4d
+    # but that exit must not exit this running bash here:
428f4d
+    ( source $DASD_FORMAT_CODE )
428f4d
+    # One must explicitly test whether or not $? is zero in a separated bash command
428f4d
+    # because with bash 3.x and bash 4.x code like
428f4d
+    #   # ( set -e ; cat qqq ; echo "hello" ) && echo ok || echo failed
428f4d
+    #   cat: qqq: No such file or directory
428f4d
+    #   hello
428f4d
+    #   ok
428f4d
+    # does not work as one may expect (cf. what "man bash" describes for 'set -e').
428f4d
+    # There is a subtle behavioural difference between bash 3.x and bash 4.x
428f4d
+    # when a script that has 'set -e' set gets sourced:
428f4d
+    # With bash 3.x the 'set -e' inside the sourced script is effective:
428f4d
+    #   # echo 'set -e ; cat qqq ; echo hello' >script.sh
428f4d
+    #   # ( source script.sh ) && echo ok || echo failed
428f4d
+    #   cat: qqq: No such file or directory
428f4d
+    #   failed
428f4d
+    # With bash 4.x the 'set -e' inside the sourced script gets noneffective:
428f4d
+    #   # echo 'set -e ; cat qqq ; echo hello' >script.sh
428f4d
+    #   # ( source script.sh ) && echo ok || echo failed
428f4d
+    #   cat: qqq: No such file or directory
428f4d
+    #   hello
428f4d
+    #   ok
428f4d
+    # With bash 3.x and bash 4.x testing $? in a separated bash command
428f4d
+    # keeps the 'set -e' inside the sourced script effective:
428f4d
+    #   # echo 'set -e ; cat qqq ; echo hello' >script.sh
428f4d
+    #   # ( source script.sh ) ; (( $? == 0 )) && echo ok || echo failed
428f4d
+    #   cat: qqq: No such file or directory
428f4d
+    #   failed
428f4d
+    # See also https://github.com/rear/rear/pull/1573#issuecomment-344303590
428f4d
+    if (( $? == 0 )) ; then
428f4d
+        prompt="DASD format had been successful"
428f4d
+        # When DASD_FORMAT_CODE succeeded and when not in migration mode
428f4d
+        # break the outer while loop and continue the "rear recover" workflow
428f4d
+        # which means continue with restoring the backup:
428f4d
+        is_true "$MIGRATION_MODE" || break
428f4d
+        # When DASD_FORMAT_CODE succeeded in migration mode
428f4d
+        # let the user explicitly confirm the recreated (and usually migrated) format
428f4d
+        # before continuing the "rear recover" workflow with restoring the backup.
428f4d
+        # Show the recreated DASD format to the user on his terminal (and also in the log file):
428f4d
+        LogPrint "Recreated DASD format:"
428f4d
+        lsdasd_output
428f4d
+        # Run an inner while loop with a user dialog so that the user can inspect the recreated DASD format
428f4d
+        # and perhaps even manually fix the recreated DASD format if it is not what the user wants
428f4d
+        # (e.g. by using the Relax-and-Recover shell and returning back to this user dialog):
428f4d
+        while true ; do
428f4d
+            confirm_choice="$( UserInput -I DASD_FORMAT_MIGRATED_CONFIRMATION -p "$confirm_prompt" -D "${confirm_choices[0]}" "${confirm_choices[@]}" )" && wilful_input="yes" || wilful_input="no"
428f4d
+            case "$confirm_choice" in
428f4d
+                (${confirm_choices[0]})
428f4d
+                    # Confirm recreated DASD format and continue:
428f4d
+                    is_true "$wilful_input" && LogPrint "User confirmed recreated DASD format" || LogPrint "Continuing with recreated DASD format by default"
428f4d
+                    # Break the outer while loop and continue with restoring the backup:
428f4d
+                    break 2
428f4d
+                    ;;
428f4d
+                (${confirm_choices[1]})
428f4d
+                    # Go back one step to redo DASD format:
428f4d
+                    # Only break the inner while loop (i.e. this user dialog loop)
428f4d
+                    # and  continue with the next user dialog below:
428f4d
+                    break
428f4d
+                    ;;
428f4d
+                (${confirm_choices[2]})
428f4d
+                    # rear_shell runs 'bash' with the original STDIN STDOUT and STDERR when 'rear' was launched by the user:
428f4d
+                    rear_shell "" "$rear_shell_history"
428f4d
+                    ;;
428f4d
+                (${confirm_choices[3]})
428f4d
+                    abort_dasd_format
428f4d
+                    Error "User did not confirm the recreated DASD format but aborted '$rear_workflow' in ${BASH_SOURCE[0]}"
428f4d
+                    ;;
428f4d
+            esac
428f4d
+        done
428f4d
+    fi
428f4d
+    # Run an inner while loop with a user dialog so that the user can fix things
428f4d
+    # when DASD_FORMAT_CODE failed.
428f4d
+    # Such a fix does not necessarily mean the user must change
428f4d
+    # the dasdformat.sh script when DASD_FORMAT_CODE failed.
428f4d
+    # The user might also fix things by only using the Relax-and-Recover shell and
428f4d
+    # then confirm what is on the disks and continue with restoring the backup
428f4d
+    # or abort this "rear recover" run to re-try from scratch.
428f4d
+    while true ; do
428f4d
+        choice="$( UserInput -I DASD_FORMAT_CODE_RUN -p "$prompt" -D "${choices[0]}" "${choices[@]}" )" && wilful_input="yes" || wilful_input="no"
428f4d
+        case "$choice" in
428f4d
+            (${choices[0]})
428f4d
+                # Rerun or run (after switching to recreating with DASD format script) DASD format script:
428f4d
+                is_true "$wilful_input" && LogPrint "User runs DASD format script" || LogPrint "Running DASD format script by default"
428f4d
+                # Only break the inner while loop (i.e. the user dialog loop):
428f4d
+                break
428f4d
+                ;;
428f4d
+            (${choices[1]})
428f4d
+                # Run 'less' with the original STDIN STDOUT and STDERR when 'rear' was launched by the user:
428f4d
+                less $RUNTIME_LOGFILE 0<&6 1>&7 2>&8
428f4d
+                ;;
428f4d
+            (${choices[2]})
428f4d
+                # Run 'vi' with the original STDIN STDOUT and STDERR when 'rear' was launched by the user:
428f4d
+                vi $DASD_FORMAT_CODE 0<&6 1>&7 2>&8
428f4d
+                ;;
428f4d
+            (${choices[3]})
428f4d
+                LogPrint "This is the current list of DASDs:"
428f4d
+                lsdasd_output
428f4d
+                ;;
428f4d
+            (${choices[4]})
428f4d
+                # Run 'less' with the original STDIN STDOUT and STDERR when 'rear' was launched by the user:
428f4d
+                less $original_disk_space_usage_file 0<&6 1>&7 2>&8
428f4d
+                ;;
428f4d
+            (${choices[5]})
428f4d
+                # rear_shell runs 'bash' with the original STDIN STDOUT and STDERR when 'rear' was launched by the user:
428f4d
+                rear_shell "" "$rear_shell_history"
428f4d
+                ;;
428f4d
+            (${choices[6]})
428f4d
+                # Confirm what is on the disks and continue:
428f4d
+                # Break the outer while loop and continue with restoring the backup:
428f4d
+                break 2
428f4d
+                ;;
428f4d
+            (${choices[7]})
428f4d
+                abort_dasd_format
428f4d
+                Error "User chose to abort '$rear_workflow' in ${BASH_SOURCE[0]}"
428f4d
+                ;;
428f4d
+        esac
428f4d
+    done
428f4d
+# End of the outer while loop:
428f4d
+done
428f4d
+
428f4d
+# Local functions must be 'unset' because bash does not support 'local function ...'
428f4d
+# cf. https://unix.stackexchange.com/questions/104755/how-can-i-create-a-local-function-in-my-bashrc
428f4d
+unset -f lsdasd_output
428f4d
diff --git a/usr/share/rear/layout/prepare/default/010_prepare_files.sh b/usr/share/rear/layout/prepare/default/010_prepare_files.sh
428f4d
index 7a980e63..4191be33 100644
428f4d
--- a/usr/share/rear/layout/prepare/default/010_prepare_files.sh
428f4d
+++ b/usr/share/rear/layout/prepare/default/010_prepare_files.sh
428f4d
@@ -7,6 +7,8 @@ LAYOUT_CODE="$VAR_DIR/layout/diskrestore.sh"
428f4d
 LAYOUT_XFS_OPT_DIR="$VAR_DIR/layout/xfs"
428f4d
 LAYOUT_XFS_OPT_DIR_RESTORE="$LAYOUT_XFS_OPT_DIR/restore"
428f4d
 
428f4d
+DASD_FORMAT_CODE="$VAR_DIR/layout/dasdformat.sh"
428f4d
+
428f4d
 FS_UUID_MAP="$VAR_DIR/layout/fs_uuid_mapping"
428f4d
 LUN_WWID_MAP="$VAR_DIR/layout/lun_wwid_mapping"
428f4d
 
428f4d
diff --git a/usr/share/rear/layout/prepare/default/250_compare_disks.sh b/usr/share/rear/layout/prepare/default/250_compare_disks.sh
428f4d
index c459b928..751433ba 100644
428f4d
--- a/usr/share/rear/layout/prepare/default/250_compare_disks.sh
428f4d
+++ b/usr/share/rear/layout/prepare/default/250_compare_disks.sh
428f4d
@@ -54,7 +54,9 @@ local more_than_one_same_orig_size=''
428f4d
 # Cf. the "Compare disks one by one" code below:
428f4d
 while read disk dev size junk ; do
428f4d
     if IsInArray "$size" "${original_system_used_disk_sizes[@]}" ; then
428f4d
-        more_than_one_same_orig_size='true'
428f4d
+        if ! has_mapping_hint "$dev" ; then
428f4d
+            more_than_one_same_orig_size='true'
428f4d
+        fi
428f4d
     else
428f4d
         original_system_used_disk_sizes+=( "$size" )
428f4d
     fi
428f4d
@@ -109,14 +111,17 @@ fi
428f4d
 # No further disk comparisons are needed when MIGRATION_MODE is already set true above:
428f4d
 if ! is_true "$MIGRATION_MODE" ; then
428f4d
     # Compare original disks and their possible target disk one by one:
428f4d
-    while read disk dev size junk ; do
428f4d
-        dev=$( get_sysfs_name $dev )
428f4d
+    while read disk devnode size junk ; do
428f4d
+        dev=$( get_sysfs_name $devnode )
428f4d
         Log "Comparing $dev"
428f4d
         if test -e "/sys/block/$dev" ; then
428f4d
             Log "Device /sys/block/$dev exists"
428f4d
             newsize=$( get_disk_size $dev )
428f4d
             if test "$newsize" -eq "$size" ; then
428f4d
                 LogPrint "Device $dev has expected (same) size $size bytes (will be used for '$WORKFLOW')"
428f4d
+            elif test "$( get_mapping_hint $devnode )" == "$devnode" ; then
428f4d
+                Debug "Found identical mapping hint ${devnode} -> ${devnode}"
428f4d
+                LogPrint "Device $dev found according to mapping hints (will be used for '$WORKFLOW')"
428f4d
             else
428f4d
                 LogPrint "Device $dev has size $newsize bytes but $size bytes is expected (needs manual configuration)"
428f4d
                 MIGRATION_MODE='true'
428f4d
diff --git a/usr/share/rear/layout/prepare/default/300_map_disks.sh b/usr/share/rear/layout/prepare/default/300_map_disks.sh
428f4d
index 2e90768c..468aa35c 100644
428f4d
--- a/usr/share/rear/layout/prepare/default/300_map_disks.sh
428f4d
+++ b/usr/share/rear/layout/prepare/default/300_map_disks.sh
428f4d
@@ -112,7 +112,14 @@ while read keyword orig_device orig_size junk ; do
428f4d
     # Continue with next original device when it is already used as source in the mapping file:
428f4d
     is_mapping_source "$orig_device" && continue
428f4d
     # First, try to find if there is a current disk with same name and same size as the original:
428f4d
-    sysfs_device_name="$( get_sysfs_name "$orig_device" )"
428f4d
+    # (possibly influenced by mapping hints if known)
428f4d
+    if has_mapping_hint "$orig_device" ; then
428f4d
+        candidate_target_device_name="$( get_mapping_hint "$orig_device" )"
428f4d
+        Debug "Using mapping hint ${candidate_target_device_name} as candidate for $orig_device mapping"
428f4d
+    else
428f4d
+        candidate_target_device_name="$orig_device"
428f4d
+    fi
428f4d
+    sysfs_device_name="$( get_sysfs_name "$candidate_target_device_name" )"
428f4d
     current_device="/sys/block/$sysfs_device_name"
428f4d
     if test -e $current_device ; then
428f4d
         current_size=$( get_disk_size $sysfs_device_name )
428f4d
@@ -122,11 +129,16 @@ while read keyword orig_device orig_size junk ; do
428f4d
         # Continue with next one if the current one is already used as target in the mapping file:
428f4d
         is_mapping_target "$preferred_target_device_name" && continue
428f4d
         # Use the current one if it is of same size as the old one:
428f4d
-        if test "$orig_size" -eq "$current_size" ; then
428f4d
+        if has_mapping_hint "$orig_device" || test "$orig_size" -eq "$current_size" ; then
428f4d
             # Ensure the determined target device is really a block device:
428f4d
             if test -b "$preferred_target_device_name" ; then
428f4d
+                if has_mapping_hint "$orig_device" ; then
428f4d
+                    mapping_reason="determined by mapping hint"
428f4d
+                else
428f4d
+                    mapping_reason="same name and same size $current_size"
428f4d
+                fi
428f4d
                 add_mapping "$orig_device" "$preferred_target_device_name"
428f4d
-                LogPrint "Using $preferred_target_device_name (same name and same size) for recreating $orig_device"
428f4d
+                LogPrint "Using $preferred_target_device_name ($mapping_reason) for recreating $orig_device"
428f4d
                 # Continue with next original device in the LAYOUT_FILE:
428f4d
                 continue
428f4d
             fi
428f4d
diff --git a/usr/share/rear/layout/save/GNU/Linux/200_partition_layout.sh b/usr/share/rear/layout/save/GNU/Linux/200_partition_layout.sh
428f4d
index 3ab7357d..da6ce64c 100644
428f4d
--- a/usr/share/rear/layout/save/GNU/Linux/200_partition_layout.sh
428f4d
+++ b/usr/share/rear/layout/save/GNU/Linux/200_partition_layout.sh
428f4d
@@ -362,18 +362,27 @@ Log "Saving disk partitions."
428f4d
 
428f4d
             if [[ $blockd == dasd* && "$ARCH" == "Linux-s390" ]] ; then
428f4d
                 devname=$(get_device_name $disk)
428f4d
+                dasdnum=$( lsdasd | awk "\$3 == \"$blockd\" { print \$1}" )
428f4d
+                dasdstatus=$( lsdasd | awk "\$3 == \"$blockd\" { print \$2}" )
428f4d
+                # ECKD or FBA
428f4d
+                dasdtype=$( lsdasd | awk "\$3 == \"$blockd\" { print \$5}" )
428f4d
+                if [ "$dasdtype" != ECKD ] && [ "$dasdtype" != FBA ]; then
428f4d
+                    LogPrint "Type $dasdtype of DASD $blockd unexpected: neither ECKD nor FBA"
428f4d
+                fi
428f4d
 
428f4d
-                echo "# active dasd bus and channel"
428f4d
-                echo "# bus-id <name device> type"
428f4d
-                echo "dasd_channel $( lsdasd|grep $blockd|awk '{ print $1 " "  $2 " "  $3 " "  $4}' )"
428f4d
-
428f4d
-                echo "# dasdfmt - disk layout is either cdl for the compatible disk layout (default) or ldl"
428f4d
-                echo "#  example usage: dasdfmt -b 4096 -d cdl -y /dev/dasda"
428f4d
-                layout=$(dasdview -x  /dev/$blockd|grep "^format"|awk '{print $7}')
428f4d
-                blocksize=$( dasdview -i  /dev/$blockd|grep blocksize|awk '{print $6}' )
428f4d
-                echo "# dasdfmt $devname"
428f4d
-                echo "# dasdfmt -b <blocksize> -d <layout> -y <devname>"
428f4d
-                echo "dasdfmt -b $blocksize -d $layout -y $devname"
428f4d
+                echo "# every DASD bus and channel"
428f4d
+                echo "# Format: dasd_channel <bus-id> <device name>"
428f4d
+                echo "dasd_channel $dasdnum $blockd"
428f4d
+
428f4d
+                # We need to print the dasd_channel line even for ignored devices,
428f4d
+                # otherwise we could have naming gaps and naming would change when
428f4d
+                # recreating layout.
428f4d
+                # E.g. if dasda is ignored, and dasdb is not, we would create only dasdb
428f4d
+                # during recreation, but it would be named dasda.
428f4d
+                if [ "$dasdstatus" != active ]; then
428f4d
+                    Log "Ignoring $blockd: it is not active (Status is $dasdstatus)"
428f4d
+                    continue
428f4d
+                fi
428f4d
             fi
428f4d
 
428f4d
             #FIXME: exclude *rpmb (Replay Protected Memory Block) for nvme*, mmcblk* and uas
428f4d
@@ -387,11 +396,38 @@ Log "Saving disk partitions."
428f4d
                 devname=$(get_device_name $disk)
428f4d
                 devsize=$(get_disk_size ${disk#/sys/block/})
428f4d
                 disktype=$(parted -s $devname print | grep -E "Partition Table|Disk label" | cut -d ":" -f "2" | tr -d " ")
428f4d
-
428f4d
-                echo "# Disk $devname"
428f4d
-                echo "# Format: disk <devname> <size(bytes)> <partition label type>"
428f4d
-                echo "disk $devname $devsize $disktype"
428f4d
-
428f4d
+                if [ "$disktype" != "dasd" ]; then
428f4d
+                    echo "# Disk $devname"
428f4d
+                    echo "# Format: disk <devname> <size(bytes)> <partition label type>"
428f4d
+                    echo "disk $devname $devsize $disktype"
428f4d
+                elif [[ $blockd == dasd* && "$ARCH" == "Linux-s390" ]] ; then
428f4d
+                    layout=$(dasdview -x $devname |grep "^format"|awk '{print $7}')
428f4d
+                    case "$layout" in
428f4d
+                        (NOT)
428f4d
+                            # NOT -> dasdview has printed "NOT formatted"
428f4d
+                            LogPrintError "Ignoring $blockd: it is not formatted"
428f4d
+                            continue
428f4d
+                            ;;
428f4d
+                        (LDL|CDL)
428f4d
+                            ;;
428f4d
+                        (*)
428f4d
+                            BugError "Invalid 'disk $devname' entry (unknown DASD layout $layout)"
428f4d
+                            ;;
428f4d
+                    esac
428f4d
+                    test $disktype || Error "No partition label type for DASD entry 'disk $devname'"
428f4d
+                    blocksize=$( get_block_size "$blockd" )
428f4d
+                    if ! test $blocksize ; then
428f4d
+                        # fallback - ugly method
428f4d
+                        blocksize=$( dasdview -i $devname |grep blocksize|awk '{print $6}' )
428f4d
+                        test $blocksize || Error "Unknown block size of DASD $devname"
428f4d
+                    fi
428f4d
+                    dasdcyls=$( get_dasd_cylinders "$blockd" )
428f4d
+                    echo "# Disk $devname"
428f4d
+                    echo "# Format: disk <devname> <size(bytes)> <partition label type> <logical block size> <DASD layout> <DASD type> <size(cylinders)>"
428f4d
+                    echo "disk $devname $devsize $disktype $blocksize $layout $dasdtype $dasdcyls"
428f4d
+                else
428f4d
+                    Error "Invalid 'disk $devname' entry (DASD partition label on non-s390 arch $ARCH)"
428f4d
+                fi
428f4d
                 echo "# Partitions on $devname"
428f4d
                 echo "# Format: part <device> <partition size(bytes)> <partition start(bytes)> <partition type|name> <flags> /dev/<partition>"
428f4d
                 extract_partitions "$devname"
428f4d
diff --git a/usr/share/rear/lib/layout-functions.sh b/usr/share/rear/lib/layout-functions.sh
428f4d
index 91c5ff73..4f5b8f6f 100644
428f4d
--- a/usr/share/rear/lib/layout-functions.sh
428f4d
+++ b/usr/share/rear/lib/layout-functions.sh
428f4d
@@ -93,6 +93,12 @@ abort_recreate() {
428f4d
     restore_original_file "$LAYOUT_FILE"
428f4d
 }
428f4d
 
428f4d
+abort_dasd_format() {
428f4d
+    Log "Error detected during DASD formatting."
428f4d
+    Log "Restoring saved original $DASD_FORMAT_FILE"
428f4d
+    restore_original_file "$DASD_FORMAT_FILE"
428f4d
+}
428f4d
+
428f4d
 # Test and log if a component $1 (type $2) needs to be recreated.
428f4d
 create_component() {
428f4d
     local device="$1"
428f4d
@@ -722,6 +728,46 @@ get_block_size() {
428f4d
     fi
428f4d
 }
428f4d
 
428f4d
+# Get the number of cylinders of a DASD.
428f4d
+# The number of cylinders has the advantage of being fixed - size depends on formatting
428f4d
+# and number of cylinders is valid even for unformatted DASDs, size is not.
428f4d
+get_dasd_cylinders() {
428f4d
+    local disk_name="${1##*/}" # /some/path/dasda -> dasda
428f4d
+    local dasd_cyls
428f4d
+
428f4d
+    dasd_cyls=$(dasdview -i /dev/$disk_name | grep cylinders | cut -d ':' -f2 | awk '{print $4}')
428f4d
+    ### Make sure we always return a number
428f4d
+    echo $(( dasd_cyls ))
428f4d
+}
428f4d
+
428f4d
+# Sometimes we know what the new device for the original device should be in a more reliable way
428f4d
+# than by looking at disk sizes. THis information is called "mapping hints". Let's pass them
428f4d
+# to the mapping code using the DISK_MAPPING_HINTS array. Each element of the array has the form
428f4d
+# "/dev/source /dev/target" (space-separated).
428f4d
+
428f4d
+# Output the mapping hint for the original device.
428f4d
+function get_mapping_hint () {
428f4d
+    local device="$1"
428f4d
+    local hint mapping_hint_source mapping_hint_target
428f4d
+
428f4d
+    for hint in "${DISK_MAPPING_HINTS[@]}"; do
428f4d
+        mapping_hint_source=${hint%% *}
428f4d
+        mapping_hint_target=${hint##* }
428f4d
+        if [ "${device}" == "${mapping_hint_source}" ] ; then
428f4d
+            echo "$mapping_hint_target"
428f4d
+            return 0
428f4d
+        fi
428f4d
+    done
428f4d
+    return 1
428f4d
+}
428f4d
+
428f4d
+# Determine if there is a mapping hint for the original device.
428f4d
+function has_mapping_hint () {
428f4d
+    local device="$1"
428f4d
+
428f4d
+    get_mapping_hint "$device" > /dev/null
428f4d
+}
428f4d
+
428f4d
 # Get the UUID of a device.
428f4d
 # Device is something like /dev/sda1.
428f4d
 blkid_uuid_of_device() {