resize-rootfs-if-needed.sh 835 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 is already using (almost) the whole disk
  12. # 203M for BIOS and /boot data, 222 for ext4 filesystem overhead
  13. # See QubesOS/qubes-core-agent-linux#146 for more details
  14. size_margin=$(((222 + 203) * 2 * 1024))
  15. rootfs_size=$(df --block-size=512 --output=size / | tail -n 1 | tr -d ' ')
  16. if [ "$(cat $sysfs_xvda/size)" -lt \
  17. $(( size_margin + 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