码迷,mamicode.com
首页 > 其他好文 > 详细

针对mdadm的RAID1失效测试

时间:2018-10-03 00:24:30      阅读:471      评论:0      收藏:0      [点我收藏+]

标签:mon   gnu   home   des   create   extend   byte   字节   sector   

背景

对软RAID(mdadm)方式进行各个场景失效测试。

一、初始信息

内核版本:

root@omv30:~# uname -a
Linux omv30 4.18.0-0.bpo.1-amd64 #1 SMP Debian 4.18.6-1~bpo9+1 (2018-09-13) x86_64 GNU/Linux

使用omv创建RAID1之后,查询sdb的信息,此时sdb对应的是8ac693c5的UUID,device号为1:

root@omv30:~# mdadm --query /dev/sdb
/dev/sdb: is not an md array
/dev/sdb: device 1 in 2 device undetected raid1 /dev/md0.  Use mdadm --examine for more detail.
root@omv30:~# mdadm --examine /dev/sdb
/dev/sdb:
          Magic : a92b4efc
        Version : 1.2
    Feature Map : 0x0
     Array UUID : 921a8946:b273e00e:3fa4b99d:040a4437
           Name : omv30:raid1  (local to host omv30)
  Creation Time : Sun Sep 30 22:31:39 2018
     Raid Level : raid1
   Raid Devices : 2

 Avail Dev Size : 2095104 (1023.00 MiB 1072.69 MB)
     Array Size : 1047552 (1023.00 MiB 1072.69 MB)
    Data Offset : 2048 sectors
   Super Offset : 8 sectors
   Unused Space : before=1960 sectors, after=0 sectors
          State : clean
    Device UUID : 64a58fb5:c7e76b1a:29453878:8ac693c5

    Update Time : Mon Oct  1 13:20:56 2018
  Bad Block Log : 512 entries available at offset 72 sectors
       Checksum : 2e1fb65b - correct
         Events : 21


   Device Role : Active device 1
   Array State : AA (‘A‘ == active, ‘.‘ == missing, ‘R‘ == replacing)
