KVM virt-clone while the VM is running

8,477

If you don't care about in-memory data, you can snapshot the backing device and take a copy of that snapshot.

This of course require a storage pool with snapshot support (mostly LVM or ZFS, as BTRFS is abysmal slow for virtual machines storage).

Share:
8,477

Related videos on Youtube

zino
Author by

zino

Updated on September 18, 2022

Comments

  • zino
    zino over 1 year

    Is it possible to clone a running kvm machine without tools like virt-clone?

    They already have the original vm in production, I cannot shut it down. If I don't care about temporary data corruption (what an initial fsck can fix) on the clone, can I just cp the qcow image file to a new name, create a new vm definition which uses that disk and start the machine up?

    • c4f4t0r
      c4f4t0r about 9 years
      virt-clone --original slesp4 --name newsp4 ERROR Domain with devices to clone must be paused or shutoff.
    • imz -- Ivan Zakharyaschev
      imz -- Ivan Zakharyaschev almost 7 years
      virt-clone is also allowed after virsh suspend; perhaps, that won't count as a real shutdown for you.
    • keithpjolley
      keithpjolley over 3 years
      virt-clone no longer supports cloning suspended machines.
  • Christopher Perrin
    Christopher Perrin about 9 years
    Or copy the file if the storage is file based
  • shodanshok
    shodanshok about 9 years
    While surely you can copy a "running" image with a simple "cp", consistency will be thrown out of the window. With journaling filesystem this can lead to filesystem-wide corruption, so please do NOT use this method on production system.
  • shodanshok
    shodanshok about 9 years
    Interesting. Anyway, I would not risk data integrity and system stability installing a 3rd part module in a production server, especially considering how that module install itself in the uber important VFS layer.
  • Spooler
    Spooler over 7 years
    While a system will allow you to do this, this will profoundly corrupt any image that is in use. If it is in use, it must be at least almost entirely read-only for this to remotely succeed. I wouldn't recommend this method on any system. A good way to get around this would be to deploy a base Debain system of the same version, (so you get all of your bootloader and partitioning created for you, if you don't want to do that manually), and then using rsync within the original VM to copy the entire root filesystem into the new VM image, overwriting all but /etc/fstab and the whole boot directory.
  • Alex Berry
    Alex Berry about 7 years
    I like this solution. I would possibly add that you could momentarily remount filesystems as read-only on the server while taking the snapshot, then remount as rw after the snapshot is taken, though depending on the service this might break the "I can't shut it down" rule.