鸿 网 互 联 www.68idc.cn

当前位置 : 服务器租用 > 操作系统维护 > vmware > >

备份一个通过拷贝来创建虚拟机镜像的脚本

来源:互联网 作者:佚名 时间:2015-04-10 15:26
备份一个通过拷贝来创建虚拟机镜像的脚本 [plain] #!/bin/sh machine=$1 mac=$2 ip=$3 if [ -z $machine ]; then echo usage: sh $0 machine mac ip exit fi source_bytes=`fdisk -ucl /dev/vbd/test00|grep test00|grep -Eo [0-9]+ bytes|cut -d -f1` sourc
备份一个通过拷贝来创建虚拟机镜像的脚本
 
[plain]
#!/bin/sh  
  
machine=$1  
mac=$2  
ip=$3  
  
if [ -z "$machine" ]; then  
    echo "usage: sh $0 machine mac ip"  
    exit  
fi  
  
source_bytes=`fdisk -ucl /dev/vbd/test00|grep test00|grep -Eo "[0-9]+ bytes"|cut -d" " -f1`  
source_M=$(($source_bytes/1024/1024))  
  
echo "creating new logic volumn $machine"  
lvcreate -L ${source_M}M -n $machine vbd  
  
echo "copy data from lv test00"  
dd if=/dev/vbd/test00 of=/dev/vbd/$machine bs=1M count=$source_M  
  
echo "mount new created logic volumn"  
kpartx -av /dev/vbd/$machine  
  
echo "scan volumn group"  
vgscan  
  
echo "rename volumn group to $machine"  
vgrename test00 $machine  
  
echo "load volumn group $machine"  
vgchange -ay $machine  
  
echo "mount logic volumn lv_root"  
mount /dev/$machine/lv_root /mnt  
  
echo "modify fstab to new volumn group name $machine"  
sed -i "s/test00/$machine/g" /mnt/etc/fstab   
sed -i "s/test00/$machine/g" /mnt/etc/sysconfig/network  
  
if [ -n "$mac" ]; then  
    sed -i "s/00:16:3E:38:01:E6/$mac/g" /mnt/etc/sysconfig/network-scripts/ifcfg-eth0  
fi  
  
if [ -n "$ip" ]; then  
   【本文来自鸿网互联 (http://www.68idc.cn)】 sed -i "s/192.168.1.230/$ip/g" /mnt/etc/sysconfig/network-scripts/ifcfg-eth0  
fi  
  
echo "umount lv_root"  
umount /mnt  
  
echo "mount first partition of vbd-$machine"  
mount /dev/mapper/vbd-${machine}p1 /mnt  
  
echo "change menu.lst to $machine"  
sed -i "s/test00/$machine/g" /mnt/grub/menu.lst  
  
echo "umount vbd-$machine"  
umount /mnt  
  
echo "disable vg"  
vgchange -an $machine  
  
echo "disable $machine"  
kpartx -d /dev/vbd/$machine  
 
网友评论
<