resize-rootfs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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 and xda3 partition
  10. echo ',+' | sfdisk --no-reread --no-tell-kernel -q -N 3 /dev/xvda
  11. # and reload partition table; prefer partprobe over blockdev
  12. # --rereadpt, as it works on mounted partitions
  13. partprobe /dev/xvda
  14. udevadm settle
  15. ;;
  16. ca:*)
  17. echo "Unsupported partition layout, resize it manually" >&2
  18. exit 1
  19. ;;
  20. $dm_major:*)
  21. new_size=$(cat /sys/block/xvda/size)
  22. ro=$(cat /sys/block/xvda/ro)
  23. if [ "$ro" -eq 1 ]; then
  24. new_table="0 $new_size snapshot /dev/xvda /dev/xvdc2 N 16"
  25. else
  26. new_table="0 $new_size linear /dev/xvda 0"
  27. fi
  28. dmsetup load dmroot --table "$new_table"
  29. dmsetup resume dmroot
  30. ;;
  31. *)
  32. echo "Unsupported device type for root volume, resize it manually" >&2
  33. exit 1
  34. ;;
  35. esac
  36. resize2fs /dev/mapper/dmroot