mdadmで2台のRAID1から3台のRAID5に変換する

OS : Ubuntu 18.04

現在、ソフトウェアRAIDのmdadmを使って2TBのSSD2台でRAID1を組んでいる。

ここにSSDを1台追加し、RAID5に変換してみる。

まずは状態の確認。

$ sudo mdadm -D /dev/md0
/dev/md0:
           Version : 1.2
     Creation Time : Tue Aug 20 12:48:38 2019
        Raid Level : raid1
        Array Size : 1953381376 (1862.89 GiB 2000.26 GB)
     Used Dev Size : 1953381376 (1862.89 GiB 2000.26 GB)
      Raid Devices : 2
     Total Devices : 2
       Persistence : Superblock is persistent

     Intent Bitmap : Internal

       Update Time : Fri Jan 24 09:23:16 2020
             State : clean
    Active Devices : 2
   Working Devices : 2
    Failed Devices : 0
     Spare Devices : 0

Consistency Policy : bitmap

              Name : hoge:0
              UUID : e8d83f0f:f1411b0f:424916f5:4e7e31c6
            Events : 11779

    Number   Major   Minor   RaidDevice State
       2       8       17        0      active sync   /dev/sdb1
       1       8        1        1      active sync   /dev/sda1

/dev/sdaと/dev/sdbの2台でRAID1が組まれているのがわかる。

ここからRAID5に変更するには、–addで新しいディスクを追加し、–growでRAID5に更新すればいい。

$ sudo mdadm --add /dev/md0 /dev/sdd
mdadm: added /dev/sdd

$ sudo mdadm -D /dev/md0
/dev/md0:
           Version : 1.2
     Creation Time : Tue Aug 20 12:48:38 2019
        Raid Level : raid1
        Array Size : 1953381376 (1862.89 GiB 2000.26 GB)
     Used Dev Size : 1953381376 (1862.89 GiB 2000.26 GB)
      Raid Devices : 2
     Total Devices : 3
       Persistence : Superblock is persistent

     Intent Bitmap : Internal

       Update Time : Mon Jan 27 14:49:39 2020
             State : clean
    Active Devices : 2
   Working Devices : 3
    Failed Devices : 0
     Spare Devices : 1

Consistency Policy : bitmap

              Name : hoge:0
              UUID : e8d83f0f:f1411b0f:424916f5:4e7e31c6
            Events : 11780

    Number   Major   Minor   RaidDevice State
       2       8       17        0      active sync   /dev/sdb1
       1       8        1        1      active sync   /dev/sda1

       3       8       48        -      spare   /dev/sdd

新たに追加した/dev/sddがspareとして認識された。

$ sudo mdadm --grow /dev/md0 --level=raid5 --raid-devices=3
mdadm: level of /dev/md0 changed to raid5

$ sudo mdadm -D /dev/md0
/dev/md0:
           Version : 1.2
     Creation Time : Tue Aug 20 12:48:38 2019
        Raid Level : raid5
        Array Size : 1953381376 (1862.89 GiB 2000.26 GB)
     Used Dev Size : 1953381376 (1862.89 GiB 2000.26 GB)
      Raid Devices : 3
     Total Devices : 3
       Persistence : Superblock is persistent

     Intent Bitmap : Internal

       Update Time : Mon Jan 27 14:51:09 2020
             State : clean, reshaping
    Active Devices : 3
   Working Devices : 3
    Failed Devices : 0
     Spare Devices : 0

            Layout : left-symmetric
        Chunk Size : 64K

Consistency Policy : bitmap

    Reshape Status : 0% complete
     Delta Devices : 1, (2->3)

              Name : hoge:0
              UUID : e8d83f0f:f1411b0f:424916f5:4e7e31c6
            Events : 11799

    Number   Major   Minor   RaidDevice State
       2       8       17        0      active sync   /dev/sdb1
       1       8        1        1      active sync   /dev/sda1
       3       8       48        2      active sync   /dev/sdd

Raid Levelがraid5、Raid DevicesとTotal Devicesが3になった。

RAID5にしたことで、ディスクの変換が行われる。

$ cat /proc/mdstat
Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10]
md0 : active raid5 sdd[3] sdb1[2] sda1[1]
      1953381376 blocks super 1.2 level 5, 64k chunk, algorithm 2 [3/3] [UUU]
      [>....................]  reshape =  0.0% (685760/1953381376) finish=284.7min speed=114293K/sec
      bitmap: 0/15 pages [0KB], 65536KB chunk

