clone damaged hard drive

This is example how to backup hard drive with smartctl errors to new one.

This is part of log smartctl -a result

7 Seek_Error_Rate 0x000f 084 060 030 Pre-fail Always - 300021937
187 Reported_Uncorrect 0x0032 024 024 000 Old_age Always - 76
195 Hardware_ECC_Recovered 0x001a 093 063 000 Old_age Always - 161432094

The damaged disk is 160gb and I cloned it on new 500gb

First I tried with dd tool , but the operation was not successfull.

pv -tpreb /dev/sda | dd of=/dev/sdb
pv: (stdin): read failed: Input/output error ] 10% ETA 2:48:10
15.8GB 0:20:21 [13.3MB/s] [=============> ] 10%
33221136+0 records in
33221136+0 records out
17009221632 bytes (17 GB) copied, 1223.27 s, 13.9 MB/s

This is log from dmesg

[ 1457.622297] ata2.00: exception Emask 0x0 SAct 0x0 SErr 0x0 action 0x0
[ 1457.622715] ata2.00: BMDMA stat 0x65
[ 1457.623023] ata2.00: failed command: READ DMA
[ 1457.623346] ata2.00: cmd c8/00:03:15:ea:fa/00:00:00:00:00/e1 tag 0 dma 1536 in
[ 1457.623347] res 51/40:00:15:ea:fa/00:00:00:00:00/e1 Emask 0x9 (media error)
[ 1457.624072] ata2.00: status: { DRDY ERR }
[ 1457.624521] ata2.00: error: { UNC }
[ 1457.756509] ata2.00: configured for UDMA/133
[ 1457.773080] ata2.01: configured for UDMA/133
[ 1457.773471] ata2: EH complete
[ 1461.137528] ata2.00: exception Emask 0x0 SAct 0x0 SErr 0x0 action 0x0
[ 1461.137949] ata2.00: BMDMA stat 0x65
[ 1461.138260] ata2.00: failed command: READ DMA
[ 1461.138584] ata2.00: cmd c8/00:03:15:ea:fa/00:00:00:00:00/e1 tag 0 dma 1536 in
[ 1461.138585] res 51/40:00:15:ea:fa/00:00:00:00:00/e1 Emask 0x9 (media error)
[ 1461.139315] ata2.00: status: { DRDY ERR }
[ 1461.139758] ata2.00: error: { UNC }
[ 1461.255080] ata2.00: configured for UDMA/133
[ 1461.268734] ata2.01: configured for UDMA/133
[ 1461.269125] sd 1:0:0:0: [sda] Unhandled sense code
[ 1461.269426] sd 1:0:0:0: [sda] Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
[ 1461.269742] sd 1:0:0:0: [sda] Sense Key : Medium Error [current] [descriptor]
[ 1461.270069] Descriptor sense data with sense descriptors (in hex):
[ 1461.270445] 72 03 11 04 00 00 00 0c 00 0a 80 00 00 00 00 00
[ 1461.270914] 01 fa ea 15
[ 1461.271379] sd 1:0:0:0: [sda] Add. Sense: Unrecovered read error - auto reallocate failed
[ 1461.271839] sd 1:0:0:0: [sda] CDB: Read(10): 28 00 01 fa ea 15 00 00 03 00
[ 1461.272317] end_request: I/O error, dev sda, sector 33221141
[ 1461.272779] Buffer I/O error on device sda, logical block 33221141
[ 1461.273240] Buffer I/O error on device sda, logical block 33221142
[ 1461.273666] Buffer I/O error on device sda, logical block 33221143
[ 1461.274116] ata2: EH complete

You see read dma errors…

I saved my hdd using ddrescue tool

ddrescue /dev/sda /dev/sdb -b 128MB

Press Ctrl-C to interrupt
rescued: 159982 MB, errsize: 58036 kB, current rate: 0 B/s
ipos: 17009 MB, errors: 2, average rate: 26632 kB/s
opos: 17009 MB, time from last successful read: 21 s
Finished

/dev/sda – damaged
/dev/sdb – new hdd
I cloned /dev/sda to /dev/sdb

Let me show you another damaged hard drive

smartctl -a /dev/sdb

