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).
Related videos on Youtube
Author by
zino
Updated on September 18, 2022Comments
-
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 about 9 yearsvirt-clone --original slesp4 --name newsp4 ERROR Domain with devices to clone must be paused or shutoff.
-
imz -- Ivan Zakharyaschev almost 7 years
virt-clone
is also allowed aftervirsh suspend
; perhaps, that won't count as a real shutdown for you. -
keithpjolley over 3 years
virt-clone
no longer supports cloning suspended machines.
-
-
Christopher Perrin about 9 yearsOr copy the file if the storage is file based
-
shodanshok about 9 yearsWhile 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 about 9 yearsInteresting. 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 over 7 yearsWhile 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 about 7 yearsI 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.