rm -f /etc/udev/rules.d/70-persistent-net.rules
nova stop uuid
[root@node-63~]# scp -r /var/lib/nova/instances/5e8d5d06-e3ed-4f56-b28b-7d57309e9fbb node-76:/tmp/
qemu-img convert -f raw disk -O qcow2 disk
[root@node-63~]# qemu-img info /var/lib/nova/instances/5e8d5d06-e3ed-4f56-b28b-7d57309e9fbb/disk image:/var/lib/nova/instances/5e8d5d06-e3ed-4f56-b28b-7d57309e9fbb/disk file format: qcow2 virtual size:50G(53687091200 bytes) disk size:734M cluster_size:65536 backing file:/var/lib/nova/instances/_base/c631b3cc0e8ed9b5fa4d9020995b108d50ba085f Format specific information: compat:1.1 lazy refcounts:false
[root@node-63~]# scp /var/lib/nova/instances/_base/c631b3cc0e8ed9b5fa4d9020995b108d50ba085f node-76:/tmp/5e8d5d06-e3ed-4f56-b28b-7d57309e9fbb/
source /root/openrc-xxx
nova boot <instance-name>--image <image-uuid>--flavor <flavor-id>--nic net-id=<net-uuid>,v4-fixed-ip=<fixed-ip>--security-groups
<security-groups_id> --available-zone nova:hostname
注意:前端
1)instance-name 須要很原來的虛擬機名稱保持一致node
2)image-uuid,已經在K版環境上傳了I版鏡像,能夠直接使用:數據庫
有些鏡像沒法使用,建立這些鏡像的虛擬機時,請用任意其餘鏡像代替centos
3)flavor,選擇和之前的flavor內容一致的模板安全
4)net-uuid,請選擇正確的網絡bash
5)v4-fixed-ip,填寫正確的ip地址,和老系統保持ip一致網絡
6)--security-groups,填寫正確的安全組ssh
7)--available-zone ,事先規劃好的目標計算節點工具
再次注意:測試
建立虛擬機時,須要使用特定租戶建立,而不是用admin建立。
nova stop 41c0cc46-8afd-4333-877b-45310f2a80b2
mv /var/lib/nova/instances/5e8d5d06-e3ed-4f56-b28b-7d57309e9fbb/disk /var/lib/nova/instances/<new-vm-uuid>/
mv /var/lib/nova/instances/5e8d5d06-e3ed-4f56-b28b-7d57309e9fbb/c631b3cc0e8ed9b5fa4d9020995b108d50ba085f /var/lib/nova/instances/_base/
nova start xxxx
1. 是否可以正常啓動,重啓,讀寫數據。
2.虛機全部信息保持與原虛機一致,包括登陸密碼。
3.網絡可達東西南北流量正常,浮動ip能夠訪問。
#!/bin/bash #1:vm uuid #2:dest host #copy instance file to remote host set-e if[ $# -ne 2 ];then echo "please inpute two parment 1:uuid and 2:dest hostip" exit fi source openrc-zmg.sh echo vm-uuid:$1 echo remotehostip: $2 status=`nova show $1|grep "^| status"|cut -f 3-d "|"|sed 's/ //g'` if["$status"="ACTIVE"];then echo "please use [nova stop uuid] to shutoff the vm" exit fi nova show $1 sourcehost=`nova show $1|grep "OS-EXT-SRV-ATTR:host"|cut -f 3-d "|"` echo sourcehost:$sourcehost diskfile=/var/lib/nova/instances/$1 echo $diskfile #ssh $sourcehost "sshpass -p qwe123 scp -r /var/lib/nova/instances/$1 $2:/tmp" #echo diskfile copy complete #sleep 5 #ls #ssh $sourcehost qemu-img info /var/lib/nova/instances/"$1"/disk|grep backing|cut -d : -f 2|tr -d '\r'|xargs -i cp -r {} /tmp #sleep 5 expect <<! set timeout -1 spawn ssh $sourcehost expect "root@node" send "sshpass -p qwe123 rsync -arv --progress /var/lib/nova/instances/$1 $2:/var/lib/nova/instances/tmp\r" expect "~]#" send "qemu-img info /var/lib/nova/instances/$1/disk|grep back|cut -d : -f 2|xargs -i sshpass -p qwe123 scp {} $2:/var/lib/nova/instances/tmp/$1\r" expect "~]#" send "echo copy competed!\r" expect eof !
xargs -n7 ./create-vm.sh <test
#!/bin/bash set-e if[ $# -ne 7 ];then echo -e "please input parament\n1:<instance-name>\n2:<image-uuid>\n3:<flavor-id>\n4:<net-uuid>\n5:<fixed-ip>\n6:<security-groups_id>\n7:hostname" exit fi nova boot "$1"--image $2 --flavor $3 --nic net-id=$4,v4-fixed-ip=$5 --security-groups $6 --availability-zone nova:$7 sleep 30 uuid=`nova show "$1"|grep "^| id"|cut -f 3-d "|"` nova show "$1"
#!/bin/bash set-e if[ $# -ne 2 ];then echo "please inpute two parment 1:new vm uuid and 2:old vm uuid" exit fi status=`nova show $1|grep "^| status"|cut -f 3-d "|"|sed 's/ //g'` echo $status if["$status"="ACTIVE"];then echo "please use [nova stop uuid] to shutoff the vm" exit fi source admin-tenant.sh nova show $1 host=`nova show $1|grep "OS-EXT-SRV-ATTR:host"|cut -f 3-d "|"` echo "=====VM is at:$host==============" ssh $host mv /var/lib/nova/instances/tmp/$2/disk /var/lib/nova/instances/$1/ echo "========mv disk compelted====" sleep 3 echo "=====check the disk time for change======== " ssh $host ls -al /var/lib/nova/instances/$1/disk echo "disk change ok!" sleep 10 nova start $1 echo "========start vm==wait 30s======" nova show $1 sleep 30 echo "=======create 0M disk.config=======" ssh $host qemu-img create /var/lib/nova/instances/$1/disk.config 0M; ssh $host chown nova:nova /var/lib/nova/instances/$1/disk.config; echo "======check disk.config owner====== " ssh $host ls -al /var/lib/nova/instances/$1/disk.config