prepare-volatile-img.sh 469 B

12345678910111213141516171819202122232425262728
  1. #!/bin/sh
  2. if [ "`id -u`" != "0" ]; then
  3. exec sudo $0 $*
  4. fi
  5. set -e
  6. if ! echo $PATH | grep -q sbin; then
  7. PATH=$PATH:/sbin:/usr/sbin
  8. fi
  9. FILENAME=$1
  10. ROOT_SIZE=$2
  11. SWAP_SIZE=$[ 1024 ]
  12. if [ -z "$ROOT_SIZE" -o -z "$FILENAME" ]; then
  13. echo "Usage: $0 <filename> <root.img size in MB>"
  14. exit 1
  15. fi
  16. if [ -e "$FILENAME" ]; then
  17. echo "$FILENAME already exists, not overriding"
  18. exit 1
  19. fi
  20. TOTAL_SIZE=$[ $ROOT_SIZE + $SWAP_SIZE + 512 ]
  21. truncate -s ${TOTAL_SIZE}M "$FILENAME"