歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux教程

Linux中使用mdadm創建與管理軟raid

注:本次操作以RHEL4為例,但應該可以應用到其它大部分的distro上(guess)。

目錄

1 mdadm的幾個常用參數

2 創建軟raid的大體流程

3 示例:創建軟raid5(+hotspare)

4 出現故障後的恢復

5 misc

[編輯]mdadm的幾個常用參數

-C 創建Raid,後面跟參數,代表raid設備的名稱。比如:/dev/md0,/dev/md1。

-n 用於創建磁盤陣列的磁盤個數。

-l Raid的級別。

-x 指定用於hotspare(熱備盤)的磁盤個數。如果陣列中有一塊硬盤壞了,它會立刻頂上,並rebuild;

-D 顯示軟raid的詳細信息;

-s 掃描配置文件(/etc/mdadm.conf)或'/proc/mdstat'來查看遺漏的信息f;

[編輯]創建軟raid的大體流程

使用fdisk工具為新磁盤創建分區;

使用mkfs.XXXX工具將剛才劃分好的分區格式化成某種格式的文件系統。比如:ext3,reiserfs等;

使用mdadm來創建軟raid;

創建/etc/mdadm.conf文件(注意文件的格式,包括是否有逗號等等。該文件是為了系統在重啟後能夠自動啟用軟raid。可以查看/etc/rc.sysinit腳本,搜索'mdadm'字符串就明白了);

[編輯]示例:創建軟raid5(+hotspare)

以下是我的一次實際操作的完整過程:

這是用'fdisk -l'命令查看到的我當前的磁盤和分區情況(只有/dev/sda在使用,其它四個都是新磁盤,沒有分區,沒有格式化):

# fdisk -lDisk /dev/sda: 6442 MB, 6442450944 bytes255 heads, 63 sectors/track, 783 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *           1         720     5783368+  83  Linux/dev/sda2             721         783      506047+  82  Linux swapDisk /dev/sdb: 214 MB, 214748160 bytes64 heads, 32 sectors/track, 204 cylindersUnits = cylinders of 2048 * 512 = 1048576 bytesDisk /dev/sdb doesn't contain a valid partition tableDisk /dev/sdc: 214 MB, 214748160 bytes64 heads, 32 sectors/track, 204 cylindersUnits = cylinders of 2048 * 512 = 1048576 bytesDisk /dev/sdc doesn't contain a valid partition tableDisk /dev/sdd: 214 MB, 214748160 bytes64 heads, 32 sectors/track, 204 cylindersUnits = cylinders of 2048 * 512 = 1048576 bytesDisk /dev/sdd doesn't contain a valid partition tableDisk /dev/sde: 214 MB, 214748160 bytes64 heads, 32 sectors/track, 204 cylindersUnits = cylinders of 2048 * 512 = 1048576 bytesDisk /dev/sde doesn't contain a valid partition table

使用fdisk創建分區(本例中將整塊磁盤劃分為一個主分區。其余幾塊磁盤也做相同的操作。):

# fdisk /dev/sdbDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel. Changes will remain in memory only,until you decide to write them. After that, of course, the previouscontent won't be recoverable.Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)Command (m for help): nCommand action   e   extended   p   primary partition (1-4)pPartition number (1-4): 1First cylinder (1-204, default 1):Using default value 1Last cylinder or +size or +sizeM or +sizeK (1-204, default 204):Using default value 204Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.

為剛才新建的分區建立文件系統(其余幾個分區依次做相同的操作):

# mkfs.ext3 /dev/sdb1mke2fs 1.35 (28-Feb-2004)Filesystem label=OS type: LinuxBlock size=1024 (log=0)Fragment size=1024 (log=0)52416 inodes, 208880 blocks10444 blocks (5.00%) reserved for the super userFirst data block=1Maximum filesystem blocks=6737100826 block groups8192 blocks per group, 8192 fragments per group2016 inodes per groupSuperblock backups stored on blocks:        8193, 24577, 40961, 57345, 73729, 204801Writing inode tables: doneCreating journal (4096 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 37 mounts or180 days, whichever comes first.  Use tune2fs -c or -i to override.

所有磁盤都操作完後,再次用'fdisk -l'查看磁盤及分區狀態:

# fdisk -lDisk /dev/sda: 6442 MB, 6442450944 bytes255 heads, 63 sectors/track, 783 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *           1         720     5783368+  83  Linux/dev/sda2             721         783      506047+  82  Linux swapDisk /dev/sdb: 214 MB, 214748160 bytes64 heads, 32 sectors/track, 204 cylindersUnits = cylinders of 2048 * 512 = 1048576 bytes   Device Boot      Start         End      Blocks   Id  System/dev/sdb1               1         204      208880   83  LinuxDisk /dev/sdc: 214 MB, 214748160 bytes64 heads, 32 sectors/track, 204 cylindersUnits = cylinders of 2048 * 512 = 1048576 bytes   Device Boot      Start         End      Blocks   Id  System/dev/sdc1               1         204      208880   83  LinuxDisk /dev/sdd: 214 MB, 214748160 bytes64 heads, 32 sectors/track, 204 cylindersUnits = cylinders of 2048 * 512 = 1048576 bytes   Device Boot      Start         End      Blocks   Id  System/dev/sdd1               1         204      208880   83  LinuxDisk /dev/sde: 214 MB, 214748160 bytes64 heads, 32 sectors/track, 204 cylindersUnits = cylinders of 2048 * 512 = 1048576 bytes   Device Boot      Start         End      Blocks   Id  System/dev/sde1               1         204      208880   83  Linux

使用mdadm創建一個軟raid,raid級別:5;並有一個hotspare盤:

# mdadm -C /dev/md0 -l5 -n3 -x1 /dev/sd[b-e]1mdadm: array /dev/md0 started.

輸出信息顯示軟raid(/dev/md0)已經啟用了。使用mdadm的-D參數(--detail)可以查看軟raid狀態:

# mdadm -D /dev/md0/dev/md0:        Version : 00.90.01  Creation Time : Wed Aug 23 15:10:19 2006     Raid Level : raid5     Array Size : 417536 (407.75 MiB 427.56 MB)    Device Size : 208768 (203.88 MiB 213.78 MB)   Raid Devices : 3  Total Devices : 4Preferred Minor : 0    Persistence : Superblock is persistent    Update Time : Wed Aug 23 15:10:21 2006          State : clean Active Devices : 3Working Devices : 4 Failed Devices : 0  Spare Devices : 1         Layout : left-symmetric     Chunk Size : 64K    Number   Major   Minor   RaidDevice State       0       8       17        0      active sync   /dev/sdb1       1       8       33        1      active sync   /dev/sdc1       2       8       49        2      active sync   /dev/sdd1       3       8       65       -1      spare   /dev/sde1           UUID : f8283de5:39c73d89:b9fbc266:fdceb416         Events : 0.2

生成配置文件(/etc/mdadm.conf):

# mdadm -D -s >/etc/mdadm.conf

Copyright © Linux教程網 All Rights Reserved