blob: 6858a8a389c458dc2c47d7152da6268112aa3b01 (
plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#!/bin/bash
if [ $# -ne 1 ] || [ ! -b "$1" ]; then
>&2 echo 'run:'
>&2 echo ' kamikaze-fsck /dev/$device'
exit 1
fi
if ! [ -w "$1" ]; then
>&2 printf 'Cannot write to "%s" - you are not root, are you?\n' "$1"
exit 1
fi
>&2 printf 'Warning: running e2fsck in kamikaze-mode - this WILL destroy data on "%s".\n' "$1"
>&2 printf 'Enter uppercase yes to continue.\n'
read -r s
if [ "$s" != 'YES' ]; then
>&2 echo 'aborted.'
exit 1
fi
>&2 echo 'ok, lets do it'
tmp_dir=$(mktemp -d)
trap 'rm -rf --one-file-system "${tmp_dir}"' EXIT
touch "${tmp_dir}/faulty-inode"
while [ -f "${tmp_dir}/faulty-inode" ]; do
if [ -s "${tmp_dir}/faulty-inode" ]; then
debugfs -w "$1" -R "$(cat "${tmp_dir}/faulty-inode")"
fi
rm "${tmp_dir}/faulty-inode"
last_faulty_inode='INVALID'
e2fsck -f -y "$1" -E no_optimize_extents,fixes_only -C 0 \
| tee /dev/stderr \
| sed '
s/^Inode \([0-9]\+\) block [0-9]\+ conflicts with critical metadata, skipping block checks\.$/\1/
t
d
' \
| while read -r faulty_inode; do
if [ "${last_faulty_inode}" != "${faulty_inode}" ]; then
last_faulty_inode="${faulty_inode}"
faulty_inode_count=0
fi
faulty_inode_count=$((faulty_inode_count+1))
if [ ${faulty_inode_count} -ge 5 ]; then
printf 'clri <%s>\n' "${faulty_inode}" \
>> "${tmp_dir}/faulty-inode"
pkill -xf "e2fsck -f -y $1 -E no_optimize_extents,fixes_only -C 0"
sleep 20
pkill -9 -xf "e2fsck -f -y $1 -E no_optimize_extents,fixes_only -C 0"
while pgrep -xf "e2fsck -f -y $1 -E no_optimize_extents,fixes_only -C 0"; do
sleep 1
done
fi
done
done
|