resize-rootfs-if-needed.sh 699 B

1234567891011121314151617181920212223242526
  1. #!/bin/sh
  2. # Possibly resize root device (partition, filesystem), if underlying device was
  3. # enlarged.
  4. set -e
  5. # if underlying root device is read-only, don't do anything
  6. if [ "$(blockdev --getro /dev/xvda)" -eq "1" ]; then
  7. echo "xvda is read-only, not resizing" >&2
  8. exit 0
  9. fi
  10. sysfs_root_dev="/sys/dev/block/$(mountpoint -d /)"
  11. sysfs_xvda="/sys/class/block/xvda"
  12. # if root filesystem use already (almost) the whole dis
  13. non_rootfs_data=$(( 250 * 1024 * 2 ))
  14. if [ "$(cat "$sysfs_xvda/size")" -lt \
  15. $(( non_rootfs_data + $(cat "$sysfs_root_dev/size") )) ]; then
  16. echo "root filesystem already at the right size" >&2
  17. exit 0
  18. fi
  19. # resize needed, do it
  20. /usr/lib/qubes/resize-rootfs