fix-bad-sectors.sh 629 B

12345678910111213141516171819202122
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. # The script below finds bad sectors on ALL discs,
  4. # puts them into a text file,
  5. # then test if text file size is different than zero,
  6. # so e2fsck will mark bad sectors
  7. # (these sectors will not be used by operating system)
  8. minsize=0
  9. target="/tmp/bad-blocks.txt"
  10. for disc in `fdisk -l | grep '^/' | awk '{ print $1 }'`; do
  11. badblocks -v $disc > "$target"
  12. tam=$(du -k "$target" | cut -f 1)
  13. if [ $tam -eq $minsize ]; then
  14. echo "no badblocks on $disc"
  15. else
  16. echo "badblock(s) found(s) on $disc"
  17. e2fsck -l "$target" "$disc"
  18. fi
  19. done