중요: 실제 시스템에서 진행하기 전에 전체 백업을 반드시 수행하세요. RAID 및 부팅 관련 작업은 실수 시 부팅 불가로 이어질 수 있습니다.
4 RAID 배열 생성
이제 /dev/md0, /dev/md1, /dev/md2 RAID 배열을 생성합니다. /dev/hdb1은 /dev/md0에, /dev/hdb5는 /dev/md1에, /dev/hdb6는 /dev/md2에 추가됩니다. 현재 시스템이 /dev/hda* 파티션에서 동작 중이므로 /dev/hda1, /dev/hda5, /dev/hda6는 즉시 추가할 수 없습니다. 따라서 아래 세 명령에서 placeholder로 missing을 사용합니다:
mdadm --create /dev/md0 --level=1 --raid-disks=2 missing /dev/hdb1
mdadm --create /dev/md1 --level=1 --raid-disks=2 missing /dev/hdb5
mdadm --create /dev/md2 --level=1 --raid-disks=2 missing /dev/hdb6생성 뒤에는
cat /proc/mdstat명령으로 배열 상태를 확인합니다. [U] 또는 [U]는 배열이 degraded 상태임을 의미하고 [UU]는 정상 상태임을 의미합니다:
[root@server1 ~]# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md2 : active raid1 hdb6[1]
4642688 blocks [2/1] [_U]
md1 : active raid1 hdb5[1]
417536 blocks [2/1] [_U]
md0 : active raid1 hdb1[1]
176576 blocks [2/1] [_U]
unused devices:
[root@server1 ~]# 다음으로 각 RAID에 파일시스템을 생성합니다 (/dev/md0과 /dev/md2는 ext3, /dev/md1은 swap):
mkfs.ext3 /dev/md0
mkswap /dev/md1
mkfs.ext3 /dev/md2이제 /etc/mdadm.conf(아직 새로운 배열 정보가 없음)를 현재 상태에 맞게 업데이트합니다:
cp /etc/mdadm.conf /etc/mdadm.conf_orig
mdadm --examine --scan >> /etc/mdadm.conf파일 내용을 출력합니다:
cat /etc/mdadm.conf파일에서 이제 세 개의 (degraded) RAID 배열에 대한 상세 정보를 볼 수 있어야 합니다:
| # mdadm configuration file # # mdadm will function properly without the use of a configuration file, # but this file is useful for keeping track of arrays and member disks. # In general, a mdadm.conf file is created, and updated, after arrays # are created. This is the opposite behavior of /etc/raidtab which is # created prior to array construction. # # # the config file takes two types of lines: # # DEVICE lines specify a list of devices of where to look for # potential member disks # # ARRAY lines specify information about how to identify arrays so # so that they can be activated # # You can have more than one device line and use wild cards. The first # example includes SCSI the first partition of SCSI disks /dev/sdb, # /dev/sdc, /dev/sdd, /dev/sdj, /dev/sdk, and /dev/sdl. The second # line looks for array slices on IDE disks. # #DEVICE /dev/sd[bcdjkl]1 #DEVICE /dev/hda1 /dev/hdb1 # # If you mount devfs on /dev, then a suitable way to list all devices is: #DEVICE /dev/discs/*/* # # # # ARRAY lines specify an array to assemble and a method of identification. # Arrays can currently be identified by using a UUID, superblock minor number, # or a listing of devices. # # super-minor is usually the minor number of the metadevice # UUID is the Universally Unique Identifier for the array # Each can be obtained using # # mdadm -D |
5 시스템을 RAID1에 맞게 조정
이제 /dev/md0과 /dev/md2를 마운트합니다 (swap인 /dev/md1은 마운트 불필요):
mkdir /mnt/md0
mkdir /mnt/md2mount /dev/md0 /mnt/md0
mount /dev/md2 /mnt/md2다음 명령을 통해 두 배열이 마운트되었는지 확인합니다:
mount예시 출력:
[root@server1 ~]# mount
/dev/hda6 on / type ext3 (rw,relatime)
none on /proc type proc (rw)
/dev/hda1 on /boot type ext3 (rw,relatime)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/md0 on /mnt/md0 type ext3 (rw)
/dev/md2 on /mnt/md2 type ext3 (rw)
[root@server1 ~]#다음으로 /etc/fstab를 수정합니다. /dev/hda1 → /dev/md0, /dev/hda5 → /dev/md1, /dev/hda6 → /dev/md2로 바꿉니다:
vi /etc/fstab| /dev/md2 / ext3 relatime 1 1 /dev/md0 /boot ext3 relatime 1 2 /dev/cdrom /media/cdrom auto umask=0022,users,iocharset=utf8,noauto,ro,exec 0 0 /dev/fd0 /media/floppy auto umask=0022,users,iocharset=utf8,noauto,exec,flush 0 0 none /proc proc defaults 0 0 /dev/md1 swap swap defaults 0 0 |
/etc/mtab에서도 /dev/hda1 → /dev/md0 및 /dev/hda6 → /dev/md2로 교체합니다(마지막 두 /dev/md 항목은 무시 가능):
vi /etc/mtab| /dev/md2 / ext3 rw,relatime 0 0 none /proc proc rw 0 0 /dev/md0 /boot ext3 rw,relatime 0 0 none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0 /dev/md0 /mnt/md0 ext3 rw 0 0 /dev/md2 /mnt/md2 ext3 rw 0 0 |
다음으로 GRUB 부트로더 설정을 수정합니다. /boot/grub/menu.lst를 열고 default 0 바로 아래에 fallback 1을 추가합니다:
vi /boot/grub/menu.lst| [...] default 0 fallback 1 [...] |
이는 첫 번째 커널이 부팅에 실패하면 fallback(두 번째 항목)이 시도되도록 합니다.
같은 파일의 하단에서 커널 stanza를 복사하여 첫 번째 기존 stanza 앞에 붙여 넣고 root=/dev/hda6을 root=/dev/md2로, (hd0,0)을 (hd1,0)으로 바꿉니다. resume=/dev/hda5가 있으면 resume=/dev/md1로 바꾸십시오:
| [...] title linux kernel (hd1,0)/vmlinuz BOOT_IMAGE=linux root=/dev/md2 resume=/dev/md1 initrd (hd1,0)/initrd.img title linux kernel (hd0,0)/vmlinuz BOOT_IMAGE=linux root=/dev/hda6 resume=/dev/hda5 initrd (hd0,0)/initrd.img |
전체 파일 예시는 다음과 같습니다:
| timeout 10 color black/cyan yellow/cyan default 0 fallback 1 title linux kernel (hd1,0)/vmlinuz BOOT_IMAGE=linux root=/dev/md2 resume=/dev/md1 initrd (hd1,0)/initrd.img title linux kernel (hd0,0)/vmlinuz BOOT_IMAGE=linux root=/dev/hda6 resume=/dev/hda5 initrd (hd0,0)/initrd.img title failsafe kernel (hd0,0)/vmlinuz BOOT_IMAGE=failsafe root=/dev/hda6 failsafe initrd (hd0,0)/initrd.img |
(hd1,0)은 /dev/hdb의 첫 파티션을 가리키며, 이미 RAID 배열의 일부입니다. 잠시 후 시스템을 재부팅하면(아직 degraded 상태) RAID에서 부팅을 시도하고 실패 시 /dev/hda로 fallback합니다.
다음으로 ramdisk(initrd)를 현재 상황에 맞춰 갱신합니다:
mv /boot/initrd-`uname -r`.img /boot/initrd-`uname -r`.img_orig
mkinitrd /boot/initrd-`uname -r`.img `uname -r`이제 /dev/hda1과 /dev/hda6의 내용을 /dev/md0 및 /dev/md2(각각 /mnt/md0, /mnt/md2에 마운트됨)로 복사합니다:
cp -dpRx / /mnt/md2cd /boot
cp -dpRx . /mnt/md06 GRUB 준비
다음으로 두 번째 하드디스크인 /dev/hdb(=GRUB에서는 (hd1))에 GRUB을 설치합니다. 먼저 grub 셸을 실행합니다:
grubGRUB 프롬프트에서 아래 명령을 순서대로 입력합니다:
root (hd0,0)출력 예시:
grub> root (hd0,0)
Filesystem type is ext2fs, partition type 0x83
grub>setup (hd0)출력 예시 (일부 생략):
grub> setup (hd0)
Checking if "/boot/grub/stage1" exists... no
Checking if "/grub/stage1" exists... yes
Checking if "/grub/stage2" exists... yes
Checking if "/grub/e2fs_stage1_5" exists... yes
Running "embed /grub/e2fs_stage1_5 (hd0)"... 15 sectors are embedded.
succeeded
Running "install /grub/stage1 (hd0) (hd0)1+15 p (hd0,0)/grub/stage2 /grub/menu.lst"... succeeded
Done.
grub>같은 절차를 (hd1,0)과 (hd1)에 대해 반복합니다:
root (hd1,0)
setup (hd1)
quit모든 작업 후 일반 셸로 돌아와 시스템을 재부팅합니다:
reboot시스템이 RAID로 부팅되면, degraded 상태(미러의 한쪽이 missing)에서 복구를 진행하고 남은 디스크에 파티션을 추가하여 리빌드하면 됩니다.
운영자 체크리스트
- 작업 전 전체 백업 수행
- mdadm.conf 백업: /etc/mdadm.conf_orig
- fstab, mtab 백업
- /boot 내용이 /mnt/md0로 정상 복사되었는지 확인
- initrd 재생성 확인
- GRUB을 두 디스크에 모두 설치했는지 확인
- 재부팅 후 콘솔에서 /proc/mdstat 확인
복구 실패 시나리오 및 대처
- 부팅 불가: GRUB이 두 디스크 중 한쪽에만 설치되었거나 menu.lst 내 root 장치가 잘못되었을 수 있음. 긴급 상황에서는 라이브 CD로 부팅해 /mnt/md0, /mnt/md2를 마운트하고 GRUB 재설치.
- 배열이 리빌드되지 않음: 잘못된 파티션 테이블이나 uuid mismatch가 원인일 수 있음. mdadm –detail /dev/mdX로 상태 확인 후 필요한 디스크를 –add.
- initrd 문제: 커널 버전과 일치하는 initrd가 생성되었는지 확인. uname -r 결과와 /boot/initrd-*.img 이름이 일치해야 함.
대안 및 권장 방법
- LVM을 함께 사용하면 파일시스템 이동과 스냅샷 기반 복구가 쉬워짐.
- 최신 시스템에서는 GRUB2를 사용하고 device-mapper, UUID 기반 fstab 및 grub.cfg를 활용하면 더 안정적임.
- 테스트 환경에서 전체 재부팅 시나리오를 먼저 검증할 것.
간단 용어집
- RAID1: 디스크 미러링으로 가용성 향상
- degraded: 배열 구성원이 하나 이상 빠진 상태
- initrd (initramfs): 커널 부팅 시 필요한 초기 파일시스템
- mdadm: Linux 소프트웨어 RAID 관리 도구
요약
- missing을 이용해 degraded 상태로 RAID1 배열을 생성하고 파일시스템을 구성했습니다.
- mdadm.conf, fstab, mtab을 갱신하고 initrd를 재생성했습니다.
- /dev/hda의 내용을 RAID로 복사하고 GRUB을 양쪽 디스크에 설치해 RAID에서의 부팅을 준비했습니다.
추가로, 실제 환경에서는 단계별로 확인(마운트, mdstat, 부팅 성공 여부)을 하며 진행하세요.