← 返回命令列表

Linux command

virt-clone 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Clone

virt-clone --original [vm_name] --auto-clone

Clone

virt-clone --original [vm_name] --name [new_vm_name] --file [path/to/new_disk.qcow2]

Clone

virt-clone --original [vm_name] --name [new_vm_name] --auto-clone --mac RANDOM

Clone and replace

virt-clone --original [vm_name] --name [new_vm_name] --auto-clone --replace

Clone without copying storage

virt-clone --original [vm_name] --name [new_vm_name] --preserve-data

Print the generated clone XML

virt-clone --original [vm_name] --auto-clone --print-xml

说明

virt-clone creates a copy of an existing libvirt virtual machine. It clones the VM configuration and can duplicate or create new disk images, generating unique identifiers for the clone. The tool handles creating new UUIDs, MAC addresses, and storage paths to avoid conflicts with the original VM. It is commonly used for creating test environments or deploying multiple similar VMs. Disks marked as readonly or shareable are skipped by default unless --force-copy is used.

参数

-o, --original _name_
Name of the original VM to clone (must be shut off).
--original-xml _file_
Libvirt guest XML file to use as the original guest.
-n, --name _name_
Name for the new cloned VM.
--auto-clone
Automatically generate new name, storage, and MAC.
-f, --file _path_
Path for the new disk image. Repeat for multi-disk guests.
-m, --mac _address_
MAC address for the new VM (or RANDOM).
-u, --uuid _uuid_
UUID for the new guest (default: randomly generated).
--preserve-data
Do not clone storage; preserve disk images and reference them.
--reflink
Use copy-on-write reflinks if the filesystem supports it.
--nonsparse
Fully allocate new storage instead of creating sparse files.
--force-copy _target_
Force cloning of the specified disk target (e.g. 'hdc', 'sda').
--replace
Shut down and remove any existing guest with the target name.
--print-xml
Print generated clone XML and exit without cloning.
-c, --connect _uri_
Connect to specified hypervisor URI.
-d, --debug
Print debugging information.

FAQ

What is the virt-clone command used for?

virt-clone creates a copy of an existing libvirt virtual machine. It clones the VM configuration and can duplicate or create new disk images, generating unique identifiers for the clone. The tool handles creating new UUIDs, MAC addresses, and storage paths to avoid conflicts with the original VM. It is commonly used for creating test environments or deploying multiple similar VMs. Disks marked as readonly or shareable are skipped by default unless --force-copy is used.

How do I run a basic virt-clone example?

Run `virt-clone --original [vm_name] --auto-clone` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -o, --original _name_ do in virt-clone?

Name of the original VM to clone (must be shut off).