linux raid1无法恢复,RAID1单硬盘损坏更换硬盘后恢复的方法

其实很简单,在万一真出问题前演练一下没准扣我少点工资(

假设有sda和sdb两个盘并组了raid1

这里的情况是sdb突然爆炸了,无法使用。

可以使用mdadm模拟这种情况:

mdadm --manage /dev/md0 --fail /dev/sdb1

mdadm --manage /dev/md1 --fail /dev/sdb2

或者模拟暴力移除:

mdadm --manage /dev/md0 --remove /dev/sdb1

mdadm --manage /dev/md1 --remove /dev/sdb2

reboot重启一下

运行

cat /proc/mdstat

查看当前磁盘raid情况

[root@server1 ~]# cat /proc/mdstat

Personalities : [raid1]

md0 : active raid1 sda1[0]

104320 blocks [2/1] [U_]

md1 : active raid1 sda2[0]

10377920 blocks [2/1] [U_]

unused devices:

[root@server1 ~]#

也可以使用fdisk

fdisk -l

[root@server1 ~]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/sda1 * 1 13 104391 fd Linux raid autodetect

/dev/sda2 14 1305 10377990 fd Linux raid autodetect

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table

Disk /dev/md1: 10.6 GB, 10626990080 bytes

2 heads, 4 sectors/track, 2594480 cylinders

Units = cylinders of 8 * 512 = 4096 bytes

Disk /dev/md1 doesn't contain a valid partition table

Disk /dev/md0: 106 MB, 106823680 bytes

2 heads, 4 sectors/track, 26080 cylinders

Units = cylinders of 8 * 512 = 4096 bytes

Disk /dev/md0 doesn't contain a valid partition table

[root@server1 ~]#

假设现在新的好硬盘sdb已经换上了

先同步一下分区表

sfdisk -d /dev/sda | sfdisk /dev/sdb

[root@server1 ~]# sfdisk -d /dev/sda | sfdisk /dev/sdb

Checking that no-one is using this disk right now ...

OK

Disk /dev/sdb: 1305 cylinders, 255 heads, 63 sectors/track

sfdisk: ERROR: sector 0 does not have an msdos signature

/dev/sdb: unrecognized partition table type

Old situation:

No partitions found

New situation:

Units = sectors of 512 bytes, counting from 0

Device Boot Start End #sectors Id System

/dev/sdb1 * 63 208844 208782 fd Linux raid autodetect

/dev/sdb2 208845 20964824 20755980 fd Linux raid autodetect

/dev/sdb3 0 - 0 0 Empty

/dev/sdb4 0 - 0 0 Empty

Successfully wrote the new partition table

Re-reading the partition table ...

If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)

to zero the first 512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1

(See fdisk(8).)

[root@server1 ~]#

同时,可能新硬盘其实是个二手硬盘以前做过raid,这时我们需要把sdb里的raid记录清空一遍。

mdadm --zero-superblock /dev/sdb1

mdadm --zero-superblock /dev/sdb2

然后我们就可以把硬盘和以前的硬盘组起来了

mdadm -a /dev/md0 /dev/sdb1

mdadm -a /dev/md1 /dev/sdb2

然后就可以查看硬盘数据恢复情况了

cat /proc/mdstat

[root@server1 ~]# cat /proc/mdstat

Personalities : [raid1]

md0 : active raid1 sdb1[1] sda1[0]

104320 blocks [2/2] [UU]

md1 : active raid1 sdb2[2] sda2[0]

10377920 blocks [2/1] [U_]

[======>..............] recovery = 32.3% (3360768/10377920) finish=1.5min speed=74238K/sec

unused devices:

[root@server1 ~]#

还有,不要忘记给两个硬盘都重新安装引导!

grub:

grub

root (hd0,0)

setup (hd0)

root (hd1,0)

setup (hd1)

quit

grub2:

grub2-install /dev/sda

grub2-install /dev/sdb

syslinux:

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值