상세 컨텐츠

본문 제목

10분 만에 뛰는 Ubuntu 20.04 RAID 1

DIY

by 목장주 2021. 8. 28. 14:37

본문

뜻한바 있어서 리눅스에 RAID를 설치하기로 했다. 메인보드에서 RAID를 지원하지만 막상 설정을 끝냈는데 우분투에서 제대로 잡히지가 않았다. 하드웨어 RAID를 해볼까 했는데... 시간 낭비 없이 바로 리눅스에서 제공하는 RAID 뛰러 가즈아! 

 

먼저 현재 설치된 하드를 살펴보면 다음과 같다. 

$ sudo lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
......
sda      8:0    0 238.5G  0 disk 
├─sda1   8:1    0   512M  0 part /boot/efi
├─sda2   8:2    0     1K  0 part 
└─sda5   8:5    0   238G  0 part /
sdb      8:16   0   3.7T  0 disk 
sdc      8:32   0   3.7T  0 disk

 

sda는 SSD로 리눅스가 설치되어 있다. sdb, sdc는 자료 저장용으로 새로산 4T WD 하드.

 

뜯고 바로 장착한 새 드라이드이므로 일단 파티션부터 잡아주도록 하자. 파티션은 fdisk [디바이스명] 으로 해주면 된다. 먼저 /dev/sdb부터.

 

$ sudo fdisk /dev/sdb

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 ext4 signature will be removed by a write command.

Device does not contain a recognized partition table.
The size of this disk is 3.7 TiB (4000787030016 bytes). DOS partition table format cannot be used on drives for volumes larger than 2199023255040 bytes for 512-byte sectors. Use GUID partition table format (GPT).

Created a new DOS disklabel with disk identifier 0x4ffd9590.

 

하드에 아직 아무 파티션 테이블도 없다, 하드 크기가 2T 보다 크기 때문에 DOS 파티션이 아닌 GPT를 사용하라는 문구를 볼 수 있다. 그래도 마지막 문구를 보면 일단 DOS를 생성해주긴 하는 듯 하다. 

 

하드 크기가 3.7T인데 1.7T를 낭비할 수 없으니 GPT를 생성해 주자. g 명령어를 입력하면 끝!

 

Command (m for help): g
Created a new GPT disklabel (GUID: AA89193E-3296-8241-B232-6BC121FBAB17).
The old ext4 signature will be removed by a write command.

 

그럼 이제 GPT 라벨을 생성했으니 파티션을 작성할 차례. 새로운 파티션 작성은 n 명령으를 입력하고 엔터 3번 눌러주면 끝!

 

Command (m for help): n
Partition number (1-128, default 1): 
First sector (2048-7814037134, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-7814037134, default 7814037134): 

Created a new partition 1 of type 'Linux filesystem' and of size 3.7 TiB.

 

이제 RAID를 위해 파티션 타입을 바꿔주면 된다. 명령어는 t, RAID 파티션 타입 번호는 29.

 

Command (m for help): t
Selected partition 1
Partition type (type L to list all types): L
  1 EFI System                     C12A7328-F81F-11D2-BA4B-00A0C93EC93B
  2 MBR partition scheme           024DEE41-33E7-11D3-9D69-0008C781F39F
    .........
 29 Linux RAID                     A19D880F-05FC-4D3B-A006-743F0F84911E
Partition type (type L to list all types): 29
Changed type of partition 'Linux filesystem' to 'Linux RAID'.

 

다 끝났으니 저장하면 끝. 저장은 w.

 

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

 

두 번째 하드도 똑같이 해주면 된다. 

 

HDD 2개에 대한 사전 작업은 끝났으니 이제 RAID 1로 묶어 주면 된다. RAID 설정은 mdadm으로 가능하다. 아직 설치가 안 되어 있다면 먼저 설치부터.

 

$ sudo apt install mdadm

 

mdadm으로 RAID를 생성하려면 다음과 같은 인자들을 주면 된다.

 

$ sudo mdadm --create [생성될 RAID 장치명] \
--level=[RAID 레벨] \
--raid-devices=[RAID 구성할 하드의 수] \
[하드 1] [하드 2] ... [하드 n]

 

/dev/sdb1, /dev/sdc1을 RAID 1으로 묶어서 /dev/md0이란 이름으로 만들어 주고 싶다면

 

$ sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1

 

RAID 생성은 끝났지만, 아직 HDD 포맷은 안 했다. ext4 타입으로 포맷하고 싶다면

 

$ mkfs.ext4 /dev/md0

 

RAID 1 설정이 잘 되었는지는 fdisk -l 또는 cat /proc/mdstat 명령으로 확인 가능하다. 

 

자 지금부터 확인 들어갑니다..

 

$ cat /proc/mdstat
Personalities : [raid1] 
md0 : active raid1 sdc1[1] sdb1[0]
      3906885440 blocks super 1.2 [2/2] [UU]
      [>....................]  resync =  0.1% (6839552/3906885440) finish=341.2min speed=190472K/sec
      bitmap: 30/30 pages [120KB], 65536KB chunk

unused devices: <none>

 

 

$ sudo fdisk -l
........
Disk /dev/sdc: 3.65 TiB, 4000787030016 bytes, 7814037168 sectors
Disklabel type: gpt

Device     Start        End    Sectors  Size Type
/dev/sdc1   2048 7814037134 7814035087  3.7T Linux RAID

Disk /dev/sdb: 3.65 TiB, 4000787030016 bytes, 7814037168 sectors
Disklabel type: gpt

Device     Start        End    Sectors  Size Type
/dev/sdb1   2048 7814037134 7814035087  3.7T Linux RAID

Disk /dev/md0: 3.65 TiB, 4000650690560 bytes, 7813770880 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

 

RAID를 설정했으니 mdadm.conf의 말미에 설정 결과를 추가하자.

 

$ sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf

 

생성된 RAID를 원하는 곳에 마운트해보자. /mnt/data에 마운트를 한다면 다음과 같이 마운트를 실행한다. 

 

$ sudo mount /dev/md0 /mnt/data

 

이제 부팅할 때 자동으로 마운트 하도록 /etc/fstab에 다음과 같이 추가해주면 된다.

 

/dev/md0 /mnt/data ext4 defaults 0 0

 

 

10분 만에 RAID1 완성!

 

관련글 더보기