Advertisement
Guest User

Check Trim script

a guest
Feb 1st, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.26 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. if [ $# -ne 3 ]; then
  4. echo
  5. echo "Usage: $0 "
  6. echo
  7. echo " is a temporary file for the test"
  8. echo " is the file size in MB"
  9. echo " is the device being tested, e.g. /dev/sda"
  10. echo
  11. echo "Example: $0 tempfile 5 /dev/sda"
  12. echo
  13. echo "This would run the test for /dev/sda creating a"
  14. echo "temporary file named \"tempfile\" with 5 MB"
  15. echo
  16. exit 1
  17. fi
  18. FILE="$1"
  19. SIZE=$2
  20. DEVICE="$3"
  21. # Create the temporary file
  22. dd if=/dev/urandom of="$FILE" count=1 bs=${SIZE}M oflag=direct
  23. sync
  24. # Get the address of the first sector
  25. hdparm --fibmap "$FILE"
  26. SECTOR=`hdparm --fibmap "$FILE" | tail -n1 | awk '{ print $2; }'`
  27. # Read the first sector prior to deletion
  28. hdparm --read-sector $SECTOR "$DEVICE"
  29. echo
  30. echo "This is a sector of the file. It should have been successfully read"
  31. echo "and show a bunch of random data."
  32. echo
  33. read -n 1 -p "Press any key to continue..."
  34. # Delete the file and re-read the sector
  35. rm -f $FILE
  36. sync
  37. echo
  38. echo "File deleted. Sleeping for 120 seconds before re-reading the sector."
  39. echo "If TRIM is working, you should see all 0s now."
  40. sleep 5
  41. hdparm --read-sector $SECTOR "$DEVICE"
  42. echo
  43. echo "If the sector isn't filled with 0s, something is wrong with your"
  44. echo "configuration. Try googling for \"TRIM SSD Linux\"."
  45. echo
  46. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement