Created
November 22, 2013 17:04
-
-
Save bfritz/7603332 to your computer and use it in GitHub Desktop.
hard drive burnin
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
| apt-get install smartmontools pv g++ | |
| g++ -o randdata randdata.cpp |
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
| ./hdd_burnin.sh /dev/disk/by-id/ata-WDC_WD20EFRX-68EUZN0_WD-WMC4M12345678 WD_red_nas_WMC4M1231435 2000G |
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
| #!/bin/sh | |
| set -e | |
| DRIVE="$1" | |
| DESC="$2" | |
| HDD_SIZE="$3" | |
| BS=16M | |
| if [ -z "$DRIVE" -o -z "$DESC" -o -z "$HDD_SIZE" ]; then | |
| echo "usage: $0 /dev/sdX drive_description hdd_sizeG" | |
| echo " eg: $0 /dev/sdz samsung_2TB_HD204UI_S2H7J1CB116307 2000G" | |
| exit -1 | |
| fi | |
| if [ ! -b "$DRIVE" ]; then | |
| echo "expected block device" | |
| exit -1 | |
| fi | |
| log() { | |
| echo | |
| echo $1 | |
| } | |
| PV="pv --size=${HDD_SIZE} --buffer-size=16m --interval=15" | |
| log "Capturing initial SMART data..." | |
| smartctl --all "$DRIVE" | tee "`date +%Y%m%d_%H%M`_${DESC}_initial.log" | |
| smartctl --test=short "$DRIVE" | |
| log "Sleeping for 3 minutes while initial short test runs..." | |
| sleep 3m | |
| smartctl --all "$DRIVE" | tee "`date +%Y%m%d_%H%M`_${DESC}_after_short_test.log" | |
| log "Writing zeros..." | |
| $PV --name="write zeros" /dev/zero | dd of="$DRIVE" bs=$BS | |
| smartctl --all "$DRIVE" | tee "`date +%Y%m%d_%H%M`_${DESC}_after_writing_zeros.log" | |
| log "Reading zeros..." | |
| $PV --name="read zeros" "$DRIVE" > /dev/null | |
| smartctl --all "$DRIVE" | tee "`date +%Y%m%d_%H%M`_${DESC}_after_reading_zeros.log" | |
| log "Writing random bits..." | |
| ./randdata -1 | $PV --name="write random" | dd of="$DRIVE" bs=$BS | |
| smartctl --all "$DRIVE" | tee "`date +%Y%m%d_%H%M`_${DESC}_after_writing_random_bits.log" | |
| log "Reading random bits..." | |
| $PV --name="read random" "$DRIVE" > /dev/null | |
| smartctl --all "$DRIVE" | tee "`date +%Y%m%d_%H%M`_${DESC}_after_reading_random_bits.log" | |
| smartctl --test=short "$DRIVE" | |
| log "Sleeping for 3 minutes while final short test runs..." | |
| sleep 3m | |
| smartctl --all "$DRIVE" | tee "`date +%Y%m%d_%H%M`_${DESC}_after_final_short_test.log" |
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
| /* | |
| Copyright 2010 Ken Takusagawa | |
| This program is free software: you can redistribute it and/or modify | |
| it under the terms of the GNU General Public License as published by | |
| the Free Software Foundation, either version 3 of the License, or | |
| (at your option) any later version. | |
| This program is distributed in the hope that it will be useful, | |
| but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| GNU General Public License for more details. | |
| You should have received a copy of the GNU General Public License | |
| along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| */ | |
| #include <cstdio> | |
| #include <iostream> | |
| using std::cerr; | |
| using std::endl; | |
| #include <cstdlib> | |
| //An inlineable C++ implentation of the | |
| //TYPE_3 GNU Libc random number generator | |
| class Randclass{ | |
| static const int DEG=31; | |
| static const int SEP=3; | |
| int randtable[DEG]; | |
| int p; | |
| public: | |
| Randclass() | |
| :p(0) | |
| { | |
| const char* urandom="/dev/urandom"; | |
| FILE*fi=fopen(urandom,"r"); | |
| if(fi==0){ | |
| cerr << "error: cannot open " << urandom << endl; | |
| exit(1); | |
| } | |
| int code=fread(randtable,sizeof(int),DEG,fi); | |
| if(code!=DEG){ | |
| cerr << "error: cannot initialize: "<< code << endl; | |
| exit(1); | |
| } | |
| bool nonzero_found=false; | |
| for(int i=0;i<DEG;++i){ | |
| if(randtable[i]){ | |
| nonzero_found=true; | |
| break; | |
| } | |
| } | |
| if(!nonzero_found){ | |
| cerr << "error: only read zeros in initialization"<< endl; | |
| exit(1); | |
| } | |
| generate_more(); | |
| } | |
| private: | |
| void generate_more(){ | |
| for(int i=0;i<SEP;++i){ | |
| int j=i+(DEG-SEP); | |
| randtable[i]+=randtable[j]; | |
| } | |
| for(int i=SEP;i<DEG;++i){ | |
| //assert(i-SEP>=0); | |
| randtable[i]+=randtable[i-SEP]; | |
| } | |
| } | |
| public: | |
| int unscaled_rand(){ | |
| if (p>=DEG){ | |
| generate_more(); | |
| p=1; | |
| return randtable[0]; | |
| } else { | |
| return (randtable[p++]); | |
| } | |
| } | |
| /* | |
| int rand(){ | |
| int x=unscaled_rand(); | |
| return (x>>1)&0x7fffffff; | |
| } | |
| */ | |
| }; | |
| const int BUFSIZE=17; //17 = megabyte resolution | |
| const int bufsize=1<< BUFSIZE; //14.. | |
| int main(int argc,char**argv){ | |
| long long buf[bufsize]; | |
| if(argc!=2 && argc!=3){ | |
| cerr << argv[0] << " numbytes [shift]" << endl; | |
| cerr << endl << " Emits about numbytes * 2^shift bytes" << endl; | |
| cerr << " rounded down to nearest " << sizeof(buf) << endl; | |
| cerr << " If numbytes < 0, then write infinite" << endl; | |
| return -1; | |
| } | |
| long long count=atoll(argv[1]); | |
| bool infinite = (count < 0); | |
| if(argc==3){ | |
| int shift=atoi(argv[2]); | |
| count<<=shift; | |
| } | |
| count/=bufsize; | |
| count/=sizeof(long long); | |
| cerr << "bufsize=" << (sizeof(long long)*bufsize) << " count=" << count << endl; | |
| Randclass rand; | |
| for(long long ct=0;infinite || (ct<count);++ct){ | |
| for(int i=0;i<bufsize;++i){ | |
| for(int j=0;j<3;++j){ | |
| unsigned int x=rand.unscaled_rand(); | |
| x>>=10; //take 22 high order bits, shift in 0s | |
| //std::cout << x << endl; | |
| //One of the the rare instances that things work | |
| //even though buf[i] is uninitialized. | |
| //22*3=66 > 64 | |
| buf[i]<<=22; | |
| buf[i]|=x; | |
| } | |
| } | |
| int code=fwrite(buf,sizeof(long long),bufsize,stdout); | |
| if(code!=bufsize) { | |
| cerr << "write failed: " << code << endl; | |
| return -1; //disk full | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment