Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More failsafe 200_partition_layout.sh #2802

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 17 additions & 30 deletions usr/share/rear/layout/save/GNU/Linux/200_partition_layout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,16 @@ extract_partitions() {
parted -s $device print > $TMP_DIR/parted
disk_label=$(grep -E "Partition Table|Disk label" $TMP_DIR/parted | cut -d ":" -f "2" | tr -d " ")
fi

# Ensure $disk_label is valid to determine the partition name/type in the next step at 'declare type'
# cf. https://github.com/rear/rear/issues/2801#issuecomment-1122015129
if ! [[ "$disk_label" = "msdos" || "$disk_label" = "gpt" || "$disk_label" = "gpt_sync_mbr" || "$disk_label" = "dasd" ]] ; then
Error "Unsupported partition table '$disk_label' (must be one of 'msdos' 'gpt' 'gpt_sync_mbr' 'dasd')"
fi

cp $TMP_DIR/partitions $TMP_DIR/partitions-data

declare type

### determine partition type for msdos partition tables
# Determine partition type for msdos partition tables:
if [[ "$disk_label" = "msdos" ]] ; then
declare -i has_logical
while read partition_nr size start junk ; do
Expand All @@ -136,8 +139,7 @@ extract_partitions() {
fi
done < $TMP_DIR/partitions-data
fi

### Find partition name for GPT disks.
# Find partition name for GPT disks.
# For the SUSE specific gpt_sync_mbr partitioning scheme
# see https://github.com/rear/rear/issues/544
# For s390 dasd disks parted does not show a partition name/type.
Expand Down Expand Up @@ -184,16 +186,6 @@ extract_partitions() {
else
# In case of GPT the 'type' field contains actually the GPT partition name.
type=$(grep "^$partition_nr:" $TMP_DIR/parted | cut -d ":" -f "6")
# There must not be any empty field in disklayout.conf
# because the fields in disklayout.conf are positional parameters
# that get assigned to variables via the 'read' shell builtin:
test "$type" || type="rear-noname"
# There must not be any IFS character in a field in disklayout.conf
# because IFS characters are used as field separators
# but in particular a GPT partition name can contain spaces
# like 'EFI System Partition' cf. https://github.com/rear/rear/issues/1563
# so that the partition name is stored as a percent-encoded string:
type=$( percent_encode "$type" )
fi
sed -i /^$partition_nr\ /s/$/\ $type/ $TMP_DIR/partitions
done < $TMP_DIR/partitions-data
Expand All @@ -209,34 +201,29 @@ extract_partitions() {
if (( "$line_length" < 10 )) ; then
line=" $line"
fi

if [[ "$FEATURE_PARTED_OLDNAMING" ]] ; then
numberfield="minor"
else
numberfield="number"
fi

number=$(get_columns "$line" "$numberfield" | tr -d " " | tr -d ";")

# In case of GPT the 'type' field contains actually the GPT partition name.
type=$(get_columns "$line" "name" | tr -d " " | tr -d ";")

# There must not be any empty field in disklayout.conf
# because the fields in disklayout.conf are positional parameters
# that get assigned to variables via the 'read' shell builtin:
test "$type" || type="rear-noname"

# There must not be any IFS character in a field in disklayout.conf
# because IFS characters are used as field separators
# but in particular a GPT partition name can contain spaces
# like 'EFI System Partition' cf. https://github.com/rear/rear/issues/1563
# so that the partition name is stored as a percent-encoded string:
type=$( percent_encode "$type" )
fi
sed -i /^$number\ /s/$/\ $type/ $TMP_DIR/partitions
done < <(grep -E '^[ ]*[0-9]' $TMP_DIR/parted)
fi
fi
# There must not be any IFS character in a field in disklayout.conf
# because IFS characters are used as field separators
# but in particular a GPT partition name can contain spaces
# like 'EFI System Partition' cf. https://github.com/rear/rear/issues/1563
# so that the partition name is stored as a percent-encoded string:
type=$( percent_encode "$type" )
# There must not be any empty field in disklayout.conf
# because the fields in disklayout.conf are positional parameters
# that get assigned to variables via the 'read' shell builtin:
test "$type" || type="rear-noname"

declare flags flaglist
### Find the flags given by parted.
Expand Down