resize-rootfs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/sh
  2. set -e
  3. dm_major=$(printf %x "$(grep device-mapper /proc/devices | cut -f 1 -d ' ')")
  4. case "$(stat -Lc %t:%T /dev/mapper/dmroot)" in
  5. ca:0)
  6. # nothing needed, xvda used directly
  7. ;;
  8. ca:3)
  9. # resize partition table itself
  10. # use undocumented ---pretend-input-tty (yes, three '-') to
  11. # force unattended operation, otherwise it aborts on first
  12. # prompt, even with '-s' option
  13. echo fix | parted ---pretend-input-tty /dev/xvda print >/dev/null
  14. # then resize 3rd partition, even though it is mounted
  15. echo yes 100% | parted ---pretend-input-tty /dev/xvda resizepart 3
  16. # and reload partition table; prefer partprobe over blockdev
  17. # --rereadpt, as it works on mounted partitions
  18. partprobe /dev/xvda
  19. ;;
  20. ca:*)
  21. echo "Unsupported partition layout, resize it manually" >&2
  22. exit 1
  23. ;;
  24. $dm_major:*)
  25. new_size=$(cat /sys/block/xvda/size)
  26. ro=$(cat /sys/block/xvda/ro)
  27. if [ "$ro" -eq 1 ]; then
  28. new_table="0 $new_size snapshot /dev/xvda /dev/xvdc2 N 16"
  29. else
  30. new_table="0 $new_size linear /dev/xvda 0"
  31. fi
  32. dmsetup load dmroot --table "$new_table"
  33. dmsetup resume dmroot
  34. ;;
  35. *)
  36. echo "Unsupported device type for root volume, resize it manually" >&2
  37. exit 1
  38. ;;
  39. esac
  40. resize2fs /dev/mapper/dmroot