Last active
September 28, 2015 22:56
-
-
Save j-griffith/95def7547c553ca68ee4 to your computer and use it in GitHub Desktop.
Trigger internal trim on SF volume
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if [ $# -ne 3 ]; then | |
echo | |
echo "Usage: $0 <filename> <size> <device>" | |
echo | |
echo "<filename> is a temporary file for the test" | |
echo "<size> is the file size in MB NOTE, this needs to be very large on the order of free-capacity - safetyBuffer" | |
echo "<device> is the device being trimmed, e.g. /dev/vda" | |
echo | |
echo "Example: $0 tempfile 5 /dev/vda" | |
echo | |
echo "This would run the test for /dev/vda creating a" | |
echo "temporary file named \"tempfile\" with 5 MB" | |
echo | |
exit 1 | |
fi | |
FILE="$1" | |
SIZE=$2 | |
DEVICE="$3" | |
# Create the temporary file | |
dd if=/dev/zero of="$FILE" count=1 bs=${SIZE}M oflag=direct | |
sync | |
# Get the address of the first sector | |
# This is optional, were were using this just for verification | |
hdparm --fibmap "$FILE" | |
SECTOR=`hdparm --fibmap "$FILE" | tail -n1 | awk '{ print $2; }'` | |
# Delete the file and read the sector | |
rm -f $FILE | |
sync | |
echo | |
echo "File deleted. Sleeping for 120 seconds before re-reading the sector." | |
echo "If TRIM is working, you should see all 0s now." | |
sleep 120 | |
hdparm --read-sector $SECTOR "$DEVICE" | |
echo | |
echo "If the sector isn't filled with 0s, something is wrong with your" | |
echo "configuration. Try googling for \"TRIM SSD Linux\"." | |
echo | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment