#!/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
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
备份一个通过拷贝来创建虚拟机镜像的脚本
最新推荐文章于 2021-03-15 22:01:13 发布