setup-rwdev.sh 798 B

12345678910111213141516171819202122232425
  1. #!/bin/sh
  2. set -e
  3. if [ -e /dev/xvdb ] ; then
  4. # The private /dev/xvdb device is present.
  5. # check if private.img (xvdb) is empty - all zeros
  6. private_size_512=`blockdev --getsz /dev/xvdb`
  7. if dd if=/dev/zero bs=512 count=$private_size_512 2>/dev/null | diff /dev/xvdb - >/dev/null; then
  8. # the device is empty, create filesystem
  9. echo "Virgin boot of the VM: creating private.img filesystem" >&2
  10. mkfs.ext4 -m 0 -q /dev/xvdb || exit 1
  11. fi
  12. tune2fs -m 0 /dev/xvdb
  13. echo "Virgin boot of the VM: marking private.img as clean" >&2
  14. fsck.ext4 -fp /dev/xvdb
  15. echo "Virgin boot of the VM: enlarging private.img" >&2
  16. if ! content=$(resize2fs /dev/xvdb 2>&1) ; then
  17. echo "resize2fs /dev/xvdb failed:" >&2
  18. echo "$content" >&2
  19. fi
  20. fi