平時大多透過硬體協力廠商做RAID,這是正確的做法。因為軟體
RAID資料毀損的風險讓許多人都有慘痛的經驗,即使知道,仍有
不得已且需要使用軟體RAID的時候,做法如下,請各位參考看看!

假若,非不得已,還是建議各位避免使用軟體RAID,畢竟災後搶
救資料才是最麻煩的事情,設定前還是得三思而後行喔!^^~

【實作需求】

※ 作業系統:硬體 RAID1 ( 320G HD * 2 )
※ 掛載磁區:軟體 RAID5 ( 320G HD * 6 )

【步驟簡介】

※ 將六顆磁碟,分別做磁碟分割 (fdisk)。
※ mdadm 指令做 RAID 5,查看設定。
※ mke2fs ext3 格式。
※ monut 磁碟。

〈fdisk〉

鳥哥 fdisk 教學

[root@frames3 ~]# fdisk /dev/sda 
The number of cylinders for this disk is set to 38913.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
 (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n  ← n = 新增磁區

Command action
 e extended
 p primary partition (1-4)

p  ← p = 主分割區

Partition number (1-4): 1  ← 編號可隨設

First cylinder (1-38913, default 1):
Last cylinder or +size or +sizeM or +sizeK (1-38913, default 38913):

# 以上預設,按 Enter 跳過即可!


Command (m for help): t  ← t = 指定磁區格式

Hex code (type L to list codes):fd

# fd = Linux raid autodetect,按下「l」即可選擇需要的格式。


Command (m for help): w  ← w = 寫入分割表

The partition table has been altered!

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

※ 六顆硬碟,請逐一重複上面的步驟。

〈mdadm〉

[root@frames3 ~]# mdadm -C /dev/md0 -l5 -n6 /dev/sd[abcefg]1
mdadm: array /dev/md0 started.

※ 上面的寫法是縮寫。


按文件格式正確寫法應是如下:

# mdadm -C /dev/md0 --level=raid5 --raid-devices=6 /dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sde1 /dev/sdf1 /dev/sdg1


mdadm 繁體中文文件



〈查看 RAID 設定〉

[root@frames3 ~]# mdadm -D /dev/md0

/dev/md0:
     Version : 00.90.01
  Creation Time : Sat Apr 14 16:53:34 2007
    Raid Level : raid5
    Array Size : 1562842880 (1490.44 GiB 1600.35 GB)
   Device Size : 312568576 (298.09 GiB 320.07 GB)
   Raid Devices : 6
  Total Devices : 6
  Preferred Minor: 0
   Persistence : Superblock is persistent

   Update Time : Sat Apr 14 16:53:34 2007
      State : clean, degraded, recovering
  Active Devices : 5
  Working Devices: 6
  Failed Devices : 0
  Spare Devices : 1

      Layout : left-symmetric
    Chunk Size : 64K

Rebuild Status : 0% complete

 Number  Major  Minor  RaidDevice   State
   0    8    1    0   active sync  /dev/sda1
   1    8    17    1   active sync  /dev/sdb1
   2    8    33    2   active sync  /dev/sdc1
   3    8    65    3   active sync  /dev/sde1
   4    8    81    4   active sync  /dev/sdf1
   5    0    0    -1   removed
   6    8    97    5   spare  /dev/sdg1

    UUID : 177f49ae:919db53d:d8542f55:ed723198
    Events : 0.1

〈mke2fs format〉

[root@frames3 ~]# mke2fs -j /dev/md0
mke2fs 1.35 (28-Feb-2004)
max_blocks 4294967295, rsv_groups = 0, rsv_gdb = 1024
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
195362816 inodes, 390710720 blocks
19535536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=394264576
11924 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
    4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
    102400000, 214990848

Writing inode tables: done
inode.i_blocks = 155656, i_size = 4243456
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

〈monut〉

[root@frames3 mnt]# mkdir /mnt/raid
[root@frames3 mnt]# mount /dev/md0 /mnt/raid
[root@frames3 mnt]# df -h
Filesystem   容量 已用 可用 已用% 掛載點
/dev/sdd1    293G 6.1G 272G  3%  /
none      4.0G   0 4.0G  0%  /dev/shm
/dev/md0    1.5T 109M 1.4T  1%  /mnt/raid


以上即完成設定,記得寫入 /etc/fstab,開機即可順利自動掛載囉! ^0^/

【實作心得】

硬體 RAID :可透過協力廠商介面設定完成,介面會自動 Initialize。
軟體 RAID :則是透過磁碟分割、設定、格式化、掛載完成的。


※ 在此也要謝謝 小健 的幫忙唷!^^~


投入資訊產業,每天似乎都在解決問題,要學習的很多問題也不
是一下子就能解決,除了耐心,我想?工作的熱誠或許才能驅使
這份工作繼續奮鬥下去,坦承自己不是很優秀,應該只算是在皮
毛上打轉,期許自己能做點什麼,讓存在顯得有那麼一點的價值
吧?

                          Paul

                       2007.04.15


arrow
arrow
    全站熱搜

    paul 發表在 痞客邦 留言(3) 人氣()