Skip to content

Commit

Permalink
Merge pull request #1765 from schabrolles/Fix_partition-replacement
Browse files Browse the repository at this point in the history
Fix partition replacement
  • Loading branch information
schabrolles committed Apr 23, 2018
2 parents d6cf9f8 + 6bc0f31 commit 160e326
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 24 deletions.
6 changes: 6 additions & 0 deletions usr/share/rear/layout/prepare/GNU/Linux/210_load_multipath.sh
Expand Up @@ -83,6 +83,12 @@ blacklist {
esac
done

# start multipathd
if has_binary multipathd &> /dev/null ; then
LogPrint "Starting multipath daemon"
multipathd >&2 && LogPrint "multipathd started" || LogPrint "Failed to start multipathd"
fi

# Search and list mpath device.
if is_true $list_mpath_device ; then
LogPrint "Listing multipath device found"
Expand Down
89 changes: 65 additions & 24 deletions usr/share/rear/lib/layout-functions.sh
Expand Up @@ -695,38 +695,79 @@ function get_part_device_name_format() {
part_name="${device_name}p" # append p between main device and partitions
;;
(*mapper[/!]*)
# Every Linux distribution / version has their own rule to name the multipthed partion device.
#
# Suse:
# Version <12 : always <device>_part<part_num> (same with/without user_friendly_names)
# Version >=12 : always <device>-part<part_num> (same with/without user_friendly_names)
# Question still open for sles10 ...
# RedHat:
# Version <7 : always <device>p<part_num> (same with/without user_friendly_names)
# Version >=7 : if user_friendly_names (default) <device><part_num> else <device>p<part_num>
# Debian:
# if user_firendly_names (default) <device>-part<part_num>
# if NOT user_firendly_names <device>p<part_num>
#

# First we need to know if user_friendly_names is activated (for Fedora/RedHat and Debian/ubuntu)
if multipathd ; then
# check if multipath if using the "user_friendly_names" by default in the current configuration.
user_friendly_names=$(echo "show config" | multipathd -k | awk '/user_friendly_names/ { gsub("\"","") ; print $2 }' | head -n 1 )
fi

case $OS_MASTER_VENDOR in

(SUSE)
# SUSE Linux SLE12 put a "-part" between [mpath device name] and [part number].
# For example /dev/mapper/3600507680c82004cf8000000000000d8-part1.
# But SLES11 uses a "_part" instead. (Let's assume it is the same for SLES10 )
if (( $OS_MASTER_VERSION < 12 )) ; then
# For SUSE before version 12
part_name="${device_name}_part" # append _part between main device and partitions
else
# For SUSE 12 or above
part_name="${device_name}-part" # append -part between main device and partitions
fi
# No need to check if user_friendly_names is activated or not as Suse always apply the same naming convention.

# SUSE Linux SLE12 put a "-part" between [mpath device name] and [part number].
# For example /dev/mapper/3600507680c82004cf8000000000000d8-part1.
# But SLES11 uses a "_part" instead. (Let's assume it is the same for SLES10 )
if (( $OS_MASTER_VERSION < 12 )) ; then
# For SUSE before version 12
part_name="${device_name}_part" # append _part between main device and partitions
else
# For SUSE 12 or above
part_name="${device_name}-part" # append -part between main device and partitions
fi
;;

(Fedora)
# RHEL 7 and above seems to named partitions on multipathed devices with
# [mpath device name] + [part number] like standard disk.
# For example: /dev/mapper/mpatha1

# But the scheme in RHEL 6 need a "p" between [mpath device name] and [part number].
# For exemple: /dev/mapper/mpathap1
if (( $OS_MASTER_VERSION < 7 )) ; then
if is_false "$user_friendly_names" ; then
# RHEL 7 and above seems to named partitions on multipathed devices with
# [mpath device UUID/WWID] + p + [part number] when "user_friendly_names"
# option is FALSE.
# For example: /dev/mapper/3600507680c82004cf8000000000000d8p1
part_name="${device_name}p" # append p between main device and partitions
else
# RHEL 7 and above seems to named partitions on multipathed devices with
# [mpath device name] + [part number] like standard disk when "user_friendly_names"
# option is used (default).
# For example: /dev/mapper/mpatha1

# But the scheme in RHEL 6 need a "p" between [mpath device name] and [part number].
# For exemple: /dev/mapper/mpathap1
if (( $OS_MASTER_VERSION < 7 )) ; then
part_name="${device_name}p" # append p between main device and partitions
else
part_name="${device_name}"
fi
fi
;;

(Debian)
# Ubuntu 16.04 (need to check for other version) named muiltipathed partitions with
# [mpath device name] + "-part" + [part number]
# for example : /dev/mapper/mpatha-part1
part_name="${device_name}-part" # append -part between main device and partitions
if is_false "$user_friendly_names" ; then
# Exceptional case for Debian/ubuntu
# When user_friendly_names is disable, debian based system will name partition
# [mpath device UUID/WWID] + p + [part number]
part_name="${device_name}p"
else
# Default case (user_friendly_name enable)
# Ubuntu 16.04 (need to check for other version) named muiltipathed partitions with
# [mpath device name] + "-part" + [part number]
# for example : /dev/mapper/mpatha-part1
part_name="${device_name}-part" # append -part between main device and partitions
fi
;;

(*)
Expand Down Expand Up @@ -795,9 +836,9 @@ function apply_layout_mappings() {

# Replace all originals with their replacements.
while read original replacement junk ; do
# Replace partitions (we normalize cciss/c0d0p1 to _REAR5_1)
part_base=$(get_part_device_name_format "$original")
sed -i -r "\|$original|s|${part_base}([0-9]+)|$replacement\1|g" "$file_to_migrate"
# Replace partitions with uniq replacement PATTERN (we normalize cciss/c0d0p1 to _REAR5_1)
# Due to multipath partion naming complexity, all known partition naming type (mpatha1,mpathap1,mpatha-part1,mpatha_part1) will be replaced by _REAR"X"_1
sed -i -r "\|$original|s|$original(p)*([-_]part)*([0-9]+)|$replacement\3|g" "$file_to_migrate"

# Replace whole devices
### note that / is a word boundary, so is matched by \<, hence the extra /
Expand Down

0 comments on commit 160e326

Please sign in to comment.