首页 > 学技术 > 技术网文 > IRIX > 正文

[精华] a useful script


来源 chinaunix.net 酷勤网整理

Hi ,everybody.
   It's long time sice I came here at last time, I hope following script will be useful to everyone.
   
--------------------------------------------------------------------------
#!/bin/sh
# program to copy root & usr partitions and create a new bootable disk
# Note that this script is limited to SCSI drives, and only those
# on controller 0.
# It makes the root & usr filesystem on partition 0 for target drive
# and install sash, ide & fx in the volume header of the target drive.
# usage ./clone_disk 0 1 0 2

echo '---------------------------------------------------------------------'
echo 'Note: This utility will create a bootable clone of the system disk '
echo 'on target disk and will build the target disk with an XFS filesystem.'
echo '---------------------------------------------------------------------'

# needed
hn=`hostname`
if [ "$hn" = "" ]&#59; then
hostname IRIS
fi

( versions eoe\*|grep xfs ) >; /dev/null 2>;&1
if [ $? -ne 0 ]&#59; 
then
echo The source disk does not have support for XFS 
echo and thus cannot be cloned by this script.
exit 1
fi

if [ $# -ne 4 ]
then
        echo "Usage:  $0  source_controler  source_id  target_controler  target_id"
        exit 1
fi


SRC_CON=$1
SRC_NUM=$2
TGT_CON=$3
TGT_NUM=$4

echo "\nJust checking:"
echo "The source (system) disk is controler "$SRC_CON" SCSI id "$SRC_NUM" "
echo "The target ( new  ) disk is controler "$TGT_CON" SCSI id "$TGT_NUM" "
echo "\007OK? (n)\c"
        read answer
        case "$answer" {
        y|Y|yes|Yes|YES) &#59;&#59;
        *) echo "\007\n\nAbort"&#59; exit 1&#59;&#59;
        }


echo "\nChecking SCSI disk"$TGT_NUM".."
hinv -c disk | grep -s "unit $TGT_NUM on SCSI controller $TGT_CON" >; /dev/null 2>;&1
if [ $? -ne 0 ]
then echo Sorry, SCSI disk $TGT_NUM not found on controller $TGT_CON
        exit 1
fi

fstype=`stat /dev/root |grep fstype|awk '{print $2}'`

fx -x &quot;dksc($TGT_CON,$TGT_NUM,0)&quot; << EOF
label/create/all
label/sync
..
exit
EOF

echo &quot;\nStart disk clone...&quot;
umount /d
mkdir /d

echo making a target filesystem with an internal log 2048 blocks long and 1 KB block size
mkfs -d name=/dev/rdsk/dks&quot;$TGT_CON&quot;d&quot;$TGT_NUM&quot;s0 -l internal,size=2048b -b size=1k
labelit /dev/rdsk/dks&quot;$TGT_CON&quot;d&quot;$TGT_NUM&quot;s0 / sgi
mount /dev/dsk/dks&quot;$TGT_CON&quot;d&quot;$TGT_NUM&quot;s0 /d
df -k
echo &quot;\ncopy root partition...&quot;
if [ &quot;$fstype&quot; = efs ]&#59; then
cd /&#59; dump 0f - / | (cd /d&#59; restore rf - )
else
cd /&#59; xfsdump -L dump -M dump -l 0 -J - / | (cd /d&#59; xfsrestore - .)
fi

fsstat /dev/usr 1>; /dev/null 2>;&amp;1
stat=$?
if [ $stat = 2 ]
then
mkdir /d/usr
df -k
echo &quot;\ncopy usr partition...&quot;
if [ &quot;$fstype&quot; = efs ]&#59; then
cd /usr&#59; dump 0f - /usr | (cd /d/usr&#59; restore rf - )
else
cd /usr&#59; xfsdump -L dump -M dump -l 0 -J - /usr | (cd /d/usr&#59; xfsrestore - .)
fi
fi

echo &quot;\ninstalling sash, ide &amp; fx in volume header.....&quot;

#create sash fx ide tmp files
if [ -d /stand ]&#59;
then
     echo &quot; keep going.......&quot;
else
     mkdir /stand
fi
# get the current header files:
/etc/dvhtool -v get sash /stand/sash /dev/rdsk/dks&quot;$SRC_CON&quot;d&quot;$SRC_NUM&quot;vh
/etc/dvhtool -v get fx   /stand/fx   /dev/rdsk/dks&quot;$SRC_CON&quot;d&quot;$SRC_NUM&quot;vh
/etc/dvhtool -v get ide  /stand/ide  /dev/rdsk/dks&quot;$SRC_CON&quot;d&quot;$SRC_NUM&quot;vh

# put them on the target
if [ -r /stand/sash ]&#59; then /etc/dvhtool -v c /stand/sash sash /dev/rdsk/dks&quot;$TGT_CON&quot;d&quot;$TGT_NUM&quot;vh&#59; fi
if [ -r /stand/fx   ]&#59; then /etc/dvhtool -v c /stand/fx     fx /dev/rdsk/dks&quot;$TGT_CON&quot;d&quot;$TGT_NUM&quot;vh&#59; fi
if [ -r /stand/ide  ]&#59; then /etc/dvhtool -v c /stand/ide   ide /dev/rdsk/dks&quot;$TGT_CON&quot;d&quot;$TGT_NUM&quot;vh&#59; fi
echo &quot;\nNew disk number &quot;$TGT_NUM&quot; ready to use.&quot;

echo &quot;\nDONE.....&quot;
exit 0



 :em02: 



 szh 回复于:2002-11-19 09:31:31

我看不明白是什么意思?


 race 回复于:2002-11-19 09:55:06

也是克隆启动盘
sgi,忙什么去了啊  常回来看看啊


 sgi 回复于:2002-11-21 17:14:25

谢谢race 把它加入精华区,我经常回来看看的,毕竟对irix还是毕竟怀念的。


 microroad 回复于:2002-11-22 08:11:18

sgi你已经不再用irix了吗?


 microroad 回复于:2002-11-22 08:19:21

刚恳了一点点,有一小惑,请说明一下:
echo &quot;\007OK? (n)\c&quot;
       read answer
       case &quot;$answer&quot; {
       y|Y|yes|Yes|YES) &#59;&#59;
       *) echo &quot;\007\n\nAbort&quot;&#59; exit 1&#59;&#59;
       }
有何作用?


 sgi 回复于:2002-11-22 20:43:00

是一个判断提示,yes就会继续,否则就退出。


 YT 回复于:2002-11-28 11:48:10

能够把这个详细的解释一遍吗?
我是CAICAI的 啊,,,,


 phoenixli 回复于:2002-11-29 00:33:16

讲了你也不懂.


 YT 回复于:2002-11-29 23:02:23

但是我会去用心学习的啊。。
呵呵
虽然偶很CAICAI 。。。




原文链接:http://bbs.chinaunix.net/viewthread.php?tid=17004
转载请注明作者名及原文出处



收藏本页到: