Chapter 4. Cloning Virtual Machines There are two types of guest virtual machine instances used in creating guest copies: Clones are instances of a single virtual machine. Clones can be used to set up a network of identical virtual machines, and they can also be distributed to other destinations. Templates are instances of a virtual machine that are designed to be used as a source for cloning. You can create multiple clones from a template and make minor modifications to each clone. This is useful in seeing the effects of these changes on the system. Both clones and templates are virtual machine instances. The difference between them is in how they are used. For the created clone to work properly, information and configurations unique to the virtual machine that is being cloned usually has to be removed before cloning. The information that needs to be removed differs, based on how the clones will be used. The information and configurations to be removed may be on any of the following levels: Platform level information and configurations include anything assigned to the virtual machine by the virtualization solution. Examples include the number of Network Interface Cards (NICs) and their MAC addresses. Guest operating system level information and configurations include anything configured within the virtual machine. Examples include SSH keys. Application level information and configurations include anything configured by an application installed on the virtual machine. Examples include activation codes and registration information. Note This chapter does not include information about removing the application level, because the information and approach is specific to each application. As a result, some of the information and configurations must be removed from within the virtual machine, while other information and configurations must be removed from the virtual machine using the virtualization environment (for example, Virtual Machine Manager or VMware). Note For information on cloning storage volumes, see Section 13.3.2.1, "Creating Storage Volumes with virsh" . 4.1. Preparing Virtual Machines for Cloning Before cloning a virtual machine, it must be prepared by running the virt-sysprep utility on its disk image, or by using the following steps: Procedure 4.1. Preparing a virtual machine for cloning Setup the virtual machine Build the virtual machine that is to be used for the clone or template. Install any software needed on the clone. Configure any non-unique settings for the operating system. Configure any non-unique application settings. Remove the network configuration Remove any persistent udev rules using the following command: Note If udev rules are not removed, the name of the first NIC may be eth1 instead of eth0. Remove unique network details from ifcfg scripts by making the following edits to /etc/sysconfig/network-scripts/ifcfg-eth[x] : Remove the HWADDR and Static lines Note If the HWADDR does not match the new guest's MAC address, the ifcfg will be ignored. Therefore, it is important to remove the HWADDR from the file. Ensure that a DHCP configuration remains that does not include a HWADDR or any unique information. Ensure that the file includes the following lines: If the following files exist, ensure that they contain the same content: /etc/sysconfig/networking/devices/ifcfg-eth[x] /etc/sysconfig/networking/profiles/default/ifcfg-eth[x] Note If NetworkManager or any special settings were used with the virtual machine, ensure that any additional unique information is removed from the ifcfg scripts. Remove registration details Remove registration details using one of the following: For Red Hat Network (RHN) registered guest virtual machines, use the following command: For Red Hat Subscription Manager (RHSM) registered guest virtual machines: If the original virtual machine will not be used, use the following commands: If the original virtual machine will be used, run only the following command: The original RHSM profile remains in the Portal. To reactivate your RHSM registration on the virtual machine after it is cloned, do the following: Obtain your customer identity code: Register the virtual machine using the obtained ID code: Removing other unique details Remove any sshd public/private key pairs using the following command: Note Removing ssh keys prevents problems with ssh clients not trusting these hosts. Remove any other application-specific identifiers or configurations that may cause conflicts if running on multiple machines. Configure the virtual machine to run configuration wizards on the boot Configure the virtual machine to run the relevant configuration wizards the time it is booted by doing one of the following: For Red Hat Enterprise Linux 6 and below, create an empty file on the root file system called .unconfigured using the following command: For Red Hat Enterprise Linux 7, enable the first boot and initial-setup wizards by running the following commands: Note The wizards that run on the boot depend on the configurations that have been removed from the virtual machine. In addition, on the first boot of the clone, it is recommended that you change the hostname.

Commands:
rm -f /etc/udev/rules.d/70-persistent-net.rules
DEVICE=eth[x] BOOTPROTO=none ONBOOT=yes #NETWORK=10.0.1.0 <- REMOVE #NETMASK=255.255.255.0 <- REMOVE #IPADDR=10.0.1.20 <- REMOVE #HWADDR=xx:xx:xx:xx:xx <- REMOVE #USERCTL=no <- REMOVE Remove any other *unique* or non-desired settings, such as UUID.
DEVICE=eth[x] BOOTPROTO=dhcp ONBOOT=yes
DEVICE=eth[x] ONBOOT=yes
rm /etc/sysconfig/rhn/systemid
subscription-manager unsubscribe --all subscription-manager unregister subscription-manager clean
subscription-manager clean
subscription-manager identity subscription-manager identity: 71rd64fx-6216-4409-bf3a-e4b7c7bd8ac9
subscription-manager register --consumerid=71rd64fx-6216-4409-bf3a-e4b7c7bd8ac9
rm -rf /etc/ssh/ssh_host_*
touch /.unconfigured
sed -ie 's/RUN_FIRSTBOOT=NO/RUN_FIRSTBOOT=YES/' /etc/sysconfig/firstboot systemctl enable firstboot-graphical systemctl enable initial-setup-graphical