summaryrefslogtreecommitdiff
path: root/packages/gce-disk-expand/src/expandfs-lib.sh
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gce-disk-expand/src/expandfs-lib.sh')
-rwxr-xr-xpackages/gce-disk-expand/src/expandfs-lib.sh42
1 files changed, 22 insertions, 20 deletions
diff --git a/packages/gce-disk-expand/src/expandfs-lib.sh b/packages/gce-disk-expand/src/expandfs-lib.sh
index 69f67ed..4a02b9f 100755
--- a/packages/gce-disk-expand/src/expandfs-lib.sh
+++ b/packages/gce-disk-expand/src/expandfs-lib.sh
@@ -29,8 +29,8 @@ resize_filesystem() {
;;
ext*)
if ! out=$(e2fsck -pf "$disk"); then
- echo "Calling e2fsck \"${disk}\" failed: ${out}"
- return 1
+ local ret=$?
+ echo "Calling e2fsck \"${disk}\" failed: ${out} exit code ${ret}"
fi
if ! out=$(resize2fs "$disk"); then
echo "Calling resize2fs \"${disk}\" failed: ${out}"
@@ -60,32 +60,31 @@ blkid_get_fstype() (
echo $ID_FS_TYPE
)
+sgdisk_get_label() {
+ local root="$1"
+ [ -z "$root" ] && return 0
+
+ if sgdisk -p "$root" | grep -q "Found invalid GPT and valid MBR"; then
+ echo "mbr"
+ else
+ echo "gpt"
+ fi
+}
-# Checks for and corrects the end-of-disk GPT backup block in case of expanded
-# disk.
-parted_fix_gpt() {
+sgdisk_fix_gpt() {
local disk="$1"
[ -z "$disk" ] && return
- if parted -sm "$disk" print 2>&1 | grep -q "fix the GPT"; then
- # Running parted prompts the user to fix this condition, but only does so in
- # the interactive exception handler. In order to pass input we must use the
- # hidden triple-dash flag and pass both print and Fix arguments. `print`
- # alone will not perform the fix, but `Fix` alone will fail the argument
- # parser.
- parted -m ---pretend-input-tty "$disk" print Fix >/dev/null 2>&1 </dev/null
- parted -m ---pretend-input-tty "$disk" print Fix >/dev/null 2>&1 </dev/null
- if parted -sm "$disk" print 2>&1 | grep -q "fix the GPT"; then
- echo "Failed to fix the GPT."
- return 1
- fi
- fi
+ local label=$(sgdisk_get_label "$disk")
+ [ "$label" != "gpt" ] && return
+
+ sgdisk --move-second-header "$disk"
}
# Returns "disk:partition", supporting multiple block types.
split_partition() {
local root="$1" disk="" partnum=""
- [ -z "$root" ] && return
+ [ -z "$root" ] && return 0
if [ -e /sys/block/${root##*/} ]; then
echo "Root is not a partition, skipping partition resize."
@@ -104,7 +103,10 @@ split_partition() {
# Checks if partition needs resizing.
parted_needresize() {
local disk="$1" partnum="$2" disksize="" partend=""
- [ -z "$root" ] && return
+ if [ -z "$disk" ] || [ -z "$partnum" ]; then
+ echo "invalid args to parted_needresize"
+ return 1
+ fi
if ! out=$(parted -sm "$disk" unit b print 2>&1); then
echo "Failed to get disk details: ${out}"