Skip to content

Instantly share code, notes, and snippets.

@plembo
Last active August 29, 2022 14:52
Show Gist options
  • Save plembo/ce0c3714e77b67f6bfc32fc5da8bc22c to your computer and use it in GitHub Desktop.
Save plembo/ce0c3714e77b67f6bfc32fc5da8bc22c to your computer and use it in GitHub Desktop.
Using virt-clone

Using virt-clone

The virt-clone utility is a useful tool for rapidly reproducing KVM (libvirtd) virtual machines.

Basic command to clone an existing virtual machine:

$ sudo virt-clone \
--original debian1 \
--name debian2 \
--file /var/lib/libvirt/images/debian2.qcow2

Once the clone has been created, the following commands can be used to rename it and reset values like the hostname and ssh keys. Log into the guest machine and su to root:

# echo 'debian2' > /etc/hostname
# sed -i 's/debian1/debian2/g' /etc/hosts
# reboot
# /bin/rm -v /etc/ssh/ssh_host_*
# dpkg-reconfigure openssh-server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment