create_block.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env bash
  2. # Copyright 2015 The Kubernetes Authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # Create block.tar.gz with a small ext2 filesystem.
  16. # It must be run as root (to mount with '-o loop')!
  17. # Exit on the first error.
  18. set -e
  19. MNTDIR="$(mktemp -d)"
  20. cleanup()
  21. {
  22. # Make sure we return the right exit code
  23. RET=$?
  24. # Silently remove everything and ignore errors
  25. set +e
  26. /bin/umount "$MNTDIR" 2>/dev/null
  27. /bin/rmdir "$MNTDIR" 2>/dev/null
  28. /bin/rm block 2>/dev/null
  29. exit $RET
  30. }
  31. trap cleanup TERM EXIT
  32. # Create 120MB device with ext2
  33. # (volume_io tests need at least 100MB)
  34. dd if=/dev/zero of=block seek=120 count=1 bs=1M
  35. mkfs.ext2 block
  36. # Add index.html to it
  37. mount -o loop block "$MNTDIR"
  38. echo "Hello from RBD" > "$MNTDIR/index.html"
  39. umount "$MNTDIR"
  40. rm block.tar.gz 2>/dev/null || :
  41. tar cfz block.tar.gz block