-
Notifications
You must be signed in to change notification settings - Fork 0
/
bs_optimizer.sh
49 lines (44 loc) · 1 KB
/
bs_optimizer.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/sh
# You should run this as root.
######## START EDITING #######
TIME=5 # time to wait
TEMPNAME="temp_BS"
######## STOP EDITING #######
if [ $# -ne 2 ]; then
echo "Syntax: sudo sh script.sh [device] [dest path]"
exit 1
fi
#set -e
SIZE=0
TEMP_SIZE=0
BEST_BS=0
OS_TYPE=$(uname)
for BLOCK_SIZE in 512 1024 2048 4096 8192 16384 32768 67108864 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 134217728
do
OUT_FILE=$2"_"$TEMPNAME"_"$BLOCK_SIZE
dd if=$1 of=$OUT_FILE bs=$BLOCK_SIZE& pid=$!
echo "Checking $BLOCK_SIZE bytes..."
sleep $TIME
kill -9 $pid
wait $pid
case "$OS_TYPE" in
Darwin|*BSD)
TEMP_SIZE=$(stat -f "%z" $OUT_FILE)
;;
Linux)
TEMP_SIZE=$(stat -c "%s" $OUT_FILE)
;;
*)
echo "Your OS is not osX, *BSD, or Linux."
exit 1
;;
esac
if [ $TEMP_SIZE -gt $SIZE ]; then
BEST_BS=$BLOCK_SIZE
SIZE=$TEMP_SIZE
fi
rm $OUT_FILE
done
echo "The best blocksize is $BEST_BS. Running:"
echo "dd if=$1 of=$2 bs=$BEST_BS"
dd if=$1 of=$2 bs=$BEST_BS