SMART Attributes Data Structure revision number: 10
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE
1 Raw_Read_Error_Rate 0x000f 117 097 006 Pre-fail Always - 134254745
3 Spin_Up_Time 0x0003 095 095 000 Pre-fail Always - 0
4 Start_Stop_Count 0x0032 100 100 020 Old_age Always - 268
5 Reallocated_Sector_Ct 0x0033 100 100 036 Pre-fail Always - 0
7 Seek_Error_Rate 0x000f 079 060 030 Pre-fail Always - 26353902756
9 Power_On_Hours 0x0032 065 065 000 Old_age Always - 31247
10 Spin_Retry_Count 0x0013 100 100 097 Pre-fail Always - 0
12 Power_Cycle_Count 0x0032 100 100 020 Old_age Always - 221
187 Reported_Uncorrect 0x0032 100 100 000 Old_age Always - 0
189 High_Fly_Writes 0x003a 100 100 000 Old_age Always - 0
190 Airflow_Temperature_Cel 0x0022 073 052 045 Old_age Always - 27 (Lifetime Min/Max 27/27)
194 Temperature_Celsius 0x0022 027 048 000 Old_age Always - 27 (0 17 0 0)
195 Hardware_ECC_Recovered 0x001a 107 058 000 Old_age Always - 205043611
197 Current_Pending_Sector 0x0012 100 100 000 Old_age Always - 0
198 Offline_Uncorrectable 0x0010 100 100 000 Old_age Offline - 0
199 UDMA_CRC_Error_Count 0x003e 200 200 000 Old_age Always - 0
200 Multi_Zone_Error_Rate 0x0000 100 253 000 Old_age Offline - 0
202 Data_Address_Mark_Errs 0x0032 100 253 000 Old_age Always - 0

These are critical

Raw_Read_Error_Rate
Reallocated_Sector_Ct
Seek_Error_Rate
Reallocated_Event_Count
UDMA_CRC_Error_Count
Multi_Zone_Error_Rate

(0x0C:0x0016): Remote Access to 3DM2 has been disabled. Please connect using the local machine by entering ‘localhost’ in the URL bar

(0x0C:0x0016): Remote Access to 3DM2 has been disabled. Please connect using the local machine by entering ‘localhost’ in the URL bar

vim /etc/3dm2/3dm2.conf

RemoteAccess=1

/etc/init.d/3dm2 stop
/etc/init.d/3dm2 start

install smartmontools to monitor your hard drives

aptitude install smartmontools

vim /etc/default/smartmontools

start_smartd=yes

vim /etc/smartd.conf

DEVICESCAN -d removable -n standby -m [email protected] -M exec /usr/share/smartmontools/smartd-runner
/dev/sda -S on -o on -a -I 194 -m [email protected]

If we have more than one hard drive
/dev/sda -S on -o on -a -I 194 -m [email protected]

Now restart the service
/etc/init.d/smartmontools restart

Now configure exim to send email notifications

dpkg-reconfigure exim4-config

1) Split configuration into small files? No
2) General type of mail configuration: internet site; mail is sent and received directly using SMTP
3) System mail name: hostname.domain.name
4) IP-addresses to listen on for incoming SMTP connections: 127.0.0.1
5) Other destinations for which mail is accepted: hostname.domain.name
6) Domains to relay mail for: !! empty !!
7) Machines to relay mail for: !! empty !!
8) Keep number of DNS-queries minimal (Dial-on-Demand)?: No
9) Delivery method for local mail: mbox format in /var/mail/

mod_evasive prevent DOS attacks on apache webserver

aptitude search mod-evasive
p libapache2-mod-evasive – evasive module to minimize HTTP DoS or brute force attacks

aptitude install libapache2-mod-evasive

mkdir -p /var/log/apache2/evasive

chown -R www-data:root /var/log/apache2/evasive/

vim /etc/apache2/mods-available/mod-evasive.load

LoadModule evasive20_module /usr/lib/apache2/modules/mod_evasive20.so

DOSHashTableSize 3097
DOSPageCount 5
DOSSiteCount 100
DOSPageInterval 2
DOSSiteInterval 2
DOSBlockingPeriod 600
DOSLogDir “/var/log/apache2/evasive”
DOSEmailNotify [email protected]

apachectl configtest
Syntax OK

apachectl restart