From 4a4c9143a40a326f02ccfc0d023877e225105fe5 Mon Sep 17 00:00:00 2001 From: CentOS Sources Date: Jul 29 2019 12:53:49 +0000 Subject: import cloud-utils-growpart-0.29-2.el7_6.2 --- diff --git a/SOURCES/0002-growpart-fix-bug-when-resizing-a-middle-partition-wi.patch b/SOURCES/0002-growpart-fix-bug-when-resizing-a-middle-partition-wi.patch new file mode 100644 index 0000000..a0a5f13 --- /dev/null +++ b/SOURCES/0002-growpart-fix-bug-when-resizing-a-middle-partition-wi.patch @@ -0,0 +1,142 @@ +From 099bdf30b9c73c6924e632e174a5e988972301df Mon Sep 17 00:00:00 2001 +From: Scott Moser +Date: Wed, 5 Sep 2018 22:32:39 -0400 +Subject: [PATCH] growpart: fix bug when resizing a middle partition with + sgdisk. + +Added a test and made growpart output consistent between sgdisk +and sfdisk resizers. +Thanks to Fred De Backer. + +LP: #1706751 +bzr-revno: 331 + +diff --git a/bin/growpart b/bin/growpart +index 4947ede..2700365 100755 +--- a/bin/growpart ++++ b/bin/growpart +@@ -327,7 +327,9 @@ resize_sfdisk() { + >"${new_out}" || + fail "failed to change size in output" + +- change_info="partition=${PART} start=${pt_start} old: size=${pt_size} end=${pt_end} new: size=${new_size},end=${max_end}" ++ change_info="partition=${PART} start=${pt_start}" ++ change_info="${change_info} old: size=${pt_size} end=${pt_end}" ++ change_info="${change_info} new: size=${new_size} end=${max_end}" + if [ ${DRY_RUN} -ne 0 ]; then + echo "CHANGE: ${change_info}" + { +@@ -436,6 +438,8 @@ resize_sgdisk() { + pt_end=$(awk '$1 == '"${PART}"' { print $3 }' "${pt_data}") && + [ -n "${pt_end}" ] || + fail "${dev}: failed to get end sector" ++ # sgdisk start and end are inclusive. start 2048 length 10 ends at 2057. ++ pt_end=$((pt_end+1)) + pt_size="$((${pt_end} - ${pt_start}))" + + # Get the last usable sector +@@ -475,9 +479,9 @@ resize_sgdisk() { + + # Calculate the new size of the partition + new_size=$((${pt_max} - ${pt_start})) +- old="old: size=${pt_size},end=${pt_end}" +- new="new: size=${new_size},end=${pt_max}" +- change_info="${dev}: start=${pt_start} ${old} ${new}" ++ change_info="partition=${PART} start=${pt_start}" ++ change_info="${change_info} old: size=${pt_size} end=${pt_end}" ++ change_info="${change_info} new: size=${new_size} end=${pt_max}" + + # Backup the current partition table, we're about to modify it + rq sgd_backup $wouldrun sgdisk "--backup=${GPT_BACKUP}" "${DISK}" || +@@ -492,7 +496,7 @@ resize_sgdisk() { + # - set the partition GUID + # - set the partition name + rq sgdisk_mod $wouldrun sgdisk --move-second-header "--delete=${PART}" \ +- "--new=${PART}:${pt_start}:${pt_max}" \ ++ "--new=${PART}:${pt_start}:$((pt_max-1))" \ + "--typecode=${PART}:${code}" \ + "--partition-guid=${PART}:${guid}" \ + "--change-name=${PART}:${name}" "${DISK}" && +diff --git a/test/test-growpart-fsimage-middle b/test/test-growpart-fsimage-middle +new file mode 100755 +index 0000000..4f2dfbf +--- /dev/null ++++ b/test/test-growpart-fsimage-middle +@@ -0,0 +1,74 @@ ++#!/bin/bash ++# ++# Create a disk image where a partition other than the last is grown. ++# brought up under bug 1706751, where we had an off-by-one error ++# when resizing with sgdisk. ++ ++set -e ++ ++TEMP_D="" ++ ++rq() { ++ local out="${TEMP_D}/out" ++ "$@" > "$out" 2>&1 || { echo "FAILED:" "$@"; cat "$out"; return 1; } ++} ++fail() { echo "FAILED:" "$@" 1>&2; exit 1; } ++ ++setup_img() { ++ local img_fp="$1" img="" ++ img=$(basename "$img_fp") ++ sfdisk "${img_fp}" <"$err" > "$out"; then ++ cat "$err" "$out" ++ fail "[resizer=$resizer] growpart failed" ++ fi ++ echo "==== after ====" ++ ( cd "${TEMP_D}" && sfdisk --dump "${img##*/}" ) ++ echo ++ echo "==== after sgdisk ===" ++ ( cd "${TEMP_D}" && sgdisk --print "${img##*/}" ) ++ echo "==== growpart-stderr ===" ++ cat "$err" ++ echo "==== growpart-stdout ====" ++ cat "$out" ++ [ "$(cat $out)" = "$expected" ] || { ++ fail "[resizer=$resizer] output ^^^ did not match expected vvv:${CR}$expected" ++ } ++done ++ ++# vi: ts=4 noexpandtab +-- +2.17.2 + diff --git a/SPECS/cloud-utils-growpart.spec b/SPECS/cloud-utils-growpart.spec index 054609b..62b69fe 100644 --- a/SPECS/cloud-utils-growpart.spec +++ b/SPECS/cloud-utils-growpart.spec @@ -1,11 +1,12 @@ Name: cloud-utils-growpart Version: 0.29 -Release: 2%{?dist} +Release: 2%{?dist}.2 License: GPLv3 Group: System Environment/Base Source0: https://launchpad.net/cloud-utils/trunk/%{version}/+download/cloud-utils-%{version}.tar.gz URL: https://launchpad.net/cloud-utils Source1: LICENSE +Patch1: 0002-growpart-fix-bug-when-resizing-a-middle-partition-wi.patch BuildArch: noarch @@ -18,6 +19,8 @@ Requires: util-linux # systems. #Requires: gdisk + + %description This package provides the growpart script for growing a partition. It is primarily used in cloud images in conjunction with the dracut-modules-growroot @@ -25,6 +28,7 @@ package to grow the root partition on first boot. %prep %setup -q -n cloud-utils-%{version} +%patch1 -p1 %build @@ -45,6 +49,11 @@ cp man/growpart.* $RPM_BUILD_ROOT/%{_mandir}/man1/ %doc %{_mandir}/man1/growpart.* %changelog +* Tue Jul 09 2019 Miroslav Rezanina - 0.29-2.el7_6.2 +- growpart: fix bug when resizing a middle partition with sgdisk [rhbz#1726564] +- Resolves: rhbz#1726564 + (When growing GPT partitions use [start of next - 1] instead of [start of next] as the new end sector.) + * Wed Apr 19 2017 Charalampos Stratakis - 0.29-2 - Import to RHEL 7 Resolves: rhbz#1308711