summaryrefslogtreecommitdiff
path: root/packages/gce-disk-expand/src/usr/share/dracut/modules.d/50expand_rootfs/expand_rootfs.sh
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gce-disk-expand/src/usr/share/dracut/modules.d/50expand_rootfs/expand_rootfs.sh')
-rwxr-xr-xpackages/gce-disk-expand/src/usr/share/dracut/modules.d/50expand_rootfs/expand_rootfs.sh62
1 files changed, 36 insertions, 26 deletions
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 6e1be71..41cc6da 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,8 @@
# logged, rather than causing end of execution. Note that error handling in the
# main() function always calls return 0
-
main() {
- local disk="" partnum="" fs_type="" rootdev=""
+ local rootdev="" disk="" partnum=""
# Remove 'block:' prefix and find the root device.
if ! rootdev=$(readlink -f "${root#block:}") || [ -z "${rootdev}" ]; then
@@ -40,36 +39,47 @@ main() {
disk=${out%:*}
partnum=${out#*:}
- if ! parted_needresize "$disk" "$partnum"; then
- kmsg "Disk ${rootdev} doesn't need resizing"
- return
- fi
+ (
+ # If we can't obtain an exclusive lock on FD 9 (which is associated in this
+ # subshell with the root device we're modifying), then exit. This is needed
+ # to prevent systemd from issuing udev re-enumerations and fsck calls before
+ # we're done. See https://systemd.io/BLOCK_DEVICE_LOCKING/
- if ! parted --help | grep -q 'resizepart'; then
- kmsg "No 'resizepart' command in this parted"
- return
- fi
+ if ! flock -n 9; then
+ kmsg "couldn't obtain lock on ${rootdev}"
+ exit
+ fi
- kmsg "Resizing disk ${rootdev}"
- # Reset the counter for failed job starts to prevent overrunning the default
- # start burst limits for systemd-fsck-root.service.
- systemctl reset-failed
+ if ! parted_needresize "$disk" "$partnum"; then
+ kmsg "Disk ${rootdev} doesn't need resizing"
+ exit
+ fi
- # First, move the secondary GPT to the end.
- if ! out=$(sgdisk_fix_gpt "$disk"); then
- kmsg "Failed to fix GPT: ${out}"
- fi
+ if ! parted --help | grep -q 'resizepart'; then
+ kmsg "No 'resizepart' command in this parted"
+ exit
+ fi
- if ! out=$(parted_resizepart "$disk" "$partnum"); then
- kmsg "Failed to resize partition: ${out}"
- return
- fi
+ kmsg "Resizing disk ${rootdev}"
- if ! out=$(resize_filesystem "$rootdev"); then
- kmsg "Not resizing filesystem: ${out}"
- return
- fi
+ # First, move the secondary GPT to the end.
+ if ! out=$(sgdisk_fix_gpt "$disk"); then
+ kmsg "Failed to fix GPT: ${out}"
+ fi
+
+ if ! out=$(parted_resizepart "$disk" "$partnum"); then
+ kmsg "Failed to resize partition: ${out}"
+ exit
+ fi
+
+ if ! out=$(resize_filesystem "$rootdev"); then
+ kmsg "Failed to resize filesystem: ${out}"
+ exit
+ fi
+ ) 9<$rootdev
}
. /lib/expandfs-lib.sh
+udevadm settle
main
+udevadm settle