Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
etersoft-admin-essentials
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
etersoft-admin-essentials
Commits
de364f1a
Commit
de364f1a
authored
Sep 14, 2013
by
Vitaly Lipatov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add hdd utils
parent
9b010a12
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
119 additions
and
0 deletions
+119
-0
fix_disk.sh
hdd/fix_disk.sh
+77
-0
ttt.sh
hdd/ttt.sh
+42
-0
No files found.
hdd/fix_disk.sh
0 → 100644
View file @
de364f1a
#!/bin/sh
# TODO: use ddrescue log
# ddrescue -n in /dev/null logfile
if
[
-z
"
$1
"
]
||
[
"
$1
"
=
"-h"
]
||
[
"
$1
"
=
"--help"
]
;
then
echo
"Usage:"
echo
"fix_disk [--fix]
exit
fi
TESTONLY=
FORCE=
LIST=
[ "
$1
" = "
--fix
" ] && { TESTONLY=
$1
; shift ; }
[ "
$1
" = "
--force
" ] && FORCE=
$1
[ "
$1
" = "
--list
" ] && LIST=
$1
test_block()
{
local DEV=
$1
local block=
$2
hdparm --read-sector
$block
$DEV
>/tmp/rs
RS=
$?
head -n3 /tmp/rs
return
$RS
}
fix_block()
{
DEV=
$1
block=
$2
# FIXME: possible badblocks always returns true
# badblocks -b 512 -v -s
$DEV
$block
$block
&& { echo "
Already OK, skipped...
" ; [ -z "
$FORCE
" ] && return ; }
test_block
$DEV
$block
&& { echo "
Already OK, skipped...
" ; [ -z "
$FORCE
" ] && return ; }
if [ -z "
$TESTONLY
" ] ; then
echo "
Test only
"
return
fi
# for i in 1 2 3 ; do
# badblocks -b 512 -f -v -w
$DEV
$block
$block
# sleep 1
# done
hdparm --yes-i-know-what-i-am-doing --repair-sector
$block
$DEV
# badblocks -b 512 -v -s
$DEV
$block
$block
&& { echo "
Read OK now!
" ; return ; }
test_block
$DEV
$block
&& { echo "
Read OK now!
" ; return ; }
echo "
Something still wrong with
$block
on
$DEV
"
}
# by dmesg
# FIXME: which device??
#BLOCKLIST=
$(
#Buffer I/O error on device sda, logical block 32607659
#dmesg | grep "logical block " | sed -e "s|.*Buffer I/O error on device \(sd[a-z]\), logical block \([0-9]*\)|\1 \2|g" | sort -u | \
echo
|
while
read
devname block
;
do
#for i in $BLOCKLIST ; do
echo
#FIXME: logical block - 8 sectors (on 64 bit) or 4 sectors (on 32 bit?)
echo
"List
$block
bad block on /dev/
$devname
..."
#echo "Fixing $block block on /dev/$devname ..."
#fix_block /dev/$devname $block
done
[
-n
"
$LIST
"
]
&&
exit
dmesg |
grep
"end_request: I/O error"
|
sed
-e
"s|.*end_request: I/O error, dev
\(
sd[a-z]
\)
, sector
\(
[0-9]*
\)
|
\1
\2
|g"
|
sort
-u
|
\
while
read
devname block
;
do
#for i in $BLOCKLIST ; do
echo
echo
"Fixing
$block
block on /dev/
$devname
..."
fix_block /dev/
$devname
$block
done
hdd/ttt.sh
0 → 100644
View file @
de364f1a
#!/bin/sh
INDEV
=
/dev/sdb
OUTDEV
=
/dev/sdc
read_sector
()
{
local
DEV
=
$1
local
block
=
$2
hdparm
--read-sector
$block
$DEV
>
$3
RS
=
$?
#head -n3 /tmp/rs
return
$RS
}
is_dirty_sector
()
{
cat
$1
|
sed
-e
"s|0000 0000 0000 0000 0000 0000 0000 0000||g"
-e
"s|reading.*||g"
|
\
grep
-v
"^$"
>
$1
.out
test
-s
$1
.out
}
echo
i
=
596500
while
true
;
do
i
=
$((
$i
+
1
))
[
$((
$i
%
100
))
=
0
]
&&
echo
-e
-n
"
\r
Sector
$i
"
read_sector
$INDEV
$i
/tmp/INrs
||
continue
read_sector
$OUTDEV
$i
/tmp/OUTrs
||
exit
subst
"s|/dev/.*||g"
/tmp/INrs /tmp/OUTrs
diff
-u
/tmp/INrs /tmp/OUTrs
&&
continue
# read and differs
echo
-e
"
\n
Problem with sector
$i
"
if
is_dirty_sector /tmp/OUTrs
;
then
echo
"Non empty target, skipping"
#continue
else
ofb
=
$((
512
*
$i
))
ddrescue
-d
--force
-i
$ofb
-o
$ofb
-c
1
-s
512
$INDEV
$OUTDEV
fi
#exit
done
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment