resize-rootfs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 -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. ;;
  15. ca:*)
  16. echo "Unsupported partition layout, resize it manually" >&2
  17. exit 1
  18. ;;
  19. $dm_major:*)
  20. new_size=$(cat /sys/block/xvda/size)
  21. ro=$(cat /sys/block/xvda/ro)
  22. if [ "$ro" -eq 1 ]; then
  23. new_table="0 $new_size snapshot /dev/xvda /dev/xvdc2 N 16"
  24. else
  25. new_table="0 $new_size linear /dev/xvda 0"
  26. fi
  27. dmsetup load dmroot --table "$new_table"
  28. dmsetup resume dmroot
  29. ;;
  30. *)
  31. echo "Unsupported device type for root volume, resize it manually" >&2
  32. exit 1
  33. ;;
  34. esac
  35. resize2fs /dev/mapper/dmroot