打印

CENTOS sata raid1 恢复全记录

本帖已经被作者加入个人空间 本主题由 南非蚂蚁 于 2008-10-24 17:02 解除置顶

CENTOS sata raid1 恢复全记录

前日,服务的一个SATA300GB /dev/sda  硬盘突然开始不工作。在bios里面都无法检测到。刚过一年质保。
因为有作RAID1,立刻把它的数据线给拔掉,使用/dev/sdb 单硬盘工作。
昨天,就买了一块同型号的硬盘。把硬盘接上后,加电,
下面是恢复过程:
/sbin/sfdisk -d /dev/sda
#/sbin/sfdisk -d /dev/sdb > partitions.sda
#vi & replace sdb with sda.
6.28pm,Jan 30 2007
#sfdisk /dev/sda < partitions.sda
[root@jupiter ~]# sfdisk /dev/sda < partitions.sda
Checking that no-one is using this disk right now ...
OK

Disk /dev/sda: 36481 cylinders, 255 heads, 63 sectors/track

sfdisk: ERROR: sector 0 does not have an msdos signature
/dev/sda: unrecognized partition
Old situation:
No partitions found
New situation:
Units = sectors of 512 bytes, counting from 0

   Device Boot    Start       End   #sectors  Id  System
/dev/sda1   *        63   2104514    2104452  fd  Linux raid autodetect
/dev/sda2       2104515  32820794   30716280  fd  Linux raid autodetect
/dev/sda3      32820795  63537074   30716280  fd  Linux raid autodetect
/dev/sda4      63537075 586067264  522530190   5  Extended
/dev/sda5      63537138  67601519    4064382  82  Linux swap
/dev/sda6      67601583 586067264  518465682  fd  Linux raid autodetect
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).)
Running Raid Commands to Recover Partitions
mdadm /dev/md0 -a /dev/sda3
mdadm /dev/md1 -a /dev/sda1
mdadm /dev/md2 -a /dev/sda2
mdadm /dev/md3 -a /dev/sda6

[root@jupiter boot]# grub
Probing devices to guess BIOS drives. This may take a long time.


    GNU GRUB  version 0.95  (640K lower / 3072K upper memory)

[ Minimal BASH-like line editing is supported.  For the first word, TAB
   lists possible command completions.  Anywhere else TAB lists the possible
   completions of a device/filename.]
grub> device (hd0) /dev/sda
device (hd0) /dev/sda
grub> root (hd0,0)
root (hd0,0)
Filesystem type is ext2fs, partition type 0xfd
grub> setup (hd0)
setup (hd0)
Checking if "/boot/grub/stage1" exists... no
Checking if "/grub/stage1" exists... yes
Checking if "/grub/stage2" exists... yes
Checking if "/grub/e2fs_stage1_5" exists... yes
Running "embed /grub/e2fs_stage1_5 (hd0)"...  16 sectors are embedded.
succeeded
Running "install /grub/stage1 (hd0) (hd0)1+16 p (hd0,0)/grub/stage2 /grub/grub.conf"... succeeded
Done.

今天早上检查了一下状态,
$ cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 sdb1[1] sda1[0]
      1052160 blocks [2/2] [UU]
      
md2 : active raid1 sdb2[1] sda2[0]
      15358016 blocks [2/2] [UU]
      
md3 : active raid1 sdb6[1] sda6[0]
      259232768 blocks [2/2] [UU]
      
md0 : active raid1 sdb3[0] sda3[1]
      15358016 blocks [2/2] [UU]
      
unused devices: <none>

完全正常,重新启动,ok.
$ sar
Linux 2.6.9-42.0.3.ELsmp (jupiter)      2007年01月31日

08时07分42秒       LINUX RESTART

