How To Migrate VM From one environment to Another - 0-complexity/openvcloud GitHub Wiki
- First you have to halt the vm you want to migrate first then copy the disk and convert it to qcow2 so it allocate it's actual size and to be easier to move
$ qemu-img convert -f raw -O qcow2 original-image.raw image-converted.qcow2
- Second go to the env you want to migrate your vm to :-
- Create new vm with same specs Ram/Disk/Cpu..
- Halt the new vm from the Grid .
- Remove disk and cloudinit of the new vm.
- Location of the files is under stor-xx ( you have to identify it by the ip address given from the panel ) and /mnt/stor/ location.
root@stor-03:/mnt/vmstor/vm-2171# ls -Fal
total 20971896
drwxrwxr-x 1 ovs ovs 4096 Mar 8 10:55 ./
drwxrwxr-x 1 ovs ovs 4096 Mar 8 10:55 ../
-rwxrwxr-x 1 ovs ovs 21474836480 Mar 8 10:55 bootdisk-vm-2171.raw*
-rwxrwxr-x 1 ovs ovs 376832 Mar 8 10:55 cloud-init-vm-2171.raw*
root@stor-03:/mnt/vmstor/vm-2171# rm -f bootdisk-vm-2171.raw cloud-init-vm-2171.raw
- Then Convert original disk to the same name of the new vm
$ qemu-img convert -p -f qcow2 -O raw base_image_362.qcow2 openvstorage+tcp:node_ip:ovs_port/vm-new_vm_number/same_disk_name::username=xxx:password=xxx
Like this:-
$ qemu-img convert -p -f qcow2 -O raw base_image_362.qcow2 openvstorage+tcp:10.101.1.14:26203/vm-140/bootdisk-vm-140:username=edgeUser01:password=VHF9mWGWWuNPkUK2
- Now we have to change the disk guid in the xml of the new vm
First get guid of the disk we just converted :
From 'js' shell
In [1]: from CloudscalerLibcloud import openvstorage
In [2]: vdisk = openvstorage.getVDisk('/mnt/vmstor/vm-9/bootdisk-vm-9.raw')
In [3]: vdisk.guid
Out[3]: 'e75b147a-1ae1-4df8-87eb-cfde64b927bf'
####Copy the guid we will need it
Second update old guid in osis disk model with the new one
Then update xml in in osis domain model
From 'js' shell
In [1]: ccl = j.clients.osis.getNamespace('cloudbroker')
In [2]: lcl = j.clients.osis.getNamespace('libcloud')
In [3]: vm = ccl.vmachine.get(vm_number) #like vm = ccl.vmachine.get(9)
In [4]: vm.disks
Out[4]: [14]
In [5]: disk = ccl.disk.get(14)
In [6]: disk.referenceId
Out[6]: u'openvstorage+tcp://10.102.1.14:26203/vm-9/bootdisk-vm-9@e75b147a-1ae1-4df8-87eb-cfde64b927bf'
In [7]: disk.referenceId = 'openvstorage+tcp://10.102.1.14:26203/vm-9/bootdisk-vm-9@New-GUID'
In [8]: ccl.disk.set(disk)
just to be sure the we updated to the new GUID
In [9]: disk.referenceId
Out[9]: u'openvstorage+tcp://10.102.1.14:26203/vm-9/bootdisk-vm-9@New-GUID'
Then we need to delete metaiso disk of the new vm to make sure that passwords and disk Guid will not change if vm restarted : open Js shell
In [78]: vm = ccl.vmachine.get(106)
In [79]: vm.disks
Out[79]: [242, 243, 244]
In [80]: vm.disks.remove(243)
In [81]: vm.disks
Out[81]: [242, 244]
In [82]: ccl.vmachine.set(vm)
Out[82]: [106, False, True]
Then make sure if port forwards are done and the same in both vms , then start it.
Notes
For windows 2012/2016 and 10 that are UEFI enabled the following changes should be also performed.
apt-get install ovmf # this should run on all CPU nodes.
The XML File should also contain the following additional elements:
<os>
<type arch="x86_64" machine="pc-1.3">hvm</type>
<loader readonly='yes' type='rom'>/usr/share/ovmf/OVMF.fd</loader> <!-- This part is added -->
<boot dev="hd" />
</os>
Also under the disk configuration,
<disk device="disk" type="network">
<driver cache="none" io="threads" name="qemu" type="raw" />
<source name="vm-2183/bootdisk-vm-2183" protocol="openvstorage" vdiskguid="d536d2c5-3aee-43bf-b3aa-a7cdd6bf8e51">
<host name="10.108.3.22" port="26203" transport="tcp" />
</source>
<!-- this should be added as well -->
<backingStore/>
<target dev='hda' bus='ide'/>
<alias name='ide0-0-0'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
<!-- until here -->
</disk>