3
0

make-hdc-img.sh 586 B

123456789101112131415161718192021222324252627282930
  1. #!/bin/sh -ex
  2. mountpoint -q /
  3. [ ! -e hdc.img.dir ]
  4. cleanup()
  5. {
  6. trap - EXIT
  7. if mountpoint -q hdc.img.dir; then
  8. umount -d hdc.img.dir
  9. fi
  10. mountpoint -q hdc.img.dir ||
  11. rm -rf hdc.img.dir
  12. exit $@
  13. }
  14. trap 'cleanup $?' EXIT
  15. trap 'cleanup 1' HUP PIPE INT QUIT TERM
  16. size=$(du -ks hdc.dir | sed -rn 's/^([0-9]+).*/\1/p')
  17. [ "$size" -gt 0 ]
  18. rm -f hdc.img
  19. dd if=/dev/zero of=hdc.img count=1 bs=1024 seek=$(($size*2))
  20. mkfs.ext3 -q -F -b 1024 -i 4096 hdc.img
  21. tune2fs -c 0 -i 0 hdc.img
  22. mkdir hdc.img.dir
  23. mount -o loop hdc.img hdc.img.dir
  24. cp -a hdc.dir/* hdc.img.dir/
  25. umount -d hdc.img.dir