{"title": "CentOS\u4e0b\u4f7f\u7528mdadm\u521b\u5efaRAID10\u9635\u5217", "update_time": "2013-01-30 22:47:00", "tags": "mdadm", "pid": "214", "icon": "linux.png"}
原来有一台做hadoop slave的机器,现在想用来做运维工具机。可惜机器是sas1068e的卡,默认界面只能做一个RAID1的阵列。 为了不浪费后面10块1T的盘。我使用mdadm工具将后面10个盘做RAID10阵列。 ``` #!/bin/bash PATH='/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin' #定义参与软RAID组建的磁盘 disks=' /dev/sda /dev/sdb /dev/sdc /dev/sdd /dev/sde /dev/sdf /dev/sdg /dev/sdh /dev/sdi /dev/sdj ' #将磁盘分区 for i in $disks do total_size=`parted -s $i print 2>/dev/null | grep ^Disk | awk -F: '{print $2}' | sed 's/[ \t]\{1,\}//g'` [ "x${total_size}" == "x" ] && total_size=`fdisk -l $i 2>/dev/null | grep ^Disk | grep -v identifier | awk '{printf("%d",$3);}'` label_type='msdos' if echo $total_size | grep -q GB ; then total_size_num=`echo $total_size | sed 's/GB//g'` [ $total_size_num -gt 2000 ] && label_type='gpt' elif echo $total_size | grep -q TB ; then label_type='gpt' fi parted -s $i mklabel $label_type parted -s $i mkpart primary 0% 100% done sleep 5 partprobe sleep 2 devices=`echo $disks | sed -e 's/[ \t]\{1,\}/1 /g' -e 's/$/1/g' ` devices_count=`echo $disks | awk '{print NF}'` #使用mdadm工具组建起磁盘阵列 mdadm --create /dev/md0 --level=10 --raid-devices=${devices_count} ${devices} #生成mdadm的配置文件,以供下次启动时自动启动软raid mdadm -Ds >> /etc/mdadm.conf ``` 完成后执行fdisk -l即可以看到/dev/md0了 ``` Disk /dev/md0: 5001.0 GB, 5001010872320 bytes 2 heads, 4 sectors/track, 1220949920 cylinders Units = cylinders of 8 * 512 = 4096 bytes Disk /dev/md0 doesn't contain a valid partition table ``` 查看md0的详细信息: ``` mdadm -D /dev/md0 ``` 显示结果如下: ``` /dev/md0: Version : 0.90 Creation Time : Wed Jan 30 21:31:44 2013 Raid Level : raid10 Array Size : 4883799680 (4657.55 GiB 5001.01 GB) Used Dev Size : 976759936 (931.51 GiB 1000.20 GB) Raid Devices : 10 Total Devices : 10 Preferred Minor : 0 Persistence : Superblock is persistent Update Time : Wed Jan 30 21:38:35 2013 State : active, resyncing Active Devices : 10 Working Devices : 10 Failed Devices : 0 Spare Devices : 0 Layout : near=2 Chunk Size : 64K Rebuild Status : 3% complete UUID : 9bc0d611:5aa5749a:ffa4d4d5:af481dce Events : 0.2 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 49 3 active sync /dev/sdd1 4 8 65 4 active sync /dev/sde1 5 8 81 5 active sync /dev/sdf1 6 8 97 6 active sync /dev/sdg1 7 8 113 7 active sync /dev/sdh1 8 8 129 8 active sync /dev/sdi1 9 8 145 9 active sync /dev/sdj1 ``` 从中可以看到md0正在rebuild。对于rebuild的进度。也可以通过cat /proc/mdstat 看到相对比较简单。 之后/dev/md0可以像普通磁盘一样格式化使用了。