Using Templates
Now that you know how to create a virtual machine, you can save its settings into a template. This template will retain the original virtual machine's configurations, including virtual disk and network interface settings, operating systems and applications. You can use this template to rapidly create replicas of the original virtual machine.
Create a Fedora Template
To make a Fedora virtual machine template, use the virtual machine you created in Section 4.1.1, “Create a Fedora Virtual Machine” as a basis. Before it can be used, it has to be sealed. This ensures that machine-specific settings are not propagated through the template.
To prepare a Fedora virtual machine for use as a template
连接到一个已经存在的虚拟机, 需要配置一下, 然后关机才能作为模板使用. 例如touch一个重新配置文件, 删除ssh host key.
1. Connect to the Fedora virtual machine to be used as a template. Flag the system for re-configuration by running the following command as root:
# touch /.unconfigured
2. Remove ssh host keys. Run:
# rm -rf /etc/ssh/ssh_host_*
3. Shut down the virtual machine. Run:
# poweroff
4. The virtual machine has now been sealed, and is ready to be used as a template for Linux virtual machines.
关闭虚拟机后, 创建模板
To create a template from a Fedora virtual machine
1. In the administration portal, click the Virtual Machines tab. Select the sealed Red Hat Enterprise Linux 6 virtual machine. Ensure that it has a status of Down.
2. Click Make Template. The New Virtual Machine Template displays.
- Enter information into the following fields:
-
- Name: Name of the new template
- Description: Description of the new template
- Host Cluster: The Host Cluster for the virtual machines using this template.
- Make Private: If you tick this checkbox, the template will only be available to the template's creator and the administrative user. Nobody else can use this template unless they are given permissions by the existing permitted users.
3. Click OK. The virtual machine displays a status of "Image Locked" while the template is being created. The template is created and added to the Templates tab. During this time, the action buttons for the template remain disabled. Once created, the action buttons are enabled and the template is ready for use.
Clone a Red Hat Enterprise Linux Virtual Machine
In the previous section, you created a Fedora template complete with pre-configured storage, networking and operating system settings. Now, you will use this template to deploy a pre-installed virtual machine.
To clone a Fedora virtual machine from a template
新建虚拟机, 选择基于模板.
1. Navigate to the Tree pane and click Expand All. Click the VMs icon under the Default cluster. On the Virtual Machines tab, click New Server.
-
- On the General tab, select the existing Linux template from the Based on Template list.
- Enter a suitable Name and appropriate Description, then accept the default values inherited from the template in the rest of the fields. You can change them if needed.
- Click the Resource Allocation tab. On the Provisioning field, click the drop down menu and select the Clone option.
- 注意使用Clone选项.
2. Retain all other default settings and click OK to create the virtual machine. The virtual machine displays in the Virtual Machines list.