resize-rootfs-if-needed.sh 745 B

12345678910111213141516171819202122232425262728
  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_xvda="/sys/class/block/xvda"
  11. # if root filesystem use already (almost) the whole dis
  12. non_rootfs_data=$(( 250 * 1024 * 2 ))
  13. rootfs_size=$(df --output=size / | tail -n 1)
  14. # convert to 512-byte blocks
  15. rootfs_size=$(( rootfs_size * 2 ))
  16. if [ "$(cat "$sysfs_xvda/size")" -lt \
  17. $(( non_rootfs_data + rootfs_size )) ]; then
  18. echo "root filesystem already at $rootfs_size blocks" >&2
  19. exit 0
  20. fi
  21. # resize needed, do it
  22. /usr/lib/qubes/resize-rootfs