linux服务器系统盘坏且系统盘为软raid的修复方法
1 需要換新盤的情況
1.1 一塊盤grub損壞修復(fù)
一塊盤grub損壞修復(fù)(可通過另一塊盤進(jìn)入系統(tǒng)的情況)。更換硬盤的方式,可以熱插拔,也可以服務(wù)器斷電后更換,但如果是熱插拔,可能會(huì)導(dǎo)致盤符變更。壞了一塊硬盤的情況下,軟raid1恢復(fù)方法(以sdb為新更換的硬盤為例):
1.1.1 拷貝硬盤分區(qū)信息
拷貝正常的那塊硬盤分區(qū)信息到新的硬盤
[root@ ~]#sfdisk -d /dev/sda | sfdisk -f /dev/sdb
1.1.2 查看sdb的分區(qū)與sda是否一致
[root@ ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 300.0 GB, 300000000000 bytes
255 heads, 63 sectors/track, 36472 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sdb1 1 523 4194304 82 Linux swap / Solaris
Partition 1 does not end on cylinder boundary.
/dev/sdb2 * 523 36473 288773120 fd Linux raid autodetect
[root@ ~]# fdisk -l /dev/sda
Disk /dev/sda: 300.0 GB, 300000000000 bytes
255 heads, 63 sectors/track, 36472 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000dafc6
Device Boot Start End Blocks Id System
/dev/sda1 1 523 4194304 82 Linux swap / Solaris
Partition 1 does not end on cylinder boundary.
/dev/sda2 * 523 36473 288773120 fd Linux raid autodetect
1.1.3 讓內(nèi)核重載分區(qū)表
(若可以重啟服務(wù)器不需執(zhí)行此部)
[root@ ~]#partprobe /dev/sdb
1.1.4 把第二塊盤加入raid1中
[root@ ~]# mdadm /dev/md0 -a /dev/sdb2
等數(shù)據(jù)同步到SDB 完成之后執(zhí)行
1.1.5 復(fù)制操作系統(tǒng)的引導(dǎo)程序
(復(fù)制操作系統(tǒng)的前512字節(jié)的引導(dǎo)程序到新的硬盤,最關(guān)鍵一步,否則開機(jī)無法正常引導(dǎo),現(xiàn)場(chǎng)軟raid同步后沒法啟動(dòng)就是這個(gè)原因)
[root@ ~]# dd if=/dev/sda of=/dev/sdb bs=512 count=1
ps:硬盤上第0磁道第一個(gè)扇區(qū)被稱為MBR,也就是Master Boot Record,即主引導(dǎo)記錄,它的大小是512字節(jié),里面卻存放了預(yù)啟動(dòng)信息、分區(qū)表信息。
系統(tǒng)找到BIOS所指定的硬盤的MBR后,就會(huì)將其復(fù)制到0×7c00地址所在的物理內(nèi)存中。被復(fù)制到物理內(nèi)存的內(nèi)容就是Boot Loader,即grub。
1.1.6 添加新盤swap
[root@ ~]# mkswap
/dev/sdb1
[root@ ~]# swapon
/dev/sdb1
上面命令只在未重啟時(shí)生效
1.1.7修改fstab
修改fstab中已經(jīng)被換掉的硬盤的UUID為新swap的UUID,保證swap重啟服務(wù)器可以生效
[root@ ~]# cat
/etc/fstab
UUID可通過blkid查看
1.2 兩塊盤grub均損壞(無法進(jìn)入系統(tǒng))
有一些之前已經(jīng)換過系統(tǒng)盤,沒有按照上面的操作,然后另一塊也壞了,此時(shí)兩塊硬盤都沒法進(jìn)入系統(tǒng),采用如下方法:
掛載光盤,進(jìn)應(yīng)急模式修復(fù)
Bash-4.1# chroot /mnt/sysimage
Sh-4.1# grub
Grub > root (hd0,1)
Grub> setup (hd0)
Grub> quit
Sh-4.1# exit
Bash-4.1# reboot
成功
2 不需要換盤的情況
現(xiàn)場(chǎng)存在硬盤沒問題,但是掉raid的情況(大部分是這種情況)
檢測(cè)方法
2.1 檢查硬盤的是否正常
2.1.1 smartctl -a /dev/sdb
注意上面得輸出,標(biāo)注位置沒有錯(cuò)誤,表示硬盤沒問題
2.1.2 smartctl -H /dev/sdb
一般用這個(gè)查就可以了,health為ok即表示硬盤沒問題
2.1.3 badblocks -sv /dev/sdb
全盤掃,很慢,不建議
2.2若硬盤沒問題,重新同步即可
2.2.1 檢查raid狀態(tài)
[root@ ~]#mdadm -D /dev/md0
/dev/md0:
Version : 1.0
Creation Time : Tue Apr 29 15:19:50 2014
Raid Level : raid1
Array Size : 288772984 (275.40 GiB 295.70 GB)
Used Dev Size : 288772984 (275.40 GiB 295.70 GB)
Raid Devices : 2
Total Devices : 2
Persistence
: Superblock is persistent
Intent Bitmap : Internal
Update Time : Mon Jul 4 15:05:56
2016
State : active, degraded
Active Devices : 1
Working Devices : 1
Failed Devices : 1
Spare Devices : 0
Name : example.sz.fonsview.com:0
UUID : 8c78cdee:b6be167c:85cce8f9:9e2fe8e8
Events : 26915749
Number Major Minor
RaidDevice State
0 0 0
0 removed
1 8 18
1 active sync /dev/sdb2
0 8 2
- faulty
spare /dev/sda2
若紅色字體部分為faulty,執(zhí)行:
[root@ ~]# mdadm /dev/md0 -r /dev/sdb
[root@ ~]# mdadm /dev/md0 -a /dev/sda2
若紅色字體部分為remove,執(zhí)行:
[root@ ~]# mdadm /dev/md0 -a /dev/sda2
2.2.1 查看同步狀態(tài)
[root@ ~]# cat /proc/mdstat
總結(jié)
以上是生活随笔為你收集整理的linux服务器系统盘坏且系统盘为软raid的修复方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: WinDbg常用命令系列---单步执行p
- 下一篇: 【转】三度带与六度带 换算