Software RAID 구성 (mdadm)

■ RAID-0 대상 디스크 (RAID Level: https://namu.wiki/w/RAID)
/dev/sdb 500GB
/dev/sdc 500GB

1.mdadm 설치
  yum -y install mdadm
  apt -y install mdadm


2.대상 디스크 파티션 삭제
  dd if=/dev/zero of=/dev/sdb bs=1024 count=1
  dd if=/dev/zero of=/dev/sdc bs=1024 count=1

3.RAID 타입으로 파티셔닝
  # fdisk /dev/sdb (같은 방법으로 sdc도 파티셔닝)

    Welcome to fdisk (util-linux 2.32.1).
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.

    Device does not contain a recognized partition table.
    Created a new DOS disklabel with disk identifier 0x5e7f68d2.

    Command (m for help): n
    Partition type
       p   primary (0 primary, 0 extended, 4 free)
       e   extended (container for logical partitions)
    Select (default p): p
    Partition number (1-4, default 1):
    First sector (2048-976773167, default 2048):
    Last sector, +sectors or +size{K,M,G,T,P} (2048-976773167, default 976773167):

    Created a new partition 1 of type 'Linux' and of size 465.8 GiB.
    Partition #1 contains a ext4 signature.

    Do you want to remove the signature? [Y]es/[N]o: Y

    The signature will be removed by a write command.

    Command (m for help): t
    Selected partition 1
    Hex code (type L to list all codes): fd
    Changed type of partition 'Linux' to 'Linux raid autodetect'.

    Command (m for help): p
    Disk /dev/sdb: 465.8 GiB, 500107862016 bytes, 976773168 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: 0x5e7f68d2

    Device     Boot Start       End   Sectors   Size Id Type
    /dev/sdb1        2048 976773167 976771120 465.8G fd Linux raid autodetect

    Filesystem/RAID signature on partition 1 will be wiped.

    Command (m for help): w
    The partition table has been altered.
    Calling ioctl() to re-read partition table.
    Syncing disks.

4.변경사항 확인
  # mdadm -E /dev/sd[b-c]
    /dev/sdb:
       MBR Magic : aa55
    Partition[0] :    976771120 sectors at         2048 (type fd)
    /dev/sdc:
       MBR Magic : aa55
    Partition[0] :    976771120 sectors at         2048 (type fd)

  # mdadm -E /dev/sd[b-c]1
    mdadm: No md superblock detected on /dev/sdb1.
    mdadm: No md superblock detected on /dev/sdc1.

5.RAID 장치 생성
  # mdadm --create /dev/md0 --level=0 --raid-devices=2 /dev/sdb1 /dev/sdc1
    mdadm: Note: this array has metadata at the start and
        may not be suitable as a boot device.  If you plan to
        store '/boot' on this device please ensure that
        your boot-loader understands md/v1.x metadata, or use
        --metadata=0.90
    Continue creating array? y
    mdadm: Defaulting to version 1.2 metadata
    mdadm: array /dev/md0 started.
    # cat /proc/mdstat
    Personalities : [raid1]
    md0 : active raid1 sdc1[1] sdb1[0]
          488253440 blocks super 1.2 [2/2] [UU]
          [>....................]  resync =  0.1% (605696/488253440) finish=107.3min speed=75712K/sec
          bitmap: 4/4 pages [16KB], 65536KB chunk

    unused devices: <none>

6.RAID 장치 생성 확인
  # mdadm -E /dev/sd[b-c]1
    /dev/sdb1:
              Magic : a92b4efc
            Version : 1.2
        Feature Map : 0x1
         Array UUID : 0fe62843:e7d9d0e8:56b5b49a:69682d79
               Name : db:0  (local to host db)
      Creation Time : Sat Jun  1 04:09:43 2024
         Raid Level : raid1
       Raid Devices : 2

     Avail Dev Size : 976506928 sectors (465.63 GiB 499.97 GB)
         Array Size : 488253440 KiB (465.63 GiB 499.97 GB)
      Used Dev Size : 976506880 sectors (465.63 GiB 499.97 GB)
        Data Offset : 264192 sectors
       Super Offset : 8 sectors
       Unused Space : before=264112 sectors, after=48 sectors
              State : active
        Device UUID : 2fe4cb6b:c2be29d8:96db5e70:ce4628fa

    Internal Bitmap : 8 sectors from superblock
        Update Time : Sat Jun  1 04:10:48 2024
      Bad Block Log : 512 entries available at offset 16 sectors
           Checksum : 8e9ac22 - correct
             Events : 13


       Device Role : Active device 0
       Array State : AA ('A' == active, '.' == missing, 'R' == replacing)
    /dev/sdc1:
              Magic : a92b4efc
            Version : 1.2
        Feature Map : 0x1
         Array UUID : 0fe62843:e7d9d0e8:56b5b49a:69682d79
               Name : db:0  (local to host db)
      Creation Time : Sat Jun  1 04:09:43 2024
         Raid Level : raid1
       Raid Devices : 2

     Avail Dev Size : 976506928 sectors (465.63 GiB 499.97 GB)
         Array Size : 488253440 KiB (465.63 GiB 499.97 GB)
      Used Dev Size : 976506880 sectors (465.63 GiB 499.97 GB)
        Data Offset : 264192 sectors
       Super Offset : 8 sectors
       Unused Space : before=264112 sectors, after=48 sectors
              State : active
        Device UUID : bb646c05:8a3ebe24:2b3cfce6:c92a7010

    Internal Bitmap : 8 sectors from superblock
        Update Time : Sat Jun  1 04:10:48 2024
      Bad Block Log : 512 entries available at offset 16 sectors
           Checksum : 7c03f105 - correct
             Events : 13


       Device Role : Active device 1
       Array State : AA ('A' == active, '.' == missing, 'R' == replacing)

  자세하게 상태 체크
  # mdadm --detail /dev/md0
    /dev/md0:
               Version : 1.2
         Creation Time : Sat Jun  1 04:09:43 2024
            Raid Level : raid1
            Array Size : 488253440 (465.63 GiB 499.97 GB)
         Used Dev Size : 488253440 (465.63 GiB 499.97 GB)
          Raid Devices : 2
         Total Devices : 2
           Persistence : Superblock is persistent

         Intent Bitmap : Internal

           Update Time : Sat Jun  1 04:11:08 2024
                 State : clean, resyncing
        Active Devices : 2
       Working Devices : 2
        Failed Devices : 0
         Spare Devices : 0

    Consistency Policy : bitmap

         Resync Status : 1% complete

                  Name : db:0  (local to host db)
                  UUID : 0fe62843:e7d9d0e8:56b5b49a:69682d79
                Events : 17

        Number   Major   Minor   RaidDevice State
           0       8       17        0      active sync   /dev/sdb1
           1       8       33        1      active sync   /dev/sdc1

  간단하게 상태 체크
  # mdadm --query /dev/md0

7. 디스크 포맷
  # mkfs -t ext4 /dev/md0

8.fstab 추가
  # vi /etc/fstab
  /dev/md0 /mnt/md0 ext4 defaults 1 2

9. RAID 시작과 중지
  mdadm --run /dev/md0
  mdadm --stop /dev/md0
위로 스크롤