KVM Live Migration without Shared Storage

KVM Guest VM Live Migration without Share Storage -----

Prerequisites -----

> Ruining Guest virtual machine on one of the KVM Host server.
> Both the KVM Host servers are able accessible each other.
> 1 Gbps Network configured on both the Host servers
> Longing to the host servers with root user or normal user have sudo rights.
> Make sure ssh service port is enabled on both the host and firewall.


Steps to migrate gust vm -----

> Assume Guest VM runing on KVM Host1 ( I have give cls1 hostname to KVM Host1 and cls2 hostname to KVM Host 2 )
List the virtual machines ruining on cls1 server.
Command :- #virsh list         ----- This command display the runing virtual machines on the host

Name :- virt1     ----- This is ruining virtual machine
ID :-  1               ----- This is first virtual machine on the host.



> Check the virtual machine size.
Note :- In this scenario I have used default storage path /var/lib/libvirt/images

Command :- #cd /var/lib/libvirt/images               ----- Go to images directory
                       #ls -l                                                ----- Check the list and size of the virtual machines

Keep the following information of virtual machine those are going to be migrate to another host server.
Size of the virtual machine ( 12884901888 ) and .img file name ( virt1.img )


> Create image file with the same name virt1.img and same file size 1288490188 on another host server (cls2)

Command :- #cd /var/lib/libvirt/images                               ----- Go to images directory

                      #follocate -l 12884901888 /var/lib/libvirt/images/virt1.img     ----- Create image file


> Run the list command on cls2 host server to confirm file is created with the same size
Command :-#cd /var/lib/libvirt/images
                     #ls -l


> Now go to cls1 server and run the following command to migrate virtual machine to cls2 host server.
Command :- #virsh migrate --live --copy-storage-all virt1 qemu+ssh://198.19.99.142/system
virt1 :- Virtual machine name for migration
198.19.99.142 :- KVM host server ip where virtual machine will be ruining after live migration


> Once the virtual machine migrated to another host. Run the following command on cls1 host server.

Command :- #virsh list
Virtual machine virt1 no listed in the list.

             ID         Name                                         State
             ----------------------------------------------------------------------

> Run the following command on cls2 host server to check the migrated virtual machine status.
Command :- #virsh list
  virt1 virtual machine running on the second host cls2 server now.




EOF

Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Hi why I'm getting an error: Unable to get index for interface p3p1: No such device. My 2 KVM servers are connected thru switch. Thanks

    ReplyDelete
  4. Thanks for great post. Can you fix the typo: follocate to fallocate.

    ReplyDelete
  5. Thanks for great post.

    I'd like to use this to migrate my virtual environment from my desktop to notebook.
    Unfortunately my VM images are all in .qcow2 format and during "virsh migrate" i recieve the error:
    qemu-system-x86_64: -drive file=/var/lib/libvirt/images/myVM.qcow2,if=none,id=drive-ide0-0-0,format=qcow2: could not open disk image /var/lib/libvirt/images/myVM.qcow2: Image is not in qcow2 format

    is there any workaround for this?

    Thanks

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. Hi Frits,

      I am kind of new to Ubuntu & Virtualization. I was doing a live migration and got stuck with the same error as pointed out by mk-maddin, could you please elaborate on how to create and empty qcow2 container and fix the migration. Also is it possible to measure the time taken for the whole migration ?

      Delete
    3. I'm also using qcow2 and solved this as follows:

      Instead of fallocate, I had to use truncate -s 288490188 virt1.qcow2
      Then, I converted it to a qcow2 container: qemu-img convert -f raw - qcow2 virt1.qcow2 virt1.qcow2
      After that, the live migration works.

      You can also directly create the empty qcow2 container by typing: qemu-img create -f qcow2 -o preallocation=metadata /storage/pool/path/virt1.qcow2 10739318784

      Delete
    4. Use the time command for measure the time taken for the migration.. Simply put time before the command. (e.g. time virsh migrate --live........)

      Delete
  6. Thank you for this article! :)

    I just migrated a running vm withing a qcow2 container, which works fine.
    Unfortunately, the whole disk is transferred. My container has a size of 10 GB. But only 3GB of data is used. Is there a way to prevent transferring the whole 10 GB?

    ReplyDelete
    Replies
    1. error: Cannot recv data: ssh: connect to host 198.168.79.129 port 22: Connection refused: Connection reset by peer

      Delete
    2. what command you have execute to migrate

      Delete
  7. error: internal error: unable to execute QEMU command 'migrate': this feature or command is not currently supported
    hi my error please help me

    ReplyDelete

Post a Comment

Popular posts from this blog

Create CentOS 6 Local package and Group package Repository

Create Linux ( LUCI ) Cluster