setup-rwdev.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/sh
  2. set -e
  3. dev=/dev/xvdb
  4. if [ -e "$dev" ] ; then
  5. # The private /dev/xvdb device is present.
  6. # check if private.img (xvdb) is empty - all zeros
  7. private_size_512=`blockdev --getsz "$dev"`
  8. if dd if=/dev/zero bs=512 count="$private_size_512" 2>/dev/null | diff "$dev" - >/dev/null; then
  9. # the device is empty, create filesystem
  10. echo "Virgin boot of the VM: creating private.img filesystem on $dev" >&2
  11. if ! content=$(mkfs.ext4 -m 0 -q "$dev" 2>&1) ; then
  12. echo "Virgin boot of the VM: creation of private.img on $dev failed:" >&2
  13. echo "$content" >&2
  14. echo "Virgin boot of the VM: aborting" >&2
  15. exit 1
  16. fi
  17. if ! content=$(tune2fs -m 0 "$dev" 2>&1) ; then
  18. echo "Virgin boot of the VM: marking free space on $dev as usable failed:" >&2
  19. echo "$content" >&2
  20. echo "Virgin boot of the VM: aborting" >&2
  21. exit 1
  22. fi
  23. fi
  24. echo "Private device management: checking $dev" >&2
  25. if content=$(fsck.ext4 -p "$dev" 2>&1) ; then
  26. echo "Private device management: fsck.ext4 of $dev succeeded" >&2
  27. else
  28. echo "Private device management: fsck.ext4 $dev failed:" >&2
  29. echo "$content" >&2
  30. fi
  31. fi