setup-rwdev.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/sh
  2. set -e
  3. dev=/dev/xvdb
  4. max_size=1073741824 # check at most 1 GiB
  5. if [ -e "$dev" ] ; then
  6. # The private /dev/xvdb device is present.
  7. # check if private.img (xvdb) is empty - all zeros
  8. private_size=$(( $(blockdev --getsz "$dev") * 512))
  9. if [ $private_size -gt $max_size ]; then
  10. private_size=$max_size
  11. fi
  12. if cmp --bytes $private_size "$dev" /dev/zero >/dev/null && { blkid -p "$dev" >/dev/null; [ $? -eq 2 ]; }; then
  13. # the device is empty, create filesystem
  14. echo "Virgin boot of the VM: creating private.img filesystem on $dev" >&2
  15. if ! content=$(mkfs.ext4 -m 0 -q "$dev" 2>&1) ; then
  16. echo "Virgin boot of the VM: creation of private.img on $dev failed:" >&2
  17. echo "$content" >&2
  18. echo "Virgin boot of the VM: aborting" >&2
  19. exit 1
  20. fi
  21. if ! content=$(tune2fs -m 0 "$dev" 2>&1) ; then
  22. echo "Virgin boot of the VM: marking free space on $dev as usable failed:" >&2
  23. echo "$content" >&2
  24. echo "Virgin boot of the VM: aborting" >&2
  25. exit 1
  26. fi
  27. fi
  28. echo "Private device management: checking $dev" >&2
  29. if content=$(fsck.ext4 -p "$dev" 2>&1) ; then
  30. echo "Private device management: fsck.ext4 of $dev succeeded" >&2
  31. else
  32. echo "Private device management: fsck.ext4 $dev failed:" >&2
  33. echo "$content" >&2
  34. fi
  35. fi