dehydrate-fs is a family of tools for separating out files from disk images for the efficient storage of both.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

26 linhas
877B

  1. #!/usr/bin/env bash
  2. set -eo pipefail
  3. image="$1"; [ -z "$1" ] && { echo "No image file specified!" >&2; exit 1; }
  4. mfile="$2"; [ -z "$2" ] && { echo "No mapfile specified!" >&2; exit 1; }
  5. [ -z "$3" -a -t 1 ] && { echo "The output of this script is unsafe for raw display." >&2
  6. exit 1; } \
  7. || ofile=${3:-/dev/stdout}
  8. BLOCKSIZE=`sed -nE 's/^#BLOCKSIZE=([0-9]+)$/\1/p' "$mfile"`
  9. [ -z "$BLOCKSIZE" ] && { echo "Mapfile does not specify blocksize!" >&2; exit 1; }
  10. shopt -s expand_aliases
  11. alias dd="dd bs=$BLOCKSIZE status=none"
  12. {
  13. i=0
  14. while read -r -d$'\n' _ block lengt _; do
  15. #Leaves the remainder block for convenience
  16. dd if="$image" skip=$i count=$((block-i))
  17. dd if=/dev/zero count=$((lengt-1))
  18. i=$((block+lengt-1))
  19. done < <(grep -v ^\# "$mfile" | sed -En '/[a-f0-9]{64}/!p' | sort -unk2)
  20. dd if="$image" skip=$i
  21. } > "$ofile"