Back up a script for creating a virtual machine image through copying

Source: Internet
Author: User

Back up a script [plain] # for creating a VM image by copying it. /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 =/dev/vbd/$ machine bs = 1 M 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.