|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * virt/virtual_machines/creating_vms_custom/virt-creating-vms-uploading-images.adoc |
| 4 | + |
| 5 | +:_mod-docs-content-type: PROCEDURE |
| 6 | +[id="virt-generalizing-linux-vm-image_{context}"] |
| 7 | += Generalizing a VM image |
| 8 | + |
| 9 | +You can generalize a {op-system-base-full} image to remove all system-specific configuration data before you use the image to create a golden image, a preconfigured snapshot of a virtual machine (VM). You can use a golden image to deploy new VMs. |
| 10 | + |
| 11 | +You can generalize a {op-system-base} VM by using the `virtctl`, `guestfs`, and `virt-sysprep` tools. |
| 12 | + |
| 13 | +.Prerequisites |
| 14 | + |
| 15 | +* You have a {op-system-base} virtual machine (VM) to use as a base VM. |
| 16 | +* You have installed the OpenShift CLI (`oc`). |
| 17 | +* You have installed the `virtctl` tool. |
| 18 | +
|
| 19 | +.Procedure |
| 20 | + |
| 21 | +. Stop the {op-system-base} VM if it is running, by entering the following command: |
| 22 | ++ |
| 23 | +[source,terminal] |
| 24 | +---- |
| 25 | +$ virtctl stop <my_vm_name> |
| 26 | +---- |
| 27 | + |
| 28 | +. Optional: Clone the virtual machine to avoid losing the data from your original VM. You can then generalize the cloned VM. |
| 29 | + |
| 30 | +. Retrieve the `dataVolume` that stores the root filesystem for the VM by running the following command: |
| 31 | ++ |
| 32 | +[source,terminal] |
| 33 | +---- |
| 34 | +$ oc get vm <my_vm_name> -o jsonpath="{.spec.template.spec.volumes}{'\n'}" |
| 35 | +---- |
| 36 | ++ |
| 37 | +.Example output |
| 38 | +[source,terminal] |
| 39 | +---- |
| 40 | +[{"dataVolume":{"name":"<my_vm_volume>"},"name":"rootdisk"},{"cloudInitNoCloud":{...}] |
| 41 | +---- |
| 42 | + |
| 43 | +. Retrieve the persistent volume claim (PVC) that matches the listed `dataVolume` by running the followimg command: |
| 44 | ++ |
| 45 | +[source,terminal] |
| 46 | +---- |
| 47 | +$ oc get pvc |
| 48 | +---- |
| 49 | ++ |
| 50 | +.Example output |
| 51 | +[source,terminal] |
| 52 | +---- |
| 53 | +NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE |
| 54 | +<my_vm_volume> Bound … |
| 55 | +---- |
| 56 | ++ |
| 57 | +[NOTE] |
| 58 | +==== |
| 59 | +If your cluster configuration does not enable you to clone a VM, to avoid losing the data from your original VM, you can clone the VM PVC to a data volume instead. You can then use the cloned PVC to create a golden image. |
| 60 | +
|
| 61 | +If you are creating a golden image by cloning a PVC, continue with the next steps, using the cloned PVC. |
| 62 | +==== |
| 63 | + |
| 64 | +. Deploy a new interactive container with `libguestfs-tools` and attach the PVC to it by running the following command: |
| 65 | ++ |
| 66 | +[source,terminal] |
| 67 | +---- |
| 68 | +$ virtctl guestfs <my-vm-volume> --uid 107 |
| 69 | +---- |
| 70 | ++ |
| 71 | +This command opens a shell for you to run the next command. |
| 72 | + |
| 73 | +. Remove all configurations specific to your system by running the following command: |
| 74 | ++ |
| 75 | +[source,terminal] |
| 76 | +---- |
| 77 | +$ virt-sysprep -a disk.img |
| 78 | +---- |
| 79 | + |
| 80 | +. In the {product-title} console, click *Virtualization* -> *Catalog*. |
| 81 | + |
| 82 | +. Click *Add volume*. |
| 83 | + |
| 84 | +. In the *Add volume* window: |
| 85 | + |
| 86 | +.. From the *Source type* list, select *Use existing Volume*. |
| 87 | + |
| 88 | +.. From the *Volume project* list, select your project. |
| 89 | + |
| 90 | +.. From the *Volume name* list, select the correct PVC. |
| 91 | + |
| 92 | +.. In the *Volume name* field, enter a name for the new golden image. |
| 93 | + |
| 94 | +.. From the *Preference* list, select the {op-system-base} version you are using. |
| 95 | + |
| 96 | +.. From the *Default Instance Type* list, select the instance type with the correct CPU and memory requirements for the version of {op-system-base} you selected previously. |
| 97 | + |
| 98 | +.. Click *Save*. |
| 99 | + |
| 100 | +The new volume appears in the *Select volume to boot from* list. This is your new golden image. You can use this volume to create new VMs. |
0 commit comments