mkdisk.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/bash
  2. DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  3. OUT=$1
  4. IN=$2
  5. OUTDIR=`dirname $1`
  6. # Calculate required space
  7. SPACE_REQ=$(du -sb "$DIR/../fatbase" | cut -f 1)
  8. let "SIZE = ($SPACE_REQ / 1000000)"
  9. # Minimum size
  10. if [ $SIZE -lt 24 ]; then
  11. SIZE=24
  12. fi
  13. # Use more sectors-per-cluster for larger disk sizes
  14. if [ $SIZE -gt 128 ]; then
  15. SPC=4
  16. else
  17. SPC=1
  18. fi
  19. # Create empty FAT image
  20. rm -f $OUT
  21. mkdir -p cdrom
  22. fallocate -l ${SIZE}M $OUT || dd if=/dev/zero bs=1M count=${SIZE} of=$OUT
  23. mkfs.fat -s $SPC -S 2048 $OUT
  24. #echo "Turning $IN into $OUT"
  25. # Add files
  26. for i in $(find $IN)
  27. do
  28. if [[ $i == $IN ]]; then
  29. continue
  30. fi
  31. OUT_FILE=`echo $i | sed s"/^$IN/$OUTDIR/"`
  32. IN_FILE=`echo $i | sed s"/^$IN//"`
  33. #echo $IN_FILE $OUT_FILE
  34. if [ -d "$i" ]; then
  35. mmd -i $OUT $IN_FILE
  36. mkdir -p $OUT_FILE
  37. else
  38. mcopy -i $OUT $i '::'$IN_FILE
  39. touch $OUT_FILE
  40. fi
  41. done
  42. rm -f cdrom/efi/boot/bootia32.efi # Otherwise virtualbox may erroneously try to load from this
  43. rm -f cdrom/efi/boot/bootx64.efi # Same