2TBのSSDを1台追加し、RAID1からRAID5にすると約284分(4.7時間)かかる様子。

reshapeが終わったら状態を再確認。

sudo mdadm -D /dev/md0
/dev/md0:
           Version : 1.2
     Creation Time : Tue Aug 20 12:48:38 2019
        Raid Level : raid5
        Array Size : 3906762752 (3725.78 GiB 4000.53 GB)
     Used Dev Size : 1953381376 (1862.89 GiB 2000.26 GB)
      Raid Devices : 3
     Total Devices : 3
       Persistence : Superblock is persistent

     Intent Bitmap : Internal

       Update Time : Mon Jan 27 18:35:18 2020
             State : clean
    Active Devices : 3
   Working Devices : 3
    Failed Devices : 0
     Spare Devices : 0

            Layout : left-symmetric
        Chunk Size : 64K

Consistency Policy : bitmap

              Name : hoge:0
              UUID : e8d83f0f:f1411b0f:424916f5:4e7e31c6
            Events : 13128

    Number   Major   Minor   RaidDevice State
       2       8       17        0      active sync   /dev/sdb1
       1       8        1        1      active sync   /dev/sda1
       3       8       48        2      active sync   /dev/sdd

Stateがcleanで、Array Sizeも4TBになっており、無事に処理が終わった様子。

Remark for Raid5/6: You will realize that (checking with ‘df’) the size of your array has not changed. If you added one 1TB drive to your existing 3-1TB-drive-array mdadm will not automatically add the new 1TB of space. Mdadm will just spread the old 3TB-array over 4 drives occupying 750GB of each drive and leaving 250GB on each drive blank. To change that, have your array unmounted and:

resize2fs

https://raid.wiki.kernel.org/index.php/Growing

RAID5にディスクを追加しても自動で容量は増えない仕様らしい。

もし上記の手順でArray Sizeが増えていなければ、書いてあるコマンドを叩くといいはず。

試しにやってみた。

$ sudo resize2fs /dev/md0
resize2fs 1.44.1 (24-Mar-2018)
Please run 'e2fsck -f /dev/md0' first.

ファイルシステムのチェックを先にしろ、と怒られた。

$ sudo e2fsck -f /dev/md0
e2fsck 1.44.1 (24-Mar-2018)
Pass 1: Checking iノードs, blocks, and sizes
Pass 2: Checking ディレクトリ structure
Pass 3: Checking ディレクトリ connectivity
Pass 4: Checking reference counts
Pass 5: Checking グループ summary information
/dev/md0: 1456414/122093568 files (0.4% non-contiguous), 415885034/488345344 blocks

もう一度、

$ sudo resize2fs /dev/md0
resize2fs 1.44.1 (24-Mar-2018)
Resizing the filesystem on /dev/md0 to 976690688 (4k) blocks.
The filesystem on /dev/md0 is now 976690688 (4k) blocks long.

最終チェック

$ sudo mdadm -D /dev/md0
/dev/md0:
           Version : 1.2
     Creation Time : Tue Aug 20 12:48:38 2019
        Raid Level : raid5
        Array Size : 3906762752 (3725.78 GiB 4000.53 GB)
     Used Dev Size : 1953381376 (1862.89 GiB 2000.26 GB)
      Raid Devices : 3
     Total Devices : 3
       Persistence : Superblock is persistent

     Intent Bitmap : Internal

       Update Time : Mon Jan 27 19:01:55 2020
             State : clean
    Active Devices : 3
   Working Devices : 3
    Failed Devices : 0
     Spare Devices : 0

            Layout : left-symmetric
        Chunk Size : 64K

Consistency Policy : bitmap

              Name : hoge:0
              UUID : e8d83f0f:f1411b0f:424916f5:4e7e31c6
            Events : 13128

    Number   Major   Minor   RaidDevice State
       2       8       17        0      active sync   /dev/sdb1
       1       8        1        1      active sync   /dev/sda1
       3       8       48        2      active sync   /dev/sdd

無事に2TBのSSD3台で、4TBのRAID5を組むことができた。

参考

Growing - Linux Raid Wiki
RAID-1 to RAID-5 using mdadm
As per subject. When converting from RAID-1 to RAID-5 using mdadm, why must a RAID 1 array contain 2 devices and not mor...
Converting RAID1 array to RAID5 using the mdadm grow command
I have finally decided to upgrade the storage in the home theatre PC, by adding a third 3TB hard drive. The storage was ...

コメント

タイトルとURLをコピーしました