Skip to content

Commit 2a57938

Browse files
authored
Merge pull request #81924 from MirzWeiss/CNV-39643
CNV-39643: Document generlizing a Linux VM
2 parents 230e6dd + 71e201e commit 2a57938

File tree

4 files changed

+112
-0
lines changed

4 files changed

+112
-0
lines changed

_topic_maps/_topic_map_rosa.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,8 @@ Topics:
18121812
File: virt-creating-vms-from-web-images
18131813
- Name: Creating VMs by uploading images
18141814
File: virt-creating-vms-uploading-images
1815+
- Name: Cloning VMs
1816+
File: virt-cloning-vms
18151817
- Name: Creating VMs by cloning PVCs
18161818
File: virt-creating-vms-by-cloning-pvcs
18171819
- Name: Installing the QEMU guest agent and VirtIO drivers

_topic_maps/_topic_map_rosa_hcp.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,6 +1730,8 @@ Topics:
17301730
# File: virt-creating-vms-from-web-images
17311731
# - Name: Creating VMs by uploading images
17321732
# File: virt-creating-vms-uploading-images
1733+
# - Name: Cloning VMs
1734+
# File: virt-cloning-vms
17331735
# - Name: Creating VMs by cloning PVCs
17341736
# File: virt-creating-vms-by-cloning-pvcs
17351737
# - Name: Installing the QEMU guest agent and VirtIO drivers
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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.

virt/virtual_machines/creating_vms_custom/virt-creating-vms-uploading-images.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ You must also install xref:../../../virt/virtual_machines/creating_vms_custom/vi
1919

2020
include::modules/virt-creating-vm-uploaded-image-web.adoc[leveloffset=+1]
2121

22+
include::modules/virt-generalizing-linux-vm-image.adoc[leveloffset=+2]
23+
24+
[role="_additional-resources"]
25+
[id="additional-resources-generalizing-linux-vms"]
26+
.Additional resources for generalizing VMs
27+
* xref:../../../virt/virtual_machines/creating_vms_custom/virt-cloning-vms.adoc#virt-cloning-vms[Cloning VMs]
28+
* xref:../../../virt/virtual_machines/creating_vms_custom/virt-creating-vms-by-cloning-pvcs.adoc#virt-cloning-pvc-to-dv-cli_virt-creating-vms-by-cloning-pvcs[Cloning a PVC to a data volume]
29+
2230
include::modules/virt-creating-windows-vm.adoc[leveloffset=+1]
2331

2432
include::modules/virt-generalizing-windows-sysprep.adoc[leveloffset=+2]

0 commit comments

Comments
 (0)