Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

RAID構成ハードディスク交換

最終更新日: 2022.04.09

■概要

RAID1を構成するハードディスクの片系故障を想定して、故障ハードディスクを交換してRAIDの再構築を行う。


■故障ハードディスク切り離し

ここでは、マスタ側ハードディスク(/dev/sda)故障を前提とする。
[root@centos ~]# mdadm --manage /dev/md0 --fail /dev/sda1 ← RAIDデバイス(/dev/md0)を構成する/dev/sda1を故障状態にする
mdadm: set /dev/sda1 faulty in /dev/md0

[root@centos ~]# mdadm --manage /dev/md1 --fail /dev/sda2 ← RAIDデバイス(/dev/md1)を構成する/dev/sda2を故障状態にする
mdadm: set /dev/sda2 faulty in /dev/md1

[root@centos ~]# cat /proc/mdstat ← RAIDデバイス状態確認
Personalities : [raid1]
md0 : active raid1 sda1[2](F) sdb1[0] ← RAIDデバイス(/dev/md0)を構成する/dev/sda1の故障状態(F)確認
      104320 blocks [2/1] [U_]

md1 : active raid1 sda2[2](F) sdb2[0] ← RAIDデバイス(/dev/md1)を構成する/dev/sda2の故障状態(F)確認
      4088448 blocks [2/1] [U_]

unused devices: 

[root@centos ~]# mdadm --manage /dev/md0 --remove /dev/sda1 ← RAIDデバイス(/dev/md0)を構成する/dev/sda1を削除する
mdadm: hot removed /dev/sda1

[root@centos ~]# mdadm --manage /dev/md1 --remove /dev/sda2 ← RAIDデバイス(/dev/md1)を構成する/dev/sda2を削除する
mdadm: hot removed /dev/sda2

[root@centos ~]# cat /proc/mdstat ← RAIDデバイス状態確認
Personalities : [raid1]
md0 : active raid1 sdb1[0] ← RAIDデバイス(/dev/md0)を構成する/dev/sda1が表示されないことを確認
      104320 blocks [2/1] [U_]

md1 : active raid1 sdb2[0] ← RAIDデバイス(/dev/md1)を構成する/dev/sda2が表示されないことを確認
      4088448 blocks [2/1] [U_]

unused devices: 

■ハードディスク交換

[root@centos ~]# halt ← システム停止

ハードディスク交換
※マスタ側ハードディスクを交換する場合は、スレーブ側ハードディスクをマスタ側へ接続し、新ハードディスクをスレーブ側へ接続する(BIOSがマスタ側からブートしようとするため)

システム起動

■新ハードディスク初期化

(1)ディスクサイズが2TB未満の場合
[root@centos ~]# fdisk -l /dev/sda ← 既存ハードディスクパーティション確認

Disk /dev/sda: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   fd  Linux raid autodetect
/dev/sda2              14         522     4088542+  fd  Linux raid autodetect

[root@centos ~]# fdisk /dev/sdb ← 新ハードディスクパーティション設定
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n ← n(新規パーティション作成)応答
Command action
   e   extended
   p   primary partition (1-4)
p ← p(基本パーティション)応答
Partition number (1-4): 1 ← 1(パーティション番号)応答
First cylinder (1-522, default 1): 1 ← 1(/dev/sda1のパーティション割当て開始位置)応答
Last cylinder or +size or +sizeM or +sizeK (1-522, default 522): 13 ← 13(/dev/sda1のパーティション割当て終了位置)応答

Command (m for help): n ← n(新規パーティション作成)応答
Command action
   e   extended
   p   primary partition (1-4)
p ← p(基本パーティション)応答
Partition number (1-4): 2 ← 2(パーティション番号)応答
First cylinder (14-522, default 14): 14 ← 14(/dev/sda2のパーティション割当て開始位置)応答
Last cylinder or +size or +sizeM or +sizeK (14-522, default 522): 522 ← 522(/dev/sda2のパーティション割当て終了位置)応答

Command (m for help): t ← t(システムID設定)応答
Partition number (1-4): 1 ← 1(パーティション番号)応答
Hex code (type L to list codes): fd ← fd(RAIDシステムID)応答
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): t ← t(システムID設定)応答
Partition number (1-4): 2 ← 2(パーティション番号)応答
Hex code (type L to list codes): fd ← fd(RAIDシステムID)応答
Changed system type of partition 2 to fd (Linux raid autodetect)

Command (m for help): a ← a(ブート可能フラグ設定)応答
Partition number (1-4): 1 ← 1(パーティション番号)応答

