Linux,Unix,BSD

mdadm을 이용한 RAID-1 구성하기

채윤아빠 2022. 3. 15. 08:09
728x90
반응형

회사 내부에 NAS 구성을 위하여 보드에 내장된 Intel RST RAID를 이용하여 HW RAID-1을 구성하려고 하였으나, 무엇때문인지 확인이 되지 않았지만 우분투 OS에서는 RAID-1 볼륨을 인식하지 못하였습니다. 두 개의 물리적 HDD를 하나의 RAID-1 볼륨으로 묶어 놓았는데, 우분투에서는 RAID 볼륨을 인식하 않고 각각의 HDD를 독립적으로 2개 인식하였습니다.

여러 가지 삽질을 하고 자료를 찾다 보니 굳이 HW RAID를 구성할 필요가 없다는 결론에 도달하였고, 조금 더 확장성이 좋은 SW RAID로 구성하기로 하였고, 본 문서에서 그 과정을 정리하여 둡니다.


새로 추가한 HDD를 "fdisk" 명령으로 확인합니다.

$ sudo fdisk -l
Disk /dev/sda: 1.84 TiB, 2000398934016 bytes, 3907029168 sectors
Disk model: ST2000DM006-2DM1
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/sdb: 1.84 TiB, 2000398934016 bytes, 3907029168 sectors
Disk model: ST2000DM006-2DM1
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/sdc: 476.96 GiB, 512110190592 bytes, 1000215216 sectors
Disk model: SAMSUNG MZ7LN512
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: 0x49ebdc42

Device     Boot     Start        End   Sectors   Size Id Type
/dev/sdc1  *         2048  250249215 250247168 119.3G 83 Linux
/dev/sdc2       250251262 1000214527 749963266 357.6G  5 Extended
/dev/sdc5       250251264  976812031 726560768 346.5G 83 Linux
/dev/sdc6       976814080 1000214527  23400448  11.2G 82 Linux swap / Solaris

새로 추가한 HDD 두 개 모두(/dev/sda, /dev/sdb)를 "fdisk" 명령을 이용하여, 새로운 파티션을 생성합니다.

$ sudo fdisk /dev/sda

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

The old isw_raid_member signature will be removed by a write command.

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

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): 1
First sector (2048-3907029167, default 2048): 2048
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-3907029167, default 3907029167): 3907029167

Created a new partition 1 of type 'Linux' and of size 1.8 TiB.
Partition #1 contains a isw_raid_member 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): wq
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

생성된 두 개의 파티션을 이용하여 RAID-1 볼륨 "/dev/md0"을 다음과 같이 생성합니다

$ sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1
mdadm: partition table exists on /dev/sda1
mdadm: partition table exists on /dev/sda1 but will be lost or
       meaningless after creating array
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.

위에서 "partition table exists on /dev/sda1"과 같은 문구가 나온 이유는 "/dev/sda1" 파티션을 "Linux Primary" 형식으로 만들었기 때문입니다. 이와 같은 문구가 나타나지 않도록 하기 위해서는 앞서 "fdisk" 명령으로 Primary 파티션을 생성한 후에, "t" 명령으로 파티션 형식을 "fd"로 변경하여, 파티션 형식이 "Linux raid auto"로 변경해 주어야 합니다.

생성된 RAID 볼륨 정보는 다음과 같이 확인할 수 있습니다.

$ sudo mdadm --detail --scan
ARRAY /dev/md0 metadata=1.2 name=hbesthee-ThinkStation-P500:0 UUID=c538b8c6:c4e3b404:b3a47203:21f09bc4
hbesthee@hbesthee-ThinkStation-P500:/data$ sudo mdadm --detail /dev/md0
/dev/md0:
           Version : 1.2
     Creation Time : Wed Mar 16 21:32:19 2022
        Raid Level : raid1
        Array Size : 1953381440 (1862.89 GiB 2000.26 GB)
     Used Dev Size : 1953381440 (1862.89 GiB 2000.26 GB)
      Raid Devices : 2
     Total Devices : 2
       Persistence : Superblock is persistent

     Intent Bitmap : Internal

       Update Time : Wed Mar 16 21:48:23 2022
             State : clean, resyncing
    Active Devices : 2
   Working Devices : 2
    Failed Devices : 0
     Spare Devices : 0

Consistency Policy : bitmap

     Resync Status : 9% complete

              Name : hbesthee-ThinkStation-P500:0  (local to host hbesthee-ThinkStation-P500)
              UUID : c538b8c6:c4e3b404:b3a47203:21f09bc4
            Events : 476

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

새로 생성된 RAID-1 볼륨을 을 "mkfs.ext4" 명령으로 포맷합니다.

$ mkfs.ext4 /dev/md0
mke2fs 1.45.5 (07-Jan-2020)
Creating filesystem with 488345360 4k blocks and 122093568 inodes
Filesystem UUID: 028191c7-b1aa-480e-a9e1-3292a913543d
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
        102400000, 214990848

Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks):
done
Writing superblocks and filesystem accounting information: done

새로 만들어진 파티션에 대한 UUID를 "blkid" 명령으로 확인합니다.

$ sudo blkid
/dev/sda1: UUID="c538b8c6-c4e3-b404-b3a4-720321f09bc4" UUID_SUB="ce101d54-d73d-1d0a-6acd-574491985380" LABEL="hbesthee-ThinkStation-P500:0" TYPE="linux_raid_member" PARTUUID="00a44a89-01"
/dev/sdb1: UUID="c538b8c6-c4e3-b404-b3a4-720321f09bc4" UUID_SUB="c6bd2e46-886f-900c-6cba-c965fbc72f8e" LABEL="hbesthee-ThinkStation-P500:0" TYPE="linux_raid_member" PARTUUID="a14493b7-01"
/dev/md0: UUID="028191c7-b1aa-480e-a9e1-3292a913543d" TYPE="ext4"

생성한 파티션을 "/data" 폴더로 마운트 (mount) 합니다.

$ sudo mkdir -p /data
$ sudo mount UUID="028191c7-b1aa-480e-a9e1-3292a913543d" /data
$ df -Th

"/etc/fstab" 파일에 새로 추가한 스토리지 파티션에 대하여 추가 설정을 하여, 재부팅 이후에도 새로 추가한 파티션을 사용할 수 있도록 합니다.

$ sudo vi /etc/fstab

UUID=028191c7-b1aa-480e-a9e1-3292a913543d /data ext4 defaults,nofail 0 2

참고자료