root@omv30:~# mdadm -D /dev/md0 
/dev/md0:
        Version : 1.2
  Creation Time : Sun Sep 30 22:31:39 2018
     Raid Level : raid1
     Array Size : 1047552 (1023.00 MiB 1072.69 MB)
  Used Dev Size : 1047552 (1023.00 MiB 1072.69 MB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

    Update Time : Mon Oct  1 19:46:42 2018
          State : clean 
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

           Name : omv30:raid1  (local to host omv30)
           UUID : 921a8946:b273e00e:3fa4b99d:040a4437
         Events : 25

    Number   Major   Minor   RaidDevice State
       0       8       32        0      active sync   /dev/sdc
       1       8       16        1      active sync   /dev/sdb

配置文件信息:

root@omv30:~# cat /etc/mdadm/mdadm.conf 
# mdadm.conf
#
# Please refer to mdadm.conf(5) for information about this file.
#

# by default, scan all partitions (/proc/partitions) for MD superblocks.
# alternatively, specify devices to scan, using wildcards if desired.
# Note, if no DEVICE line is present, then "DEVICE partitions" is assumed.
# To avoid the auto-assembly of RAID devices a pattern that CAN‘T match is
# used if no RAID devices are configured.
DEVICE partitions

# auto-create devices with Debian standard permissions
CREATE owner=root group=disk mode=0660 auto=yes

# automatically tag new arrays as belonging to the local system
HOMEHOST <system>

# definitions of existing MD arrays
ARRAY /dev/md0 metadata=1.2 name=omv30:raid1 UUID=921a8946:b273e00e:3fa4b99d:040a4437

二、盘符错乱测试

1、盘符交换测试

在VirtualBox的存储-SATA下,分别选中两块硬盘,在右边的属性将SATA端口调换位置,即可交换盘符。

root@omv30:~# mdadm -D /dev/md0 
/dev/md0:
        Version : 1.2
  Creation Time : Sun Sep 30 22:31:39 2018
     Raid Level : raid1
     Array Size : 1047552 (1023.00 MiB 1072.69 MB)
  Used Dev Size : 1047552 (1023.00 MiB 1072.69 MB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

    Update Time : Mon Oct  1 19:52:46 2018
          State : clean 
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

           Name : omv30:raid1  (local to host omv30)
           UUID : 921a8946:b273e00e:3fa4b99d:040a4437
         Events : 29

    Number   Major   Minor   RaidDevice State
       0       8       16        0      active sync   /dev/sdb
       1       8       32        1      active sync   /dev/sdc

可以看到盘符已经换了。

root@omv30:~# mdadm --examine /dev/sdb
/dev/sdb:
          Magic : a92b4efc
        Version : 1.2
    Feature Map : 0x0
     Array UUID : 921a8946:b273e00e:3fa4b99d:040a4437
           Name : omv30:raid1  (local to host omv30)
  Creation Time : Sun Sep 30 22:31:39 2018
     Raid Level : raid1
   Raid Devices : 2

 Avail Dev Size : 2095104 (1023.00 MiB 1072.69 MB)
     Array Size : 1047552 (1023.00 MiB 1072.69 MB)
    Data Offset : 2048 sectors
   Super Offset : 8 sectors
   Unused Space : before=1960 sectors, after=0 sectors
          State : clean
    Device UUID : 6e545465:3dcf10df:1d5bb938:fe840307

    Update Time : Mon Oct  1 19:52:46 2018
  Bad Block Log : 512 entries available at offset 72 sectors
       Checksum : a47a7d1f - correct
         Events : 29


   Device Role : Active device 0
   Array State : AA (‘A‘ == active, ‘.‘ == missing, ‘R‘ == replacing)
root@omv30:~# cat /proc/mdstat
Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10] 
md0 : active (auto-read-only) raid1 sdb[0] sdc[1]
      1047552 blocks super 1.2 [2/2] [UU]
      
unused devices: <none>
root@omv30:~# fdisk -l
...(省略)

Disk /dev/md0: 1023 MiB, 1072693248 bytes, 2095104 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

mount后访问正常。

2、更换硬盘位置测试

关机,新增一块硬盘,占用原来sdc的位置,启动:

root@omv30:~# mdadm -D /dev/md0 
/dev/md0:
        Version : 1.2
  Creation Time : Sun Sep 30 22:31:39 2018
     Raid Level : raid1
     Array Size : 1047552 (1023.00 MiB 1072.69 MB)
  Used Dev Size : 1047552 (1023.00 MiB 1072.69 MB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

    Update Time : Mon Oct  1 19:52:46 2018
          State : clean 
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

           Name : omv30:raid1  (local to host omv30)
           UUID : 921a8946:b273e00e:3fa4b99d:040a4437
         Events : 29

    Number   Major   Minor   RaidDevice State
       0       8       16        0      active sync   /dev/sdb
       1       8       48        1      active sync   /dev/sdd
root@omv30:~# cat /proc/mdstat
Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10] 
md0 : active (auto-read-only) raid1 sdb[0] sdd[1]
      1047552 blocks super 1.2 [2/2] [UU]
      
unused devices: <none>

原来的sdc变成了sdc,raid1还完好保存,不受影响。

3、移除硬盘测试

关机,然后移除一块硬盘,启动:

root@omv30:~# mdadm -D /dev/md0 
/dev/md0:
        Version : 1.2
     Raid Level : raid0
  Total Devices : 1
    Persistence : Superblock is persistent

          State : inactive

           Name : omv30:raid1  (local to host omv30)
           UUID : 921a8946:b273e00e:3fa4b99d:040a4437
         Events : 29

    Number   Major   Minor   RaidDevice

       -       8       16        -        /dev/sdb
root@omv30:~# mdadm --query /dev/sdb
/dev/sdb: is not an md array
/dev/sdb: device 0 in 2 device undetected raid1 /dev/md0.  Use mdadm --examine for more detail.
root@omv30:~# mdadm --examine /dev/sdb
/dev/sdb:
          Magic : a92b4efc
        Version : 1.2
    Feature Map : 0x0
     Array UUID : 921a8946:b273e00e:3fa4b99d:040a4437
           Name : omv30:raid1  (local to host omv30)
  Creation Time : Sun Sep 30 22:31:39 2018
     Raid Level : raid1
   Raid Devices : 2

 Avail Dev Size : 2095104 (1023.00 MiB 1072.69 MB)
     Array Size : 1047552 (1023.00 MiB 1072.69 MB)
    Data Offset : 2048 sectors
   Super Offset : 8 sectors
   Unused Space : before=1960 sectors, after=0 sectors
          State : clean
    Device UUID : 6e545465:3dcf10df:1d5bb938:fe840307

    Update Time : Mon Oct  1 19:52:46 2018
  Bad Block Log : 512 entries available at offset 72 sectors
       Checksum : a47a7d1f - correct
         Events : 29


   Device Role : Active device 0
   Array State : AA (‘A‘ == active, ‘.‘ == missing, ‘R‘ == replacing)
root@omv30:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10] 
md0 : inactive sdb[0](S)
      1047552 blocks super 1.2
       
