summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZach Marano <zmarano@google.com>2020-04-28 10:35:24 -0700
committerGitHub <noreply@github.com>2020-04-28 10:35:24 -0700
commit0c97a9e47007694de28ff5b29d021e534a3384d8 (patch)
tree6575e5c9848fa8ff436284122da7fe0de93ff988
parent84bb53e9e5944a2bb5d18ea77608af264c85c4c7 (diff)
downloadgoogle-compute-image-packages-0c97a9e47007694de28ff5b29d021e534a3384d8.tar.gz
Interim fix fo EL7 GPT header move race condition with systemd-fsck. (#891)development
-rw-r--r--packages/gce-disk-expand/packaging/debian/changelog6
-rwxr-xr-xpackages/gce-disk-expand/packaging/setup_deb.sh2
-rwxr-xr-xpackages/gce-disk-expand/packaging/setup_rpm.sh2
-rwxr-xr-xpackages/gce-disk-expand/src/expandfs-lib.sh38
-rwxr-xr-xpackages/gce-disk-expand/src/usr/share/dracut/modules.d/50expand_rootfs/expand_rootfs.sh5
5 files changed, 36 insertions, 17 deletions
diff --git a/packages/gce-disk-expand/packaging/debian/changelog b/packages/gce-disk-expand/packaging/debian/changelog
index 6df9156..1c8e58e 100644
--- a/packages/gce-disk-expand/packaging/debian/changelog
+++ b/packages/gce-disk-expand/packaging/debian/changelog
@@ -1,3 +1,9 @@
+gce-disk-expand (1:20200428.00-g1) stable; urgency=medium
+
+ * Fix potential races in disk expand logic with GPT disks.
+
+ -- Google Cloud Team <gc-team@google.com> Tue, 28 Apr 2020 10:24:07 -0700
+
gce-disk-expand (1:20190708.00-g1) stable; urgency=medium
* Update disk expand to fix bugs with GPT.
diff --git a/packages/gce-disk-expand/packaging/setup_deb.sh b/packages/gce-disk-expand/packaging/setup_deb.sh
index cc81711..1fc0a61 100755
--- a/packages/gce-disk-expand/packaging/setup_deb.sh
+++ b/packages/gce-disk-expand/packaging/setup_deb.sh
@@ -14,7 +14,7 @@
# limitations under the License.
NAME="gce-disk-expand"
-VERSION="20190708.00"
+VERSION="20200428.00"
working_dir=${PWD}
if [[ $(basename "$working_dir") != $NAME ]]; then
diff --git a/packages/gce-disk-expand/packaging/setup_rpm.sh b/packages/gce-disk-expand/packaging/setup_rpm.sh
index 1bc6c38..8a28e52 100755
--- a/packages/gce-disk-expand/packaging/setup_rpm.sh
+++ b/packages/gce-disk-expand/packaging/setup_rpm.sh
@@ -14,7 +14,7 @@
# limitations under the License.
NAME="gce-disk-expand"
-VERSION="20190708.00"
+VERSION="20200428.00"
rpm_working_dir=/tmp/rpmpackage/
working_dir=${PWD}
diff --git a/packages/gce-disk-expand/src/expandfs-lib.sh b/packages/gce-disk-expand/src/expandfs-lib.sh
index 4a02b9f..7a26330 100755
--- a/packages/gce-disk-expand/src/expandfs-lib.sh
+++ b/packages/gce-disk-expand/src/expandfs-lib.sh
@@ -13,6 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+kmsg() {
+ echo "gce-disk-expand: $@" > /dev/kmsg
+}
+
resize_filesystem() {
local disk="$1" fs_type=""
@@ -23,22 +27,22 @@ resize_filesystem() {
case "${fs_type}" in
xfs)
- echo "XFS filesystems must be mounted to be resized, deferring."
+ kmsg "XFS filesystems must be mounted to be resized, deferring."
echo "true" > /tmp/xfs_resize
return 1
;;
ext*)
if ! out=$(e2fsck -pf "$disk"); then
local ret=$?
- echo "Calling e2fsck \"${disk}\" failed: ${out} exit code ${ret}"
+ kmsg "Calling e2fsck \"${disk}\" failed: ${out} exit code ${ret}"
fi
if ! out=$(resize2fs "$disk"); then
- echo "Calling resize2fs \"${disk}\" failed: ${out}"
+ kmsg "Calling resize2fs \"${disk}\" failed: ${out}"
return 1
fi
;;
*)
- echo "Unsupported filesystem type ${fs_type}, unable to expand size."
+ kmsg "Unsupported filesystem type ${fs_type}, unable to expand size."
return 1
;;
esac
@@ -47,14 +51,15 @@ resize_filesystem() {
blkid_get_fstype() (
local root="$1"
+ kmsg "Getting fstype for $root with blkid."
if ! out=$(blkid -o udev "$root"); then
- echo "Detecting fstype by blkid failed: ${out}"
+ kmsg "Detecting fstype by blkid failed: ${out}"
return 1
fi
eval "$out"
if [ -z "$ID_FS_TYPE" ]; then
- echo "No ID_FS_TYPE from blkid."
+ kmsg "No ID_FS_TYPE from blkid."
return 1
fi
echo $ID_FS_TYPE
@@ -64,6 +69,7 @@ sgdisk_get_label() {
local root="$1"
[ -z "$root" ] && return 0
+ kmsg "Getting $root label with sgdisk."
if sgdisk -p "$root" | grep -q "Found invalid GPT and valid MBR"; then
echo "mbr"
else
@@ -78,7 +84,15 @@ sgdisk_fix_gpt() {
local label=$(sgdisk_get_label "$disk")
[ "$label" != "gpt" ] && return
+ # TODO Find a better solution than sleep.
+ # Add sleeps to allow this operation to fully complete. On some systems, other
+ # operations such as systemd-fsck tasks can collide and fail.
+ udevadm settle
+ sleep 1
+ kmsg "Moving GPT header for $disk with sgdisk."
sgdisk --move-second-header "$disk"
+ udevadm settle
+ sleep 1
}
# Returns "disk:partition", supporting multiple block types.
@@ -87,7 +101,7 @@ split_partition() {
[ -z "$root" ] && return 0
if [ -e /sys/block/${root##*/} ]; then
- echo "Root is not a partition, skipping partition resize."
+ kmsg "Root is not a partition, skipping partition resize."
return 1
fi
@@ -104,19 +118,20 @@ split_partition() {
parted_needresize() {
local disk="$1" partnum="$2" disksize="" partend=""
if [ -z "$disk" ] || [ -z "$partnum" ]; then
- echo "invalid args to parted_needresize"
+ kmsg "invalid args to parted_needresize"
return 1
fi
+ kmsg "Check if $disk partition $partnum needs resize with parted."
if ! out=$(parted -sm "$disk" unit b print 2>&1); then
- echo "Failed to get disk details: ${out}"
+ kmsg "Failed to get disk details: ${out}"
return 1
fi
udevadm settle
if ! printf "$out" | sed '$!d' | grep -q "^${partnum}:"; then
- echo "Root partition is not final partition on disk. Not resizing."
+ kmsg "Root partition is not final partition on disk. Not resizing."
return 1
fi
@@ -137,8 +152,9 @@ parted_resizepart() {
local disk="$1" partnum="$2"
[ -z "$disk" -o -z "$partnum" ] && return
+ kmsg "Resizing $disk partition $partnum with parted."
if ! out=$(parted -sm "$disk" -- resizepart $partnum -1 2>&1); then
- echo "Unable to resize ${disk}${partnum}: ${out}"
+ kmsg "Unable to resize ${disk}${partnum}: ${out}"
return 1
fi
udevadm settle
diff --git a/packages/gce-disk-expand/src/usr/share/dracut/modules.d/50expand_rootfs/expand_rootfs.sh b/packages/gce-disk-expand/src/usr/share/dracut/modules.d/50expand_rootfs/expand_rootfs.sh
index f907772..6e1be71 100755
--- a/packages/gce-disk-expand/src/usr/share/dracut/modules.d/50expand_rootfs/expand_rootfs.sh
+++ b/packages/gce-disk-expand/src/usr/share/dracut/modules.d/50expand_rootfs/expand_rootfs.sh
@@ -22,9 +22,6 @@
# logged, rather than causing end of execution. Note that error handling in the
# main() function always calls return 0
-kmsg() {
- echo "expand_rootfs: $@" > /dev/kmsg
-}
main() {
local disk="" partnum="" fs_type="" rootdev=""
@@ -69,7 +66,7 @@ main() {
fi
if ! out=$(resize_filesystem "$rootdev"); then
- kmsg "Failed to resize filesystem: ${out}"
+ kmsg "Not resizing filesystem: ${out}"
return
fi
}