08时10分01秒       CPU     %user     %nice   %system   %iowait     %idle
08时15分01秒       all      9.38      0.00      2.18      8.94     79.50
08时20分01秒       all      2.71      0.00      1.03      0.20     96.06
08时25分01秒       all      2.13      0.00      0.92      0.77     96.18
08时30分01秒       all     34.63      2.62     11.47     11.34     39.93
08时35分01秒       all     55.41      0.91     20.22      4.85     18.62
08时40分01秒       all     60.05      0.66     16.01      9.12     14.16
08时45分01秒       all     30.32      0.11      6.80      4.30     58.48
08时50分01秒       all     29.60      0.09      8.07      3.11     59.14
08时55分01秒       all     32.00      0.09      7.22      1.73     58.95
09时00分02秒       all     39.58      0.14     11.28      6.56     42.43
Average:          all     29.55      0.46      8.51      5.09     56.39
每一天都在努力。

TOP

数据可以恢复过来嘛?作RAID1用是什么用途来的,不懂
知识在于积累,积分在于灌水

TOP

好强大
每一天都在努力

TOP

只是坏了一块硬盘。两个硬盘做镜像的。如果两个硬盘同时坏了,就难了。
每一天都在努力。

TOP

哦,就是有备份了
知识在于积累,积分在于灌水

TOP

数据恢复是自动恢复吗???

TOP

真不错,谢谢了

TOP

恭喜您,您遇上财神了,送给你3庆典金币!
最近做了一件事情,一个希捷的sata 300G硬盘,突然又坏了。
[root@jupiter ~]# cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 sdb1[1]
      1052160 blocks [2/1] [_U]
      
md2 : active raid1 sdb2[1]
      15358016 blocks [2/1] [_U]
      
md3 : active raid1 sdb6[1]
      259232768 blocks [2/1] [_U]
      
md0 : active raid1 sdb3[0]
      15358016 blocks [2/1] [U_]

还好,咱们是raid1,另一个硬盘继续工作。
于是买了2个500GB的SATA 硬盘 Barracuda ES.2 SATA 3.0-Gb/s 500-GB Hard Drive
ST3500320NS
The Barracuda® ES2 drive is perfect for high-capacity, 7200-RPM nearline storage where dollars/GB and watts/GB are primary metrics. It offers energy-saving PowerTrim™ features, internal data integrity protection, superior rotational vibration tolerance and a SATA 3.0-Gb/s interface.
顺便将此服务器的硬盘做了一下升级。

首先将此两个硬盘做了如下分区。
[root@jupiter ~]# fdisk -l /dev/sda

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         111      891576   fd  Linux raid autodetect
/dev/sda2             112       60557   485532495   fd  Linux raid autodetect
/dev/sda3           60558       60801     1959930   fd  Linux raid autodetect

然后将此硬盘的分区信息拷贝给/dev/sdb
sfdisk -d /dev/sda | sfdisk /dev/sdb

创建RAID1
[root@jupiter ~]# mdadm --create /dev/md4 --level=1 --raid-devices=2 /dev/sda1 /dev/sdc1
[root@jupiter ~]# mdadm --create /dev/md5 --level=1 --raid-devices=2 /dev/sda1 /dev/sdc1
[root@jupiter ~]# mdadm --create /dev/md6 --level=1 --raid-devices=2 /dev/sda2 /dev/sdc2

创建过程中
[root@jupiter ~]# cat /proc/mdstat
Personalities : [linear] [raid0] [raid1] [raid5] [multipath] [raid6] [raid10]
md6 : active raid1 sdc3[1] sda3[0]
      1959808 blocks [2/2] [UU]
              resync=DELAYED
md5 : active raid1 sdc2[1] sda2[0]
      485532416 blocks [2/2] [UU]
      [>....................]  resync =  1.2% (6048960/485532416) finish=75.0min speed=106438K/sec
md4 : active raid1 sdc1[1] sda1[0]
      891456 blocks [2/2] [UU]
      
md1 : active raid1 sdb1[1]
      1052160 blocks [2/1] [_U]
      
md2 : active raid1 sdb2[1]
      15358016 blocks [2/1] [_U]
      
md3 : active raid1 sdb6[1]
      259232768 blocks [2/1] [_U]
      
md0 : active raid1 sdb3[0]
      15358016 blocks [2/1] [U_]

格式化 /boot 分区
[root@jupiter ~]# mkfs.ext3 /dev/md4
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
111552 inodes, 222864 blocks
11143 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=230686720
7 block groups
32768 blocks per group, 32768 fragments per group
15936 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840

Writing inode tables: done                           
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 22 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

创建跟分区
[root@jupiter ~]# mkfs.ext3 /dev/md5
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
60702720 inodes, 121383104 blocks
6069155 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
3705 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
        102400000

Writing inode tables: done                           
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information:
done

This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

创建SWAP分区
[root@jupiter etc]# mkswap /dev/md6
Setting up swapspace version 1, size = 2006839 kB


[root@jupiter mnt]# mount /dev/md5 /mnt/clone/
[root@jupiter mnt]# mount /dev/md4 /mnt/clone/boot

[root@jupiter ~]# cd /
[root@jupiter /]# date && tar clf - boot | tar xf - -C clone &&date
[root@jupiter /]# date && tar clf - . | tar xf - -C clone &&date

备份raid信息
[root@jupiter /]#mdadm --detail --scan > mdadm.conf

[root@jupiter ~]# mdadm --detail --scan
ARRAY /dev/md4 level=raid1 num-devices=2 UUID=c3c1e237:61b1f846:e3dd04c2:6af5244f
ARRAY /dev/md5 level=raid1 num-devices=2 UUID=9f3a791a:f2b4326d:ed35c93a:2daf9f54
ARRAY /dev/md6 level=raid1 num-devices=2 UUID=db336a88:57aef2be:6071c24c:841c6453

修改grub信息
[root@jupiter ~]# cat /boot/grub/menu.lst
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/md0
#          initrd /initrd-version.img
#boot=/dev/sda1
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.9-78.0.1.ELsmp)
        root (hd0,0)
        kernel /vmlinuz-2.6.9-78.0.1.ELsmp ro root=/dev/md5 rhgb quiet
        initrd /initrd-2.6.9-78.0.1.ELsmp.img
每一天都在努力。

TOP

写入引导分区

[root@jupiter boot]# grub
Probing devices to guess BIOS drives. This may take a long time.


    GNU GRUB  version 0.95  (640K lower / 3072K upper memory)

[ Minimal BASH-like line editing is supported.  For the first word, TAB
   lists possible command completions.  Anywhere else TAB lists the possible
   completions of a device/filename.]
grub> device (hd0) /dev/sda
device (hd0) /dev/sda
grub> root (hd0,0)
root (hd0,0)
Filesystem type is ext2fs, partition type 0xfd
grub> setup (hd0)
setup (hd0)
Checking if "/boot/grub/stage1" exists... no
Checking if "/grub/stage1" exists... yes
Checking if "/grub/stage2" exists... yes
Checking if "/grub/e2fs_stage1_5" exists... yes
Running "embed /grub/e2fs_stage1_5 (hd0)"...  16 sectors are embedded.
succeeded
Running "install /grub/stage1 (hd0) (hd0)1+16 p (hd0,0)/grub/stage2 /grub/grub.conf"... succeeded
Done.

[root@jupiter boot]# grub
Probing devices to guess BIOS drives. This may take a long time.


    GNU GRUB  version 0.95  (640K lower / 3072K upper memory)

[ Minimal BASH-like line editing is supported.  For the first word, TAB
   lists possible command completions.  Anywhere else TAB lists the possible
   completions of a device/filename.]
grub> device (hd0) /dev/sdb
device (hd0) /dev/sdb
grub> root (hd0,0)
root (hd0,0)
Filesystem type is ext2fs, partition type 0xfd
grub> setup (hd0)
setup (hd0)
Checking if "/boot/grub/stage1" exists... no
Checking if "/grub/stage1" exists... yes
Checking if "/grub/stage2" exists... yes
Checking if "/grub/e2fs_stage1_5" exists... yes
Running "embed /grub/e2fs_stage1_5 (hd0)"...  16 sectors are embedded.
succeeded
Running "install /grub/stage1 (hd0) (hd0)1+16 p (hd0,0)/grub/stage2 /grub/grub.conf"... succeeded
Done.

重新启动 OK.
每一天都在努力。

TOP

秀一下
[root@jupiter ~]# mdadm --detail /dev/md4
/dev/md4:
        Version : 00.90.01
  Creation Time : Wed Sep 17 21:08:53 2008
     Raid Level : raid1
     Array Size : 891456 (870.71 MiB 912.85 MB)
    Device Size : 891456 (870.71 MiB 912.85 MB)
   Raid Devices : 2
  Total Devices : 2
Preferred Minor : 4
    Persistence : Superblock is persistent

    Update Time : Fri Sep 19 22:44:07 2008
          State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
  Spare Devices : 0

           UUID : c3c1e237:61b1f846:e3dd04c2:6af5244f
         Events : 0.713

    Number   Major   Minor   RaidDevice State
       0       8        1        0      active sync   /dev/sda1
       1       8       17        1      active sync   /dev/sdb1
[root@jupiter ~]# mdadm --detail /dev/md5
/dev/md5:
        Version : 00.90.01
  Creation Time : Wed Sep 17 21:09:09 2008
     Raid Level : raid1
     Array Size : 485532416 (463.04 GiB 497.19 GB)
    Device Size : 485532416 (463.04 GiB 497.19 GB)
   Raid Devices : 2
  Total Devices : 2
Preferred Minor : 5
    Persistence : Superblock is persistent

    Update Time : Fri Sep 19 22:47:27 2008
          State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
  Spare Devices : 0

           UUID : 9f3a791a:f2b4326d:ed35c93a:2daf9f54
         Events : 0.68011

    Number   Major   Minor   RaidDevice State
       0       8        2        0      active sync   /dev/sda2
       1       8       18        1      active sync   /dev/sdb2
[root@jupiter ~]# mdadm --detail /dev/md6
/dev/md6:
        Version : 00.90.01
  Creation Time : Wed Sep 17 21:09:23 2008
     Raid Level : raid1
     Array Size : 1959808 (1914.20 MiB 2006.84 MB)
    Device Size : 1959808 (1914.20 MiB 2006.84 MB)
   Raid Devices : 2
  Total Devices : 2
Preferred Minor : 6
    Persistence : Superblock is persistent

    Update Time : Fri Sep 19 19:50:43 2008
          State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
  Spare Devices : 0

           UUID : db336a88:57aef2be:6071c24c:841c6453
         Events : 0.16

    Number   Major   Minor   RaidDevice State
       0       8        3        0      active sync   /dev/sda3
       1       8       19        1      active sync   /dev/sdb3

[root@jupiter ~]# df -ha
Filesystem            Size  Used Avail Use% Mounted on
/dev/md5              456G  247G  187G  57% /
none                     0     0     0   -  /proc
none                     0     0     0   -  /sys
none                     0     0     0   -  /dev/pts
usbfs                    0     0     0   -  /proc/bus/usb
/dev/md4              857M  142M  672M  18% /boot
none                  3.7G     0  3.7G   0% /dev/shm
none                     0     0     0   -  /proc/sys/fs/binfmt_misc
sunrpc                   0     0     0   -  /var/lib/nfs/rpc_pipefs
[root@jupiter ~]# uname -a
Linux jupiter 2.6.9-78.0.1.ELsmp #1 SMP Tue Aug 5 10:56:55 EDT 2008 x86_64 x86_64 x86_64 GNU/Linux
[root@jupiter ~]# cat /etc/redhat-release
CentOS release 4.7 (Final)
每一天都在努力。

TOP


感谢一直以来您对我们的支持!
当前时区 GMT+8, 现在时间是 2008-12-3 03:59 京ICP证060528 号

Designed By 17DST