使用Linux操作系统命令扫描硬盘
在系统“messages”日志中查看到文件系统异常时,采用Linux操作系统命令检查系统分区可以快速定位硬盘故障。
注意事项
badblocks命令扫描硬盘时会影响系统的IO性能,请不要在系统繁忙时执行。
操作步骤
以root用户登录。
查看系统当前硬盘信息。
# fdisk -l
例如,显示信息如下:
Disk /dev/sda: 298.9 GB, 298999349248 bytes
255 heads, 63 sectors/track, 36351 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 262 2104483+ 82 Linux swap / Solaris
/dev/sda2 * 263 32898 262148670 83 Linux
/dev/sda3 32899 36351 27736222+ 83 Linux
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
64 heads, 32 sectors/track, 40960 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
通过命令扫描硬盘。
# badblocks -s -v /dev/sdnx
其中n表示硬盘设备名,x表示硬盘对应的分区号。例如需要检查“/dev/sda2”,执行命令如下:
# badblocks -s -v /dev/sda2
Checking blocks 0 to 30681000
Checking for bad blocks (read-only test): 306809600674112/ 306810000000
30680964
30680965
30680966
30680967
30680968
30680969
30680970
30680971
30680972
30680973
...
done
Pass completed, 37 bad blocks found.其中,“37 bad blocks found”表示硬盘存在37个坏块。
atop查看系统异常情况
bj-xen-pdc04:~ # cd /var/log/atop/ (进入atop日志所在路径)
bj-xen-pdc04:/var/log/atop # ll
total 21832
-rw-r--r-- 1 root root 5111271 2013-06-30 00:00 atop_20130629
-rw-r--r-- 1 root root 5161400 2013-07-01 00:00 atop_20130630
-rw-r--r-- 1 root root 5190512 2013-07-02 00:00 atop_20130701
-rw-r--r-- 1 root root 4838774 2013-07-03 00:00 atop_20130702
-rw-r--r-- 1 root root 1989255 2013-07-03 09:29 atop_20130703
-rw------- 1 root root 0 2013-07-03 00:00 daily.log
bj-xen-pdc04:/var/log/atop # atop -r atop_20130703 (分析历史日志文件)
bj-xen-pdc04:~ # #atop (系统当前状态)
PRC | sys 259m06s | user 16m59s | | #proc 131 | #zombie 2 | clones 71138 | | #exit 0 |
CPU | sys 0% | user 0% | irq 0% | idle 197% | wait 2% | | steal 1% | guest 0% |
cpu | sys 0% | user 0% | irq 0% | idle 98% | cpu000 w 1% | | steal 0% | guest 0% |
cpu | sys 0% | user 0% | irq 0% | idle 99% | cpu001 w 1% | | steal 0% | guest 0% |
CPL | avg1 0.00 | avg5 0.01 | avg15 0.00 | | csw 180094e4 | intr 14098e5 | | numcpu 2 |
MEM | tot 4.0G | free 40.0M | cache 3.1G | dirty 0.0M | buff 259.0M | slab 214.4M | | |
SWP | tot 12.0G | free 12.0G | | | | | vmcom 421.5M | vmlim 14.0G |
PAG | scan 4118e4 | | stall 0 | | | swin 9 | | swout 24 |
DSK | sda | busy 2% | read 577992 | write 1199e4 | KiB/w 33 | MBr/s 0.02 | MBw/s 0.16 | avio 3.94 ms |
DSK | sdb | busy 0% | read 66 | write 0 | KiB/w 0 | MBr/s 0.00 | MBw/s 0.00 | avio 2.24 ms |
DSK | sdc | busy 0% | read 51 | write 0 | KiB/w 0 | MBr/s 0.00 | MBw/s 0.00 | avio 2.27 ms |
NET | transport | tcpi 6889896 | tcpo 1209373 | udpi 21 | udpo 323 | tcpao 15 | tcppo 44 | tcprs 773 |
NET | network | ipi 63073256 | ipo 3862948 | ipfrw 0 | deliv 9820e3 | | icmpi 2654e3 | icmpo 2652e3 |
NET | eth2 0% | pcki 51999e4 | pcko 52311e4 | si 220 Kbps | so 269 Kbps | erri 0 | erro 0 | drpo 0 |
NET | eth5 0% | pcki 56148e3 | pcko 22 | si 35 Kbps | so 0 Kbps | erri 0 | erro 0 | drpo 0 |
NET | bond1 ---- | pcki 51999e4 | pcko 52311e4 | si 220 Kbps | so 269 Kbps | erri 0 | erro 0 | drpo 0 |
NET | br1 ---- | pcki 11815e3 | pcko 3871052 | si 28 Kbps | so 58 Kbps | erri 0 | erro 0 | drpo 0 |
NET | bond0 ---- | pcki 56148e3 | pcko 22 | si 35 Kbps | so 0 Kbps | erri 0 | erro 0 | drpo 0 |
NET | br0 ---- | pcki 56121e3 | pcko 14 | si 31 Kbps | so 0 Kbps | erri 0 | erro 0 | drpo 0 |
NET | vif7.0 ---- | pcki 705258 | pcko 699066 | si 0 Kbps | so 0 Kbps | erri 0 | erro 0 | drpo 2 |
NET | lo ---- | pcki 621 | pcko 621 | si 0 Kbps | so 0 Kbps | erri 0 | erro 0 | drpo 0 |
** system and process activity since boot ***
PID RUID EUID THR SYSCPU USRCPU VGROW RGROW RDDSK WRDSK ST EXC S CPUNR CPU CMD 1/10
7188 root root 1 213m38s 0.02s 0K 0K 0K 0K N- - S 0 1% netback/0
7211 root root 9 13m34s 12m47s 291.6M 46128K 52244K 61036K N- - S 0 0% xend
28813 root root 1 8m20s 66.60s 0K 0K 8K 4K N- - Z 1 0% qemu-dm
8 root root 1 6m21s 9.58s 0K 0K 0K 0K N- - S 1 0% events/1
7 root root 1 6m26s 0.00s 0K 0K 0K 0K N- - S 0 0% events/0
7129 root root 1 3m37s 73.70s 8972K 564K 0K 0K N- - S 0 0% irqbalance
2705 root root 1 71.99s 0.00s 0K 0K 168K 343.8M N- - S 0 0% kjournald
7212 root root 3 50.41s 9.88s 114.5M 7272K 8K 4K N- - S 1 0% blktapctrl
4949 root root 1 42.55s 2.44s 0K 0K 0K 0K N- - S 1 0% bond0
5100 root root 1 43.81s 1.16s 0K 0K 0K 0K N- - S 1 0% bond1
5780 root root 3 32.32s 11.87s 89704K 3760K 1492K 4K N- - S 0 0% qemu-dm
7051 root root 1 35.57s 0.88s 0K 0K 0K 0K N- - S 0 0% HwLogHandle
5966 root root 1 0.88s 27.13s 403.1M 117.5M 37344K 178.3M N- - S 1 0% wireshark
29 root root 1 26.13s 0.00s 0K 0K 0K 10380K N- - S 0 0% kswapd0