unused devices: <none>
root@omv30:~# fdisk -l
Disk /dev/sda: 8 GiB, 8589934592 bytes, 16777216 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x8c9b0fb9

Device     Boot    Start      End  Sectors Size Id Type
/dev/sda1  *        2048 12582911 12580864   6G 83 Linux
/dev/sda2       12584958 16775167  4190210   2G  5 Extended
/dev/sda5       12584960 16775167  4190208   2G 82 Linux swap / Solaris


Disk /dev/sdb: 1 GiB, 1073741824 bytes, 2097152 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

raid1变成了inactive,但raid信息本身是保存在磁盘中,不会丢失。

4、结论

  • mdadm不是根据盘符/dev/sdx来记录RAID信息的,盘符无论怎么变换,RAID信息不错乱。
  • mdadm是使用Device UUID来区分硬盘的。与RAID硬盘盒不一样,硬盘盒是记录硬盘槽位号的。
  • 所以mdadm每个硬盘可以使用任意硬盘盒,不用记录位置。

三、RAID降级恢复测试

场景:正常运行的RAID1,突然一块盘失效,进行重建恢复。
方法:可以用模拟fail的方式,也可以用VirtualBox热插拔硬盘的功能。

1、模拟fail的方式

初始信息如下:

root@omv30:~# mdadm -D /dev/md0 
/dev/md0:
        Version : 1.2
  Creation Time : Sun Sep 30 22:31:39 2018
     Raid Level : raid1
     Array Size : 1047552 (1023.00 MiB 1072.69 MB)
  Used Dev Size : 1047552 (1023.00 MiB 1072.69 MB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

    Update Time : Mon Oct  1 20:29:44 2018
          State : clean 
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

           Name : omv30:raid1  (local to host omv30)
           UUID : 921a8946:b273e00e:3fa4b99d:040a4437
         Events : 31

    Number   Major   Minor   RaidDevice State
       0       8       16        0      active sync   /dev/sdb
       1       8       48        1      active sync   /dev/sdd

(1)手工fail掉sdd:

root@omv30:~# mdadm /dev/md0 --fail /dev/sdd
mdadm: set /dev/sdd faulty in /dev/md0
root@omv30:~# mdadm -D /dev/md0 
/dev/md0:
        Version : 1.2
  Creation Time : Sun Sep 30 22:31:39 2018
     Raid Level : raid1
     Array Size : 1047552 (1023.00 MiB 1072.69 MB)
  Used Dev Size : 1047552 (1023.00 MiB 1072.69 MB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

    Update Time : Mon Oct  1 20:29:59 2018
          State : clean, degraded 
 Active Devices : 1
Working Devices : 1
 Failed Devices : 1
  Spare Devices : 0

           Name : omv30:raid1  (local to host omv30)
           UUID : 921a8946:b273e00e:3fa4b99d:040a4437
         Events : 33

    Number   Major   Minor   RaidDevice State
       0       8       16        0      active sync   /dev/sdb
       -       0        0        1      removed

       1       8       48        -      faulty   /dev/sdd

如果未移除,要先移除损坏的硬盘:

root@omv30:~# mdadm /dev/md0 -r /dev/sdd
mdadm: hot remove failed for /dev/sdd: No such device or address

(2)增加新盘:

root@omv30:~# mdadm /dev/md0 --add /dev/sdc   (新加的盘是2G的,经实测不影响RAID1重建)
mdadm: added /dev/sdc
root@omv30:~# mdadm -D /dev/md0 
/dev/md0:
        Version : 1.2
  Creation Time : Sun Sep 30 22:31:39 2018
     Raid Level : raid1
     Array Size : 1047552 (1023.00 MiB 1072.69 MB)
  Used Dev Size : 1047552 (1023.00 MiB 1072.69 MB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

    Update Time : Mon Oct  1 20:36:22 2018
          State : clean, degraded, recovering 
 Active Devices : 1
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 1

 Rebuild Status : 76% complete

           Name : omv30:raid1  (local to host omv30)
           UUID : 921a8946:b273e00e:3fa4b99d:040a4437
         Events : 48

    Number   Major   Minor   RaidDevice State
       0       8       16        0      active sync   /dev/sdb
       2       8       32        1      spare rebuilding   /dev/sdc

可以看到正在重建。
过一会儿再执行:

root@omv30:~# mdadm -D /dev/md0 
/dev/md0:
        Version : 1.2
  Creation Time : Sun Sep 30 22:31:39 2018
     Raid Level : raid1
     Array Size : 1047552 (1023.00 MiB 1072.69 MB)
  Used Dev Size : 1047552 (1023.00 MiB 1072.69 MB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

    Update Time : Mon Oct  1 20:36:24 2018
          State : clean 
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

           Name : omv30:raid1  (local to host omv30)
           UUID : 921a8946:b273e00e:3fa4b99d:040a4437
         Events : 53

    Number   Major   Minor   RaidDevice State
       0       8       16        0      active sync   /dev/sdb
       2       8       32        1      active sync   /dev/sdc
root@omv30:~# cat /proc/mdstat
Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10] 
md0 : active raid1 sdc[2] sdb[0]
      1047552 blocks super 1.2 [2/2] [UU]
      
unused devices: <none>

已经重建成功。

2、热插拔硬盘测试

在VirtualBox的存储中,勾选sdb的热插拔,然后启动。
系统在运行时,到VirtualBox的存储中移除sdb硬盘,然后查看状态:

root@omv30:~# mdadm -D /dev/md0 
/dev/md0:
        Version : 1.2
  Creation Time : Sun Sep 30 22:31:39 2018
     Raid Level : raid1
     Array Size : 1047552 (1023.00 MiB 1072.69 MB)
  Used Dev Size : 1047552 (1023.00 MiB 1072.69 MB)
   Raid Devices : 2
  Total Devices : 1
    Persistence : Superblock is persistent

    Update Time : Mon Oct  1 21:13:45 2018
          State : clean, degraded 
 Active Devices : 1
Working Devices : 1
 Failed Devices : 0
  Spare Devices : 0

           Name : omv30:raid1  (local to host omv30)
           UUID : 921a8946:b273e00e:3fa4b99d:040a4437
         Events : 56

    Number   Major   Minor   RaidDevice State
       -       0        0        0      removed
       2       8       32        1      active sync   /dev/sdc

查看系统日志,发现有硬盘离线,并且RAID1降级(有日志跟踪是软RAID的一个优势):

root@omv30:/var/log# dmesg | tail -20
[  340.551533] md: recovery of RAID array md0
[  345.881625] md: md0: recovery done.
[  657.932091] EXT4-fs (md0): mounted filesystem with ordered data mode. Opts: (null)
[ 2571.324851] ata2: SATA link down (SStatus 0 SControl 300)
[ 2576.667851] ata2: SATA link down (SStatus 0 SControl 300)
[ 2582.044796] ata2: SATA link down (SStatus 0 SControl 300)
[ 2582.044864] ata2.00: disabled
[ 2582.045573] ata2.00: detaching (SCSI 3:0:0:0)
[ 2582.058467] sd 3:0:0:0: [sdb] Synchronizing SCSI cache
[ 2582.058528] sd 3:0:0:0: [sdb] Synchronize Cache(10) failed: Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK
[ 2582.058536] sd 3:0:0:0: [sdb] Stopping disk
[ 2582.058552] sd 3:0:0:0: [sdb] Start/Stop Unit failed: Result: hostbyte=DID_BAD_TARGET driverbyte=DRIVER_OK
[ 2586.709149] md/raid1:md0: Disk failure on sdb, disabling device.
               md/raid1:md0: Operation continuing on 1 devices.

加入新硬盘。新加的硬盘不能比现有的小,可以比现在的大。

root@omv30:~# mdadm /dev/md0 --add /dev/sdc

开始重建:

root@omv30:~# mdadm -D /dev/md0 
/dev/md0:
        Version : 1.2
  Creation Time : Sun Sep 30 22:31:39 2018
     Raid Level : raid1
     Array Size : 1047552 (1023.00 MiB 1072.69 MB)
  Used Dev Size : 1047552 (1023.00 MiB 1072.69 MB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

    Update Time : Mon Oct  1 21:38:36 2018
          State : clean, degraded, recovering 
 Active Devices : 1
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 1

 Rebuild Status : 56% complete

           Name : omv30:raid1  (local to host omv30)
           UUID : 921a8946:b273e00e:3fa4b99d:040a4437
         Events : 69

    Number   Major   Minor   RaidDevice State
       3       8       32        0      spare rebuilding   /dev/sdc
       2       8       16        1      active sync   /dev/sdb
root@omv30:~# cat /proc/mdstat 
Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10] 
md0 : active raid1 sdc[3] sdb[2]
      1047552 blocks super 1.2 [2/1] [_U]
      [===================>.]  recovery = 95.0% (996288/1047552) finish=0.0min speed=249072K/sec
      
unused devices: <none>

重建完成:

root@omv30:~# mdadm -D /dev/md0 
/dev/md0:
        Version : 1.2
  Creation Time : Sun Sep 30 22:31:39 2018
     Raid Level : raid1
     Array Size : 1047552 (1023.00 MiB 1072.69 MB)
  Used Dev Size : 1047552 (1023.00 MiB 1072.69 MB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

    Update Time : Mon Oct  1 21:38:39 2018
          State : clean 
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

           Name : omv30:raid1  (local to host omv30)
           UUID : 921a8946:b273e00e:3fa4b99d:040a4437
         Events : 78

    Number   Major   Minor   RaidDevice State
       3       8       32        0      active sync   /dev/sdc
       2       8       16        1      active sync   /dev/sdb
root@omv30:~# cat /proc/mdstat 
Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10] 
md0 : active raid1 sdc[3] sdb[2]
      1047552 blocks super 1.2 [2/2] [UU]
      
unused devices: <none>

四、重装系统恢复RAID1测试

1、RAID1两块硬盘正常

将两块硬盘挂到一个新装的ubuntu中,启动。

root@UB13:/home/op# fdisk -l
...(省略)

Disk /dev/md127:1023 MiB,1072693248 字节,2095104 个扇区
单元:扇区 / 1 * 512 = 512 字节
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
root@UB13:/home/op# cat /proc/mdstat 
Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10] 
md127 : active raid1 sdd[1] sdc[0]
      1047552 blocks super 1.2 [2/2] [UU]
      
unused devices: <none>

可以看到,自动识别出来/dev/md127。

root@UB13:/mnt/md# mdadm -D /dev/md127
/dev/md127:
           Version : 1.2
     Creation Time : Sun Sep 30 22:31:39 2018
        Raid Level : raid1
        Array Size : 1047552 (1023.00 MiB 1072.69 MB)
     Used Dev Size : 1047552 (1023.00 MiB 1072.69 MB)
      Raid Devices : 2
     Total Devices : 2
       Persistence : Superblock is persistent

       Update Time : Mon Oct  1 19:31:08 2018
             State : clean 
    Active Devices : 2
   Working Devices : 2
    Failed Devices : 0
     Spare Devices : 0

Consistency Policy : resync

              Name : omv30:raid1
              UUID : 921a8946:b273e00e:3fa4b99d:040a4437
            Events : 25

    Number   Major   Minor   RaidDevice State
       0       8       32        0      active sync   /dev/sdc
       1       8       48        1      active sync   /dev/sdd

系统自动识别并恢复了RAID1,不用执行mdadm --assemble --scan。
查看/etc/mdadm/mdadm.conf,也是自动加入了md信息。
mount后访问正常。

至于如何将md127修改成md0,详见下一节。

2、RAID1损坏了一块硬盘

只有一块硬盘可用,需要在新系统上重建RAID1。

root@op:/home/op# fdisk -l
(未发现新的md设备,略去详细输出)
root@op:/home/op# mdadm --examine /dev/sdb 
/dev/sdb:
          Magic : a92b4efc
        Version : 1.2
    Feature Map : 0x0
     Array UUID : 921a8946:b273e00e:3fa4b99d:040a4437
           Name : omv30:raid1
  Creation Time : Sun Sep 30 22:31:39 2018
     Raid Level : raid1
   Raid Devices : 2

 Avail Dev Size : 4192256 (2047.00 MiB 2146.44 MB)
     Array Size : 1047552 (1023.00 MiB 1072.69 MB)
  Used Dev Size : 2095104 (1023.00 MiB 1072.69 MB)
    Data Offset : 2048 sectors
   Super Offset : 8 sectors
   Unused Space : before=1960 sectors, after=2097152 sectors
          State : clean
    Device UUID : 6e2fc709:35a8f6fb:d4c0e242:6905437d

    Update Time : Mon Oct  1 21:40:25 2018
  Bad Block Log : 512 entries available at offset 72 sectors
       Checksum : e65b30a8 - correct
         Events : 78


   Device Role : Active device 1
   Array State : AA (‘A‘ == active, ‘.‘ == missing, ‘R‘ == replacing)
root@op:/home/op# cat /proc/mdstat 
Personalities : 
unused devices: <none>

说明新挂载的盘RAID1信息犹在,只需要重新识别:

root@op:/home/op# mdadm --assemble --scan
mdadm: /dev/md/raid1 has been started with 1 drive (out of 2).
root@op:/home/op# fdisk -l
...(省略)

Disk /dev/md127:1023 MiB,1072693248 字节,2095104 个扇区
单元:扇区 / 1 * 512 = 512 字节
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
root@op:/home/op# mdadm -D /dev/md127
/dev/md127:
           Version : 1.2
     Creation Time : Sun Sep 30 22:31:39 2018
        Raid Level : raid1
        Array Size : 1047552 (1023.00 MiB 1072.69 MB)
     Used Dev Size : 1047552 (1023.00 MiB 1072.69 MB)
      Raid Devices : 2
     Total Devices : 1
       Persistence : Superblock is persistent

       Update Time : Mon Oct  1 21:40:25 2018
             State : clean, degraded 
    Active Devices : 1
   Working Devices : 1
    Failed Devices : 0
     Spare Devices : 0

Consistency Policy : resync

              Name : omv30:raid1
              UUID : 921a8946:b273e00e:3fa4b99d:040a4437
            Events : 78

    Number   Major   Minor   RaidDevice State
       -       0        0        0      removed
       2       8       16        1      active sync   /dev/sdb

如果这个时间重启系统,会发现fdisk -l中没有md127了。并且mdadm -D发现RAID1处于inactive。

root@op:/home/op# mdadm -D /dev/md127
/dev/md127:
           Version : 1.2
        Raid Level : raid0
     Total Devices : 1
       Persistence : Superblock is persistent

             State : inactive
   Working Devices : 1

              Name : omv30:raid1
              UUID : 921a8946:b273e00e:3fa4b99d:040a4437
            Events : 78

    Number   Major   Minor   RaidDevice

       -       8       16        -        /dev/sdb

这时需要先mdadm -S /dev/md127删除旧的md127,
再重新mdadm --assemble --scan。
再add硬盘,完成重建即可。

root@omv30:~# mdadm /dev/md0 --add /dev/sdc

这时再重启也不会有影响,唯一的变化就是在之前主机是md0,现在变成了md127了。
解决方法:
修改/etc/mdadm/mdadm.conf,
把第二列:/dev/md/raid1
修改成:/dev/md0

再执行:

update-initramfs -u

重启,搞定。

五、常用命令

查看状态

mdadm -D /dev/md0
cat /proc/mdstat
mdadm --examine /dev/sdb

删除md

mdadm -S /dev/md0

激活md

mdadm -A /dev/md0

在新OS上重新导入raid

mdadm --assemble --scan

重建

mdadm /dev/md0 --add /dev/sdc

针对mdadm的RAID1失效测试

标签:mon   gnu   home   des   create   extend   byte   字节   sector   

原文地址:https://www.cnblogs.com/felix-zp/p/9738724.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!