summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorLiam Hopkins <liamh@google.com>2019-06-17 16:20:16 -0700
committerZach Marano <zmarano@google.com>2019-06-17 16:20:16 -0700
commit33547c121f09fcde933083bf6f9e7c5c0bd2fae5 (patch)
treea32e02d9381340f6b794eeb115f87cdc9599a24c /packages
parent96e4592dec774793be77f6b6b95cc00e86f8fbbb (diff)
downloadgoogle-compute-image-packages-33547c121f09fcde933083bf6f9e7c5c0bd2fae5.tar.gz
Disk expand: fixes for GPT (#798)
Diffstat (limited to 'packages')
-rw-r--r--packages/gce-disk-expand/packaging/gce-disk-expand.spec2
-rwxr-xr-xpackages/gce-disk-expand/packaging/setup_rpm.sh8
-rwxr-xr-xpackages/gce-disk-expand/src/expandfs-lib.sh62
-rwxr-xr-xpackages/gce-disk-expand/src/usr/share/dracut/modules.d/50expand_rootfs/expand_rootfs.sh33
-rwxr-xr-xpackages/gce-disk-expand/src/usr/share/dracut/modules.d/50expand_rootfs/xfs_growfs.sh32
5 files changed, 47 insertions, 90 deletions
diff --git a/packages/gce-disk-expand/packaging/gce-disk-expand.spec b/packages/gce-disk-expand/packaging/gce-disk-expand.spec
index a1fb6dd..7ed9682 100644
--- a/packages/gce-disk-expand/packaging/gce-disk-expand.spec
+++ b/packages/gce-disk-expand/packaging/gce-disk-expand.spec
@@ -13,7 +13,7 @@
# limitations under the License.
Name: gce-disk-expand
Summary: Google Compute Engine root disk expansion module
-Version: 2.0.0
+Version: %{_version}
Release: 1
License: Apache Software License
Group: System Environment/Base
diff --git a/packages/gce-disk-expand/packaging/setup_rpm.sh b/packages/gce-disk-expand/packaging/setup_rpm.sh
index 106aa6f..ad264e0 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="2.0.0"
+VERSION="2.0.1"
rpm_working_dir=/tmp/rpmpackage/
working_dir=${PWD}
@@ -30,6 +30,8 @@ rm -rf ${rpm_working_dir}
mkdir -p ${rpm_working_dir}/{SOURCES,SPECS}
cp packaging/${NAME}.spec ${rpm_working_dir}/SPECS/
-tar czvf ${rpm_working_dir}/SOURCES/${NAME}_${VERSION}.orig.tar.gz --exclude .git --exclude packaging --transform "s/^\./${NAME}-${VERSION}/" .
+tar czvf ${rpm_working_dir}/SOURCES/${NAME}_${VERSION}.orig.tar.gz \
+ --exclude .git --exclude packaging --transform "s/^\./${NAME}-${VERSION}/" .
-rpmbuild --define "_topdir ${rpm_working_dir}/" -ba ${rpm_working_dir}/SPECS/${NAME}.spec
+rpmbuild --define "_topdir ${rpm_working_dir}/" --define "_version ${VERSION}" \
+ -ba ${rpm_working_dir}/SPECS/${NAME}.spec
diff --git a/packages/gce-disk-expand/src/expandfs-lib.sh b/packages/gce-disk-expand/src/expandfs-lib.sh
index 92e9ed5..4bad47a 100755
--- a/packages/gce-disk-expand/src/expandfs-lib.sh
+++ b/packages/gce-disk-expand/src/expandfs-lib.sh
@@ -67,14 +67,15 @@ parted_fix_gpt() {
local disk="$1"
[ -z "$disk" ] && return
- if parted -sm "$rootdisk" print 2>&1 | grep "fix the GPT"; then
+ 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 "$rootdisk" print Fix
- if parted -sm "$rootdisk" print 2>&1 | grep "fix the GPT"; then
+ 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
@@ -110,13 +111,13 @@ parted_needresize() {
return 1
fi
- if ! echo -e "$out" | sed '$!d' | grep -q "^${partnum}:"; then
+ if ! printf "$out" | sed '$!d' | grep -q "^${partnum}:"; then
echo "Root partition is not final partition on disk. Not resizing."
return 1
fi
- disksize=$(echo -e "$out" | grep "^${disk}" | cut -d: -f2)
- partend=$(echo -e "$out" | sed '$!d' | cut -d: -f4)
+ disksize=$(printf "$out" | grep "^${disk}" | cut -d: -f2)
+ partend=$(printf "$out" | sed '$!d' | cut -d: -f4)
[ -n "$disksize" -a -n "$partend" ] || return 1
disksize=${disksize%%B}
@@ -138,52 +139,3 @@ parted_resizepart() {
fi
udevadm settle
}
-
-# Resizes partition by deleting and recreating with end position.
-# This is a subshell function to safeguard against modifications of IFS.
-parted_resize_mkpart() (
- local disk="$1" partnum="$2"
- [ -z "$disk" -o -z "$partnum" ] && return
-
- local partnum="" partbegin="" partend="" partsize=""
- local fstype="" partname="" flags="" temp=""
-
- # $ parted -sm /dev/sda unit b print
- # BYT;
- # /dev/sda:18253611008B:scsi:512:4096:msdos:Google PersistentDisk:;
- # 1:2097152B:18252611583B:18250514432B:ext4::boot;
- #
- if ! out=$(parted -sm "$disk" unit b print 2>&1); then
- echo "Unable to get partition info."
- return 1
- fi
-
- temp=/tmp/my_temp
- echo -e "$out" | sed '$!d' > $temp
- IFS=: read partnum partbegin partend partsize fstype partname flags < $temp
- rm $temp
-
- if ! out=$(parted -sm "$disk" rm $partnum 2>&1); then
- echo "Failed to delete partition: ${out}"
- return 1
- fi
-
- if ! out=$(parted -sm "$disk" -- mkpart pri $fstype $partbegin -1 2>&1); then
- echo "Failed to recreate original partition: ${out}"
- echo "Trying to create with original parameters."
- if ! out=$(parted -sm "$disk" mkpart pri $fstype $partbegin $partend 2>&1); then
- echo "Failed to recreate original partition: ${out}"
- return 1
- fi
- fi
-
- flags=${flags%%;}
- IFS=,
- for flag in $flags; do
- if ! out=$(parted -sm "$disk" set $partnum $flag on 2>&1); then
- echo "Failed to set \"$flag\" on ${disk} part ${partnum}: ${out}"
- return 1
- fi
- done
- 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 cc831b3..3d12b35 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
@@ -15,17 +15,22 @@
# Contains dracut-specific logic for detecting disk, then calls appropriate
# library functions.
+
+kmsg() {
+ echo "expand_rootfs: $@" > /dev/kmsg
+}
+
main() {
local disk="" partnum="" fs_type="" rootdev=""
# Remove 'block:' prefix and find the root device.
if ! rootdev=$(readlink -f "${root#block:}") || [ -z "${rootdev}" ]; then
- echo "Unable to find root device."
+ kmsg "Unable to find root device."
return
fi
if ! out=$(split_partition "$rootdev"); then
- echo "Failed to detect disk and partition info: ${out}"
+ kmsg "Failed to detect disk and partition info: ${out}"
return
fi
@@ -33,32 +38,28 @@ main() {
partnum=${out#*:}
if ! parted_needresize "$disk" "$partnum"; then
- echo "Disk does not need resizing."
+ kmsg "Disk ${rootdev} doesn't need resizing"
return
fi
- echo "Resizing disk ${rootdev}"
-
- if ! out=$(parted_fix_gpt); then
- echo "$out"
+ if ! parted --help | grep -q 'resizepart'; then
+ kmsg "No 'resizepart' command in this parted"
return
fi
- if parted --help | grep -q 'resizepart'; then
+ kmsg "Resizing disk ${rootdev}"
+
+ if ! out=$(parted_resizepart "$disk" "$partnum"); then
+ # Try fixing the GPT and try resizing again.
+ parted_fix_gpt "$disk"
if ! out=$(parted_resizepart "$disk" "$partnum"); then
- echo "Failed to resize partition: ${out}"
- return
- fi
- else
- echo "No 'resizepart' command in this parted, trying rm&&mkpart."
- if ! out=$(parted_resize_mkpart "$disk" "$partnum"); then
- echo "Failed to resize partition: ${out}"
+ kmsg "Failed to resize partition: ${out}"
return
fi
fi
if ! out=$(resize_filesystem "$rootdev"); then
- echo "Failed to resize filesystem: ${out}"
+ kmsg "Failed to resize filesystem: ${out}"
return
fi
}
diff --git a/packages/gce-disk-expand/src/usr/share/dracut/modules.d/50expand_rootfs/xfs_growfs.sh b/packages/gce-disk-expand/src/usr/share/dracut/modules.d/50expand_rootfs/xfs_growfs.sh
index 0e77185..f4013f6 100755
--- a/packages/gce-disk-expand/src/usr/share/dracut/modules.d/50expand_rootfs/xfs_growfs.sh
+++ b/packages/gce-disk-expand/src/usr/share/dracut/modules.d/50expand_rootfs/xfs_growfs.sh
@@ -13,29 +13,31 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+kmsg() {
+ echo "xfs_growfs: $@" >/dev/kmsg
+}
+
main() {
if [ ! -e /tmp/xfs_resize ]; then
return
fi
- if ! command -v xfs_growfs >/dev/null; then
- echo "XFS resize requested, but xfs_growfs not installed."
+ if ! type xfs_growfs >/dev/null; then
+ kmsg "XFS resize requested, but xfs_growfs not installed."
+ return
+ fi
+
+ kmsg "Mounting filesystem rw for resize."
+ if ! $(mount -o rw,remount /sysroot); then
+ kmsg "Remount failed."
return
fi
- if xfs_growfs -d -n /sysroot; then
- echo "Mounting filesystem rw."
- if ! $(mount -o rw,remount /sysroot); then
- echo "Remount failed."
- return
- fi
- echo "Resizing XFS filesystem"
- if ! out=$(xfs_growfs -d /sysroot); then
- echo "Failed to resize: ${out}"
- mount -o ro,remount /sysroot
- return
- fi
- mount -o ro,remount /sysroot
+
+ kmsg "Resizing XFS filesystem"
+ if ! out=$(xfs_growfs -d /sysroot); then
+ kmsg "Failed to resize: ${out}"
fi
+ mount -o ro,remount /sysroot
}
main