前一陣子在搞我家的 server。因為更早之前硬體出了問題,就停了很久的機…
在回復的過程中,不小心把上面的 software RAID 搞壞了,唉~資料只好重新收集了。
以下為 RAID 建立的過程。
切割 HD
一共有三顆 HD,各為 160GB,分割如下
Disk Drive: /dev/hda
Size: 160039272960 bytes, 160.0 GB
Heads: 255 Sectors per Track: 63 Cylinders: 19457
Name Flags Part Type FS Type [Label] Size (MB)
hda1 Primary Linux raid autodetect 98.71
hda5 Logical Linux swap / Solaris 509.97
hda6 Logical Linux raid autodetect 5116.13
hda7 Logical Linux raid autodetect 154314.48
Disk Drive: /dev/hdb
Size: 160039272960 bytes, 160.0 GB
Heads: 255 Sectors per Track: 63 Cylinders: 19457
Name Flags Part Type FS Type [Label] Size (MB)
hdb1 Boot Primary Linux raid autodetect 98.71
hdb5 Logical Linux swap / Solaris 509.97
hdb6 Logical Linux raid autodetect 5116.13
hdb7 Logical Linux raid autodetect 154314.48
Disk Drive: /dev/hdc
Size: 160041885696 bytes, 160.0 GB
Heads: 16 Sectors per Track: 63 Cylinders: 310101
Name Flags Part Type FS Type [Label] Size (MB)
hdc1 Primary Linux raid autodetect 100.13
hdc5 Logical Linux swap / Solaris 511.97
hdc6 Logical Linux raid autodetect 5120.19
hdc7 Logical Linux raid autodetect 154309.61
前二顆同個牌子同型號,所以 sector、cluster 都一樣,第三個比較麻煩。記得,要建成 software RAID 的 partition 的 type 要設成 RAID autodetect(0xFD),這樣 bootloader or kernel 才會去掃它的 superblock 並自動啟動之。
至於 SWAP 並不需要建在 RAID 上,只要在 /etc/fstab 中一一加進即可,linux 會自動分散它的負載。
我的規劃是,建立三個 RAID partition - md0, md1, md2。md0 為 /boot,md1 為 root,md2 上會建立 LVM2 的 physical volume,之後要變更 partition 的配置時會方便許多。
因為 LILO 只能 boot 建在 RAID1(mirror) 的 partition,所以 md0 會被建立成 RAID leve 1 的 partition,指令如下
mdadm --create /dev/md0 --level 1 --devices 3 /dev/hda1 /dev/hdb1 /dev/hdc1
如果在建立時出現找不到 /dev/md0 的訊息,表示你的 device node 還未建立,以下列的指令建立之
mknod /dev/md0 b 9 0
mknod /dev/md1 b 9 1
mknod /dev/md2 b 9 2
b 代表 block device。9 為這個 device node 的 major number,kernel 會以此做為 index 對應到內部維護的一張表取得對 Software RAID driver 的參考。0 代表這個 deivce node 的 minor number,代表這個類型 device 的序號(因為同類型的裝置會有多個)。
如果說 device node 建立完成後在 create RAID 時還是出現類似找不到 file 之類或是錯誤參數的訊息,那就用 lsmod 檢查一下是否相對應的 module (raid0 raid1 raid10 raid5...) 已載入。
接著建立 md1
mdadm --create /dev/md1 --level 5 --devices 3 /dev/hda6 /dev/hdb6 /dev/hdc6
md1 用來放置 root file system,使用 RAID 5。如果當下你只有兩顆 HD or 兩個 partitions or 兩個 loop device 可用(正常的 RAID 5 至少要,那可以設定其中一個為 missing,如下例
mdadm --create /dev/md1 --level 5 --devices 3 /dev/hda6 /dev/hdb6 missing
這樣只要兩顆就可以建起 RAID 5。不過,如果其中一個 partition 出了什麼問題,那整個 md1 就掛了…
最後,再把 md2 建立起來
mdadm --create /dev/md2 --level 5 --devices 3 /dev/hda7 /dev/hdb7 /dev/hdc7
跟建立 md1 的指令很類似,只是換個 partition。
這樣,三個 raid 就建好並啟動了。想看看目前 raid 的情況,可以下列指令得知
cat /proc/mdstate
輸出會類似下面的訊息
Personalities : [raid0] [raid1] [raid10] [raid6] [raid5] [raid4]
md2 : active raid5 hdc7[2] hda7[0] hdb7[1]
301395200 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]
unused devices:
我之前在建立 md2 時,因為暫時把 hdc 拿去做其他的用途,所以在建立之初只有兩顆 HD。在要將 hdc 加進 raid 時,hdc1 -> md0 是 OK,hdc6 -> md1 也 OK,但 hdc7 -> md2 時一直跟我說參數錯誤,看了該建的 device node 及該 load 的 module 都沒問題,所以百思不得其解~
直到上週日,才又仔細的看了看這三個 partition 的差異,發現第三個的 size 比前二個稍小,於是將 partition 重分再試著將 hdc7 加進 md2
mdadm --manage --add /dev/md2 /dev/hdc7
Yes! 成功!