VIRT-CLONE(1)

VIRT-CLONE(1) πŸ’–

okay bestie, welcome to the Virtualization Support corner of the manual, where we talk about virt-clone ✨


🌸 NAME 🌸

virt-clone β€” clone existing virtual machine images πŸ¦‹


✨ SYNOPSIS ✨

virt-clone [OPTION]...

πŸ’… DESCRIPTION πŸ’…

So virt-clone is a command line tool for cloning existing virtual machine images, and it does that using the libvirt hypervisor management library. It will copy the disk images of any existing virtual machine, and define a new guest with an identical virtual hardware configuration. The elements that need to be unique get updated so old guest and new guest don't clash, periodt πŸ‘‘

By default, virt-clone will show an error if the necessary information to clone the guest is not provided. But the --auto-clone option will generate all needed input, aside from the source guest to clone. iconic behaviour honestly πŸŽ€

Please note, virt-clone does not change anything _inside_ the guest OS β€” it only duplicates disks and does host side changes. So things like changing passwords, changing static IP address, etc are outside the scope of this tool 😭 For these types of changes, please see virt-sysprep.

🫢 GENERAL OPTIONS 🫢

Most options are not required. Minimum requirements are --original or --original-xml (to specify the guest to clone), --name, and appropriate storage options via -file 🌈

  • --connect URI β€” connect to a non-default hypervisor. See virt-install(1) for details πŸ’«
  • -o, --original ORIGINAL_GUEST β€” name of the original guest to be cloned. This guest must be shut off πŸ’€
  • --original-xml ORIGINAL_XML β€” libvirt guest xml file to use as the original guest. The guest does not need to be defined on the libvirt connection. This takes the place of the --original parameter 🌸
  • --auto-clone β€” generate a new guest name, and paths for new storage ✨

An example of possible generated output:

Original name        : MyVM
Generated clone name : MyVM-clone

Original disk path   : /home/user/foobar.img
Generated disk path  : /home/user/foobar-clone.img

If generated names collide with existing VMs or storage, a number is appended, such as foobar-clone-1.img, or MyVM-clone-3 πŸ”’

  • -n, --name NAME β€” name of the new guest virtual machine instance. This must be unique amongst all guests known to the hypervisor connection, including those not currently active πŸ‘‘
  • -u, --uuid UUID β€” UUID for the guest; if none is given a random UUID will be generated. If you specify UUID, you should use a 32-digit hexadecimal number. UUID are intended to be unique across the entire data center, and indeed world 🌍 Bear this in mind if manually specifying a UUID πŸ™ˆ
  • -f, --file PATH β€” path to the file, disk partition, or logical volume to use as the backing store for the new guest's virtual disk. If the original guest has multiple disks, this parameter must be repeated multiple times, once per disk in the original virtual machine πŸ’Ύ
  • --nvram NVRAMFILE β€” optional path to the new nvram VARS file. If no path is specified and the guest has nvram, the new nvram path will be auto-generated. If the guest doesn't have nvram this option will be ignored 🧚
  • --force-copy TARGET β€” force cloning the passed disk target ('hdc', 'sda', etc.). By default, virt-clone will skip certain disks, such as those marked 'readonly' or 'shareable' πŸ”₯
  • --skip-copy TARGET β€” skip cloning the passed disk target ('hdc', 'sda', etc.). By default, virt-clone will clone certain disk images, typically read/write devices. Use this to skip copying of a specific device, so the new VM uses the same storage path as the original VM 🚫
  • --nonsparse β€” fully allocate the new storage if the path being cloned is a sparse file. See virt-install(1) for more details on sparse vs. nonsparse πŸ“
  • --preserve-data β€” no storage is cloned: disk images specified by --file are preserved as is, and referenced in the new clone XML. This is useful if you want to clone a VM XML template, but not the storage contents πŸ’œ
  • --reflink β€” perform a lightweight copy. This is much faster if source images and destination images are all on the same btrfs filesystem. This only works for raw format disk images, any non-raw images will not attempt to use refink ⚑
  • -m, --mac MAC β€” fixed MAC address for the guest; if this parameter is omitted, or the value RANDOM is specified, a suitable address will be randomly generated. Addresses are applied sequentially to the networks as they are listed in the original guest XML 🌐
  • --print-xml β€” print the generated clone XML and exit without cloning πŸ“
  • --replace β€” before cloning, try a simple virsh destroy and virsh undefine on any existing VM with the passed --name. If those operations fail (like when virsh undefine requires --nvram flag), the clone will fail and you will need to manually remove the existing VM πŸ’€
  • -h, --help β€” show the help message and exit πŸ™‹
  • --version β€” show program's version number and exit 🏷️
  • --check β€” enable or disable some validation checks. See virt-install(1) for more details βœ…
  • -q, --quiet β€” suppress non-error output 🀫
  • -d, --debug β€” print debugging information to the terminal when running the install process. The debugging information is also stored in ~/.cache/virt-manager/virt-clone.log even if this parameter is omitted πŸ›

🌈 EXAMPLES 🌈

Clone the guest called demo on the default connection, auto generating a new name and disk clone path πŸ¦‹

# virt-clone \
     --original demo \
     --auto-clone

Clone the guest called demo which has a single disk to copy πŸ’Ώ

# virt-clone \
     --original demo \
     --name newdemo \
     --file /var/lib/xen/images/newdemo.img

Clone a QEMU guest with multiple disks πŸ—‚οΈ

# virt-clone \
     --connect qemu:///system \
     --original demo \
     --name newdemo \
     --file /var/lib/xen/images/newdemo.img \
     --file /var/lib/xen/images/newdata.img

Clone a guest to a physical device which is at least as big as the original guests disks. If the destination device is bigger, the new guest can do a filesystem resize when it boots πŸ’ͺ

# virt-clone \
     --connect qemu:///system \
     --original demo \
     --name newdemo \
     --file /dev/HostVG/DemoVM \
     --mac 52:54:00:34:11:54

πŸ› BUGS πŸ›

Please see <https://virt-manager.org/bugs> β€” go tell them everything bestie, they wanna know πŸ’Œ


Copyright (C) Fujitsu Limited, Copyright (C) Red Hat, Inc, and various contributors. This is free software. You may redistribute copies of it under the terms of the GNU General Public License <https://www.gnu.org/licenses/gpl.html>. There is NO WARRANTY, to the extent permitted by law ⚠️


🌟 SEE ALSO 🌟

virt-sysprep(1), virsh(1), virt-install(1), virt-manager(1), the project website <https://virt-manager.org> πŸ”—


and that's the whole page, no cap 🫢 this was Virtualization Support's virt-clone(1) β€” thanks for reading bestie, go clone something cute, mwah πŸ’–πŸŽ€βœ¨