resurtm

Untitled

Nov 12th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.70 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Test if TRIM is working on your SSD. Tested only with EXT4 filesystems
  4. # in Ubuntu 11.10 and Fedora 16. This script is simply an automation of
  5. # the procedures described by Nicolay Doytchev here:
  6. #
  7. # https://sites.google.com/site/lightrush/random-1/checkiftrimonext4isenabledandworking
  8. #
  9. # Author: Dorian Bolivar <[email protected]>
  10. # Date: 20120129
  11. #
  12.  
  13. if [ $# -ne 3 ]; then
  14.     echo
  15.     echo "Usage: $0 <filename> <size> <device>"
  16.     echo
  17.     echo "<filename> is a temporary file for the test"
  18.     echo "<size> is the file size in MB"
  19.     echo "<device> is the device being tested, e.g. /dev/sda"
  20.     echo
  21.     echo "Example: $0 tempfile 5 /dev/sda"
  22.     echo
  23.     echo "This would run the test for /dev/sda creating a"
  24.     echo "temporary file named \"tempfile\" with 5 MB"
  25.     echo
  26.     exit 1
  27. fi
  28.  
  29. FILE="$1"
  30. SIZE=$2
  31. DEVICE="$3"
  32.  
  33. # Create the temporary file
  34. dd if=/dev/urandom of="$FILE" count=1 bs=${SIZE}M oflag=direct
  35. sync
  36.  
  37. # Get the address of the first sector
  38. hdparm --fibmap "$FILE"
  39. SECTOR=`hdparm --fibmap "$FILE" | tail -n1 | awk '{ print $2; }'`
  40.  
  41. # Read the first sector prior to deletion
  42. hdparm --read-sector $SECTOR "$DEVICE"
  43. echo
  44. echo "This is a sector of the file. It should have been successfully read"
  45. echo "and show a bunch of random data."
  46. echo
  47. read -n 1 -p "Press any key to continue..."
  48.  
  49. # Delete the file and re-read the sector
  50. rm -f $FILE
  51. sync
  52. echo
  53. echo "File deleted. Sleeping for 120 seconds before re-reading the sector."
  54. echo "If TRIM is working, you should see all 0s now."
  55. sleep 120
  56. hdparm --read-sector $SECTOR "$DEVICE"
  57. echo
  58. echo "If the sector isn't filled with 0s, something is wrong with your"
  59. echo "configuration. Try googling for \"TRIM SSD Linux\"."
  60. echo
  61.  
  62. exit 0
Advertisement
Add Comment
Please, Sign In to add comment