LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 809|回复: 4

自动创建md设备的脚本

[复制链接]
发表于 2006-2-12 16:58:47 | 显示全部楼层 |阅读模式
目的:对于多路径的SAN DISK(multipath)自动按照WWN创建md设备(使用mdadm),另外两个相同的存储(SUN6920)之间做同步复制,最终目的是要达到相同内容的LUN创建成相同的md设备。
配置文件/etc/wwn_md.conf:
[HTML]#
#
#6920_222                                6920_223                                partid          mddev   mountpoint
3600015d00004d300000000000000073d       5600015d07004d30000000000000006ae        1                md1
3600015d00004d3000000000000000743       6600015d07004d30000000000000002fc        1                md2

[/HTML]
脚本:
[HTML]#!/bin/bash
#please configure the file /etc/wwn_md.conf!
#
USAGE="Usage: $0 '[-f] [-s] [6920_222,6920_223]'"
FORCE=false
#get the param from shell
while getopts fs: OPTION ; do
case "$OPTION" in
s) Storage="$OPTARG" ;;
f) FORCE=true ;;
\?) echo "$USAGE" ;
exit 1
;;
esac
done
#check the -s param is in 6920_222,6920_223
echo $Storage
case "$Storage" in
6920_222) post=1 ;
#get the disk's wwn from the configure file---/etc/wwn_md.conf
wwn=`awk '/^[^#]/{print $1}' /etc/wwn_md.conf`;;
6920_223) post=2 ;
wwn=`awk '/^[^#]/{print $2}' /etc/wwn_md.conf`;;
*) echo "Sorry $Storage is not a valid Storage!";
exit 1
;;
esac
echo Storage is $Storage
echo In Force ModeFORCE

#wwn=`awk '/^[^#]/{print $port}' /etc/wwn_md.conf`
#clear the temp file
for i in $wwn
do
echo >/tmp/$i
done
for i in $wwn
do
#get the partition number from the configure file
part=`awk '/'$i'/{print $3}' /etc/wwn_md.conf`
#get the md device name from the configure file
md=`awk '/'$i'/{print $4}' /etc/wwn_md.conf`
echo $md
#get all the disk device name
dev=`ls /dev/sd[a-z]|awk -F/ '{print $3}'`;
for v_dev in $dev
do
#get each disk's scsi_id
sd=`scsi_id -g -s /block/$v_dev`
if [ $sd = $i ]
then
echo $i $v_dev$part
#get disks which have the same wwn/scsi_id,and save them name to tempfile /tmp/$i
echo "/dev/"$v_dev$part >>/tmp/$i
fi
done
#combination the disk name
disk=`cat /tmp/$i | sed '{N;s/\n/ /}'`
#use mdadm to create the md device
if [ $FORCE = true ]
then
echo "force create md device is set true!"
mdadm -C /dev/$md -l multipath -n2 $disk <<EOF
y
EOF
else
echo "force create md device is set false!"
mdadm -C /dev/$md -l multipath -n2 $disk
fi
#mdadm -C /dev/$md -l multipath -n2 $disk


done[/HTML]
发表于 2006-2-14 08:02:16 | 显示全部楼层
没用过SAN DISK,孤陋寡闻了。

如果是普通硬盘的话,可以用 Linux autodetect raid 在启动的时候自动组合 md,也算是方便。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-2-14 10:03:40 | 显示全部楼层
mdadm -Es?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-2-14 10:08:09 | 显示全部楼层
Linux autodetect raid 是一种分区类型?有什么特别的地方没有?
回复 支持 反对

使用道具 举报

发表于 2006-2-14 10:13:16 | 显示全部楼层
是一种分区类型。fdisk中代码为 fd。

没什么特别的地方,就是在启动 md 那些模块的时候自动的匹配所有已经建立的 RAID 组,而不需要去配置/etc/mdadm.conf 了,方便一点。我就是这样的,比较懒。。。。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表