Command (m for help): p ← p(パーティション表示)応答

Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1          13      104391   fd  Linux raid autodetect
/dev/sdb2              14         522     4088542+  fd  Linux raid autodetect
Boot、Start、Endが既存ハードディスク/dev/sdaと同じ設定になっていることを確認

Command (m for help): w ← w(パーティションをディスクへ書き込み)応答
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

(2)ディスクサイズが2TBを超える場合
[root@centos ~]# parted -s /dev/sdc print ← 既存ハードディスクパーティション確認
モデル: ATA WDC WD40EFAX-68J (scsi)
ディスク /dev/sdc: 4001GB
セクタサイズ (論理/物理): 512B/4096B
パーティションテーブル: msdos

番号  開始    終了    サイズ  タイプ   ファイルシステム  フラグ
 1    32.3kB  2199GB  2199GB  primary                    raid

[root@centos ~]# parted /dev/sdb ← 新ハードディスクパーティション設定
GNU Parted 2.1
/dev/sdb を使用
GNU Parted へようこそ! コマンド一覧を見るには 'help' と入力してください。
(parted) mklabel gpt ← パーティションテーブルをGPTに設定
警告: いま存在している /dev/sdc のディスクラベルは破壊され、このディスクの全データが失われます。続行しますか?
はい(Y)/Yes/いいえ(N)/No? y ← y応答
(parted) mkpart primary 0% 100% ← パーティション作成※すべての領域を割り当てる
(parted) print ← 表示
モデル: ATA WDC WD40EFAX-68J (scsi)
ディスク /dev/sdb: 4001GB
セクタサイズ (論理/物理): 512B/4096B
パーティションテーブル: gpt

番号  開始    終了    サイズ  ファイルシステム  名前     フラグ
 1    1049kB  4001GB  4001GB                    primary

(parted) set 1 raid on ← RAID設定
(parted) print ← 表示
モデル: ATA WDC WD40EFAX-68J (scsi)
ディスク /dev/sdb: 4001GB
セクタサイズ (論理/物理): 512B/4096B
パーティションテーブル: gpt

番号  開始    終了    サイズ  ファイルシステム  名前     フラグ
 1    1049kB  4001GB  4001GB                    primary  raid

(parted) quit ← 終了
通知: 必要であれば /etc/fstab を更新するのを忘れないようにしてください。

■新ハードディスクをRAIDデバイスへ組み込む

[root@centos ~]# mdadm --manage /dev/md0 --add /dev/sdb1 ← /dev/sdb1をRAIDデバイス(/dev/md0)へ組み込む
mdadm: added /dev/sdb1

[root@centos ~]# mdadm --manage /dev/md1 --add /dev/sdb2 ← /dev/sdb2をRAIDデバイス(/dev/md1)へ組み込む
mdadm: added /dev/sdb2

[root@localhost ~]# watch cat /proc/mdstat ← RAIDデバイス同期状態確認
RAIDデバイス同期中状態
Personalities : [raid1]
md0 : active raid1 sdb1[1] sda1[0]
      104320 blocks [2/2] [UU]

md1 : active raid1 sdb2[2] sda2[0]
      4088448 blocks [2/1] [U_]
      [>....................]  recovery =  0.5% (22528/4088448) finish=5.9min speed=11264K/sec

unused devices: 
・
・
・
RAIDデバイス同期完了状態
Personalities : [raid1]
md0 : active raid1 sdb1[1] sda1[0]
      104320 blocks [2/2] [UU]

md1 : active raid1 sdb2[1] sda2[0]
      4088448 blocks [2/2] [UU]

unused devices: 

CTRL+Cキー押下で終了

■GRUB(ブートローダー)インストール

[root@centos ~]# grub ← GRUBシェルモード起動

    GNU GRUB  version 0.97  (640K lower / 3072K upper memory)

 [ Minimal BASH-like line editing is supported.  For the first word, TAB
   lists possible command completions.  Anywhere else TAB lists the possible
   completions of a device/filename.]

grub> root (hd1,0) ← 新ハードディスクをrootにする
 Filesystem type is ext2fs, partition type 0xfd

grub> setup (hd1) ← 新ハードディスクへGRUBインストール
 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 (hd1)"...  15 sectors are embedded.
succeeded
 Running "install /grub/stage1 (hd1) (hd1)1+15 p (hd1,0)/grub/stage2 /grub/grub.conf"... succeeded
Done.

grub> root (hd0,0) ← 旧ハードディスクをrootにする
 Filesystem type is ext2fs, partition type 0xfd

grub> setup (hd0) ← 旧ハードディスクへGRUBインストール
 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/grub.conf"... succeeded
Done.

grub> quit ← GRUBシェルモード終了


■関連コンテンツ




▲このページのトップへ戻る

プライバシーポリシー
centossrv.com