zoukankan      html  css  js  c++  java
  • linux服务器系统盘坏且系统盘为软raid的修复方法

    1 需要换新盘的情况

    1.1 一块盘grub损坏修复

    一块盘grub损坏修复(可通过另一块盘进入系统的情况)。更换硬盘的方式,可以热插拔,也可以服务器断电后更换,但如果是热插拔,可能会导致盘符变更。坏了一块硬盘的情况下,软raid1恢复方法(以sdb为新更换的硬盘为例):

    1.1.1 拷贝硬盘分区信息

    拷贝正常的那块硬盘分区信息到新的硬盘 

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

    1.1.2 查看sdb的分区与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 让内核重载分区表

    (若可以重启服务器不需执行此部)

    [root@ ~]# partprobe /dev/sdb

     

    1.1.4 把第二块盘加入raid1中

     [root@ ~]# mdadm /dev/md0 -a /dev/sdb2

    等数据同步到SDB 完成之后执行

     

    1.1.5 复制操作系统的引导程序

    (复制操作系统的前512字节的引导程序到新的硬盘,最关键一步,否则开机无法正常引导,现场软raid同步后没法启动就是这个原因)

    [root@ ~]# dd if=/dev/sda of=/dev/sdb bs=512 count=1 

    ps:硬盘上第0磁道第一个扇区被称为MBR,也就是Master Boot Record,即主引导记录,它的大小是512字节,里面却存放了预启动信息、分区表信息。
    系统找到BIOS所指定的硬盘的MBR后,就会将其复制到0×7c00地址所在的物理内存中。被复制到物理内存的内容就是Boot Loader,即grub。

    1.1.6 添加新盘swap

    [root@ ~]# mkswap /dev/sdb1

    [root@ ~]# swapon /dev/sdb1

     

    上面命令只在未重启时生效

     

    1.1.7 修改fstab

    修改fstab中已经被换掉的硬盘的UUID为新swap的UUID,保证swap重启服务器可以生效

    [root@ ~]# cat /etc/fstab

    UUID可通过blkid查看

     

    1.2 两块盘grub均损坏(无法进入系统)

    有一些之前已经换过系统盘,没有按照上面的操作,然后另一块也坏了,此时两块硬盘都没法进入系统,采用如下方法:

    挂载光盘,进应急模式修复

     

    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 不需要换盘的情况

    现场存在硬盘没问题,但是掉raid的情况(大部分是这种情况)

    检测方法

    2.1 检查硬盘的是否正常

    2.1.1 smartctl -a /dev/sdb

     

    注意上面得输出,标注位置没有错误,表示硬盘没问题

    2.1.2 smartctl -H /dev/sdb

    一般用这个查就可以了,health为ok即表示硬盘没问题

     

    2.1.3 badblocks -sv /dev/sdb

    全盘扫,很慢,不建议

    2.2若硬盘没问题,重新同步即可

    2.2.1 检查raid状态

    [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,执行:

    [root@ ~]# mdadm /dev/md0 -r /dev/sdb

    [root@ ~]# mdadm /dev/md0  -a /dev/sda2

    若红色字体部分为remove,执行:

    [root@ ~]# mdadm /dev/md0  -a /dev/sda2

    2.2.1 查看同步状态

    [root@ ~]# cat /proc/mdstat

     

  • 相关阅读:
    How to: Use Function Criteria Operators to Filter List Views 如何:使用函数条件运算符筛选列表视图
    How to: Access the Report Parameters Object in Calculated Fields Expressions 如何:在计算字段表达式中访问报表参数对象
    How to: Access the ASPxReportDesigner Control 如何:访问 ASPx 报告设计器控件
    How to: Access the ASPxDocumentViewer and ASPxWebDocumentViewer Controls 如何:访问 ASPx 文档查看器和 ASPxWeb 文档查看器控件
    How to: Add a Custom Column to the Reports List 如何:将自定义列添加到报表列表
    How to: Access the ReportViewer Control 如何:访问报表查看器控件
    How to: Access the Report Parameters Object in Report Scripts 如何:访问报表脚本中的报表参数对象
    How to: Customize the Report Export Options 操作:自定义报表导出选项
    How to: Customize the WinForms Report Designer Form 如何:自定义 WinForms 报表设计器窗体
    How to: Implement a Property Editor Using a DevExpress WinForms Control 如何:使用 DevExpress WinForms 控件实现属性编辑器
  • 原文地址:https://www.cnblogs.com/wenquanli/p/10278274.html
Copyright © 2011-2022 走看看