|
This file is 2.1 rom, maybe can fsck & reformat system...but i haven't use or try....please read it first...- #!/bin/sh( @) y4 X% t- `8 K; @; c5 F, F
- 6 a) n! {& z& A/ D$ q, ]: Z' q( `; S
- # [color=Red]Given a partition or mountpoint, fix it. Umount it if needed, fsck8 L9 ?6 m4 C5 n
- # it, try to mount it, and if that fails reformat it and mount it
, ?$ p Y7 i9 B6 o* ] - # again. Once this function returns, we've either mounted the1 v: T% c: X4 q4 j/ a0 p4 ~4 I1 K- |
- # partition (which may now be empty!) or we're so f*cked there's no
7 c4 k; F& Z4 u2 B( r3 v. F7 x - # hope of recovery.[/color]
& G4 d# T+ C& q% _) o - #
* s/ G, D$ ]6 O( B' \' e8 q% B) R O - # Pending: is it an option whether we pass -f to fsck?5 P. T+ F. w. T) P6 a- {6 F5 c$ R
- 6 L( f% F' a' g5 J8 r
- test -f /etc/default/mount_checks && . /etc/default/mount_checks
- X$ ^- v# K& D0 q
1 Y+ p7 [! V" R4 ~$ d- echo "$0 $*" | tee /dev/console > /dev/kmsg/ e h+ ?9 D$ K) O, {$ ^. A+ p7 J% C
- - h. t" u$ @3 k) X R* k0 f
- usage() {) c! L/ |* [; S% d
- echo "usage: $0 [--force-fsck] [--force-reformat] " > /dev/console
/ v# {8 Q' r3 R3 Y4 y - echo " | [--force-zero] --device </dev/something/maybe> " > /dev/console! f7 |' T) D9 j1 y5 q F
- echo " | --mountpoint <mountpoint>" > /dev/console
% c* W1 U4 N/ d7 y# T0 R' f! @ - exit 1
( \' z0 `0 ?1 B3 M/ F# y - }
, J4 G; x! ]- H) p5 O3 ?6 m
9 h6 a% x, R3 g/ U: H5 N) A9 ^, I& X! d- reformat() {5 I3 h- V" a1 r; N) m
- DEVICE=$1
& y5 c) r0 M5 X( ] v+ Y - 2 L! L' M7 g7 a; F
- # There's nothing to do if we can't umount...
/ c7 E: A+ I, `0 P. k0 `* K! v - grep "^${DEVICE}\s" /proc/mounts && umount $DEVICE+ o" t- c" i% |. j
, U( _ K! y$ j3 U7 i2 O2 e- DEV_AS_NAME=$(echo $DEVICE | tr '/' '_')0 S8 s9 M( X2 c! _
- if [ -x /etc/fs.d/do_format${DEV_AS_NAME}.sh ]; then# J; X2 {0 o9 }3 \* L% D0 F
- /etc/fs.d/do_format${DEV_AS_NAME}.sh# H( {3 ?7 v# Q* }% M
- mount $DEVICE 2>&1 | tee /dev/console | logger -s 3 m- U0 K* r: I0 J2 ?! R
- else
' B) n. m+ Y5 D, e: G+ O0 \4 l- u - TYPE=$(grep /dev/mapper/store-update /etc/fstab | awk '{print $3}')
" ~/ w; F8 i* G - case $TYPE in7 l! f# [9 g/ d4 ]$ u2 @& U) e
- ext3)1 s. h7 q, @2 L4 c: P" A- V% o' G. H
- [ $DEVICE = /dev/mapper/store-filecache ] && DASH_I="-I 256"9 F& L9 D3 b& G6 c5 e3 _7 Q" L# N: L
- mke2fs -j -b4096 -m0 $DASH_I $DEVICE
( q |) f. P- i8 h5 P! q; O - tune2fs -i 0 $DEVICE
7 z$ u* I+ ], I - ;;
! Z: U2 G3 x+ Y9 L) I1 R4 p - vfat)4 \+ R" a& w6 g0 N
- [color=Red] mkdosfs -f 1 -s 64 $DEVICE[/color]
8 `; u5 o0 y3 ^3 h. c6 {) n' C3 W7 ` - ;;
2 f1 r8 z, h! A0 Q* I - *)9 l8 x' q% E: ^% ?% v6 j6 w, x f
- echo "unable to reformat device $DEVICE of type $TYPE" | tee /dev/kmsg > /dev/console
$ i) x, [* d/ T( W7 F+ a$ B - ;;2 R4 I, \# A: ~# v, _+ x5 s
- esac
# F( |2 v3 w9 v; {/ i - , t0 R) O* Q, R- |& c7 I9 L. ^, [
- fi' t: T8 p- Y/ t8 A3 ]7 W4 B1 L
- }$ d' q& W( `$ J* m2 e H
/ U, u k. v" y- # mount /var || fixup_partition --device /var --force-fsck
5 C; _; Y V9 \7 E5 r' |+ X$ i" T, g) u - # fixup_partition --mountpoint /var --force-reformat $WIPE4 [. ~$ h0 P% H' [" U
- # fixup_partition --mountpoint /media/internal --force-reformat $WIPE. Q1 m. N" y1 t; ]! R$ C8 n
- # fixup_partition --mountpoint $PT --force-reformat $WIPE! L* O1 K6 @ x) N) O( z, [
- # MEDIA_FIX=$(fixup_partition --mountpoint /media/internal)
" N# m1 |" u$ R$ l w8 [" W9 I
& ?2 g h: _. [3 G$ E, T5 q1 z- # uses:
4 o% T$ J9 `# |: f8 L$ ~' }4 j8 } - # partition didn't mount; make it mount or reformat if necessary9 J( b( U9 u* J8 N
- # reformat partition regardless of current state, optionally zeroing first3 z2 f1 \2 a1 K) I0 A) `9 G5 X
- # always return with the thing mounted A; X5 I; Q, J! V
/ N( r9 |( t* m! t" G& x" Q$ ?! h- while [ -n "$1" ]; do
: F w# O/ A. D4 K7 u - case "$1" in
4 O+ l4 g/ H5 s* n2 z4 ~ - --device )
0 e3 l# Q9 g/ B+ [ R - DEVICE="$2"
; c" U: b& ?; L- \$ y - MOUNTPT=$(grep "^${DEVICE}\s" /etc/fstab | awk '{print $2}')
1 I) p6 h8 j( S. I! f3 N4 ]- |/ u5 { - shift 1% c w" I+ D3 r
- ;;
, I; b% w: U% w; Z* `1 z+ W - --mountpoint )
7 f& s$ j2 Q& `1 }4 J4 [- h - MOUNTPT="$2"; x, Q# D% l/ ]" P! n; }
- DEVICE=$(grep "\s${MOUNTPT}\s" /etc/fstab | awk '{print $1}')" _1 M9 `/ f8 ^
- shift 1
/ g! \1 S. `) P: |5 o7 { - ;;: u w, A7 Y* T) L
- --force-fsck )
. U) }( y) B0 U - FORCE_FSCK="-f"
9 } m9 u" j# ?* |4 r - ;;: ?& ~( H3 E% A% D9 H
- --force-reformat )1 ^ H# h6 S- Y# t; f
- FORCE_REFORMAT=1
- u4 M5 N* v6 s3 v" _( [# `6 P# @ - ;;" W9 T; y! ]6 T8 Q
- --force-zero )
) `; `% N, |- g1 P$ n( D - FORCE_REFORMAT=1 # impiled by zero3 \# \- v) A, \) N6 O# o. K: r5 }* u
- FORCE_ZERO=1
& X8 [6 T% b' X7 _( E - ;;+ x/ ?$ o% ], H" v7 }3 v. }' z
- * )
# ~+ B8 d5 t+ J' [% s: s, I - echo "$1: unknown param" > /dev/console
$ C& ~5 |- y6 H4 v! B4 ~# V/ D - usage$ P8 r% h p% V3 g
- ;;1 z' T# N* Z5 t0 l1 O, i5 M8 {4 |( o
- esac
- k. M& o$ d5 ? - shift 1& M, |( d* k3 ?" s: l* A
- done2 I R5 t% H; I- x2 v
- 0 r" n* X$ x; y
- if [ -z "$DEVICE" -o -z "$MOUNTPT" ]; then' u7 {1 h, E* |) Z* `( {
- echo "unable to find device or mountpoint" > /dev/console4 N9 W4 `4 m0 d8 _9 @
- usage2 F1 j! a$ e) C. L
- fi
, ^% ~% t/ h/ N: [3 f
! w) `1 b! q! y; ~0 G2 B- # umount if mounted; not an error if not5 `& n' M3 V" E$ }$ P( O9 A% I) ~9 ]
- if grep -q "\s${MOUNTPT}\s" /proc/mounts; then
5 ]- m5 G8 |3 Q9 }5 F [, Z5 K1 p - # need to loop passing --force-umount flags; this must succeed.0 Q% w% ^ [* G) `" h% N
- # Would log those holding files open in this case.
" i0 [3 E q' y - if ! umount_or_blame.sh $MOUNTPT; then
, |8 U; V1 b: U, E' R8 k" M* a* e* A - echo "unable to umount $DEVICE" > /dev/console
; E9 ^7 _' k7 L* V% p" w - exit 10 z* c, c: ]6 |$ Y6 E
- fi$ |: ]4 S; K7 F n& Y2 G
- fi
* |( f: C |5 Y. W( y5 h7 A
+ b2 M" l; i4 E1 ~* c- # no point trying to fsck if we're reformating/zeroing
8 l) I1 n8 \$ ]" z - if [ -z "$FORCE_REFORMAT" ]; then2 j9 A/ J6 a6 C8 {' Z
- fsck -y $FORCE_FSCK $DEVICE 2>&1 | tee /dev/console > /dev/kmsg
! P+ e% ^8 k: U" ~4 g8 i - WHAT_WAS_DONE="fsck"
' o8 d, `" L2 C6 J - fi
: s8 F. k/ _3 O8 J - $ p& E7 I. n0 P- F, I/ G8 {1 k6 q
- if [ -n "$FORCE_ZERO" ]; then
, @. L) j5 b% O, ^2 B7 a - 9 M, A- @. P5 H. l5 V
- # We only provide feedback for /media/internal
/ J* \2 Z# g7 O - FALLBACK=1( U- x P; h$ v3 z9 ~" r
- if [ $MOUNTPT = $MEDIA_MOUNT ]; then) K6 i5 I" v- I4 N2 ?
- FALLBACK=""
7 W) o1 W& V( E - FEEDBACK_PIPE=/tmp/progress
& z/ _2 f7 `3 G+ c2 F - # create named pipe to send progress to fbprogress
" }3 Q: p% |0 i2 \2 G - grep -q '/tmp\s' /proc/mounts || mount /tmp # may not be mounted....- N A; I6 A% \; W' m2 {( z6 X
- rm -rf $FEEDBACK_PIPE # in case it's something else" G# [% q" m0 M0 F
- if ! mknod $FEEDBACK_PIPE p; then( J1 V& @* Q) W& h' |
- echo "$0: mknod failed!!" | tee /dev/console > /dev/kmsg
) t( j8 z/ q* S* O - FALLBACK=1
7 @! M5 S4 W/ g - else
0 X9 P' R& R) e - # fbprogress shows indeterminate progress while wiping all
% l) s. R+ b$ ~3 \0 l4 |2 P - # partitions
' }9 K5 _* o0 i- ]- e! {; q - fbprogress -f erasing -p $FEEDBACK_PIPE &
$ b' Y$ n$ g1 y; C - FBPROGRESS_PID=$!7 y' |* ~/ i* T1 g9 S
- echo "$0: fbprogress: $FBPROGRESS_PID" | tee /dev/console > /dev/kmsg+ {) @/ w0 `1 F0 s
- ( W1 B' @* n% F& ?. d. |/ J7 s4 m
- /usr/sbin/wipe_with_feedback.sh $FEEDBACK_PIPE || FALLBACK=1
. B$ }& C7 d" D9 b - / K, U$ P4 H E) m8 v" r; i8 b
- kill $FBPROGRESS_PID+ B* D4 v4 Q/ j% S8 C; t
- rm -f $FEEDBACK_PIPE
7 B$ S% e4 X/ `9 h1 _. b5 } - fi( o5 g/ p, J8 Y. E( |/ h5 W
- fi- i- U- ^, v4 O) A$ J) @- |
: |& g8 g9 o5 e4 h- D: K- if [ -n "$FALLBACK" ]; then
T# t% X$ C9 e - dd if=/dev/zero of=$DEVICE bs=65536# L0 s# T& f. J( _0 B
- fi& M8 D9 y, K0 Y4 r
- fi6 P* p2 S$ ~7 @$ {3 e9 v
- 4 I. S9 Y( y% [8 b7 I+ i; R
- # Mount unless we're about to nuke; v$ Y* v4 g7 s* k4 b
- if [ -z "$FORCE_REFORMAT" ]; then
! j8 A5 F4 s2 t" @* U - mount $DEVICE 2>&1 | tee /dev/console | logger -s
. [6 N. D0 F1 w+ I! l - fi
" b& l) z6 _* O1 F - 5 R1 n6 G4 e0 k, K4 L6 d: v9 p3 h
- grep -q "\s${MOUNTPT}\s" /proc/mounts || FORCE_REFORMAT=1* ]2 T4 C1 K ?' _3 m, H
- ' O" U5 n' `; Z1 \; @: `4 s% x- o
- if [ -n "$FORCE_REFORMAT" ]; then
2 Y5 G$ v+ ]3 ^4 B/ T' [) S0 l - echo "$0: reformatting $DEVICE" | tee /dev/console > /dev/kmsg7 z7 ]; b) B* J+ F
- reformat $DEVICE9 Z8 x7 R4 a6 N9 p* y1 t
- WHAT_WAS_DONE="reformat"
) e; E- C8 x i0 M - mount $DEVICE
6 p: |: x# Y' X6 z+ t. M i! f* k - fi
6 Z T; r% t( x! X$ W
5 X3 A! B/ c$ R( [ E) b( M- # "return" what we did to fix the thing
1 |1 o I9 j6 u W0 f1 h0 t - echo "$WHAT_WAS_DONE"
% B/ i: ?$ @! x0 b. g - return $?"""
复制代码 |
|