Linux-qcow2 format install virtual machine and script one-click Clone qcow2 virtual Machine

Source: Internet
Author: User

1 using QCOW2 format disk file when hard disk KVM installed (clone system occupies very small space)

Cd/var/lib/libvirt/images (disk file storage area)

Qemu-img create-f qcow2 haha.img 80G (disk Instant creation complete, potential size 80G, actual size by current actual consumption size)

Virt-manager installed, hard drive Select/var/lib/libvirt/images/haha.img

Qcow2 Cloning (quick creation of new disk files) qemu-img create-b haha.img-f qcow2 haha01.img

2 Cloning qcow2 format KVM virtual machine with script

#!/bin/bash

Img_dir=/var/lbi/libirt/images #定义磁盘路径

Basevm=haha #定义原系统名

Xmlfile=/tmp/myvm.xml #定义xml命令文件路径

While [1]

Do

Read-p "Please enter the cloned virtual machine digital code:" Vmnum #脚本交互模式

If [-Z ' ${vmnum} '];then #输入的不是数字

echo "You can't enter anything."

Continue #跳出当前循环

elif ["$VMNUM"! = $ (echo ${vmnum}*1 | BC)];then #判断输入的值是不是数字

echo "You must enter a number"

Continue #跳出当前循环

elif ["$VMNUM"-lt 0-1 "$VMNUM"-gt];then #判断输入的小于1或者大于99

echo "The number you entered is invalid"

Continue

Else

Break #跳出所有循环

Fi

Done

Newvm=hahanew${vmnum} #定义新客隆系统名

If [-F ${img_dir}/${newvm}.img];then #判断用户输入的编号是否已存在

echo "${NEWVM} already exists!!!"

Exit 1

Fi

Echo-en "Creating Disk ... \t\t\t" #-n: Non-newline-e uses special characters currently using n

Qemu-img create-b ${img_dir}/${basevm}.img-f qcow2 ${img_dir}/{newvm}.img &>/dev/null #克隆

Echo-e "\e[32;1m[ok]\e[0m" #输出绿色的OK

Virsh dumpxml rhel6 > $XMLFILE #指定xml路径

Sed-i "/<NAME>${BASEVM}/S/${BASEVM}/${NEWVM}" $XMLFILE #修改系统名

Sed-i "/uuid/s/<uuid>.*</<uuid>$ (Uuidgen) </" $XMLFILE #修改UUID

Sed-i "/libvirt/s/${basevm}/${newvm}/" $XMLFILE #修改磁盘

Sed-i "/mac addr/s/00 '/${vmnum} '/" $XMLFILE #修改MAC地址

Echo-en "New virtual machine cloning complete ..../t/t/t"

Virsh define $XMLFILE &>/dev/null #定义新的虚拟机

echo "[OK]"


Linux-qcow2 format install virtual machine and script one-click Clone qcow2 virtual 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.