This is a cache of https://docs.okd.io/4.14/virt/virtual_machines/creating_vms_custom/virt-creating-vms-uploading-images.html. It is a snapshot of the page at 2024-11-25T06:44:12.149+0000.
Creating VMs by uploading images - Virtual machines | Virtualization | OKD 4.14
×

You can create virtual machines (VMs) by uploading operating system images from your local machine.

You can create a Windows VM by uploading a Windows image to a PVC. Then you clone the PVC when you create the VM.

You must install the QEMU guest agent on VMs created from operating system images that are not provided by Red Hat.

You must also install VirtIO drivers on Windows VMs.

Creating a VM from an uploaded image by using the web console

You can create a virtual machine (VM) from an uploaded operating system image by using the OKD web console.

Prerequisites
  • You must have an IMG, ISO, or QCOW2 image file.

Procedure
  1. Navigate to VirtualizationCatalog in the web console.

  2. Click a template tile without an available boot source.

  3. Click Customize VirtualMachine.

  4. On the Customize template parameters page, expand Storage and select Upload (Upload a new file to a PVC) from the Disk source list.

  5. Browse to the image on your local machine and set the disk size.

  6. Click Customize VirtualMachine.

  7. Click Create VirtualMachine.

Creating a Windows VM

You can create a Windows virtual machine (VM) by uploading a Windows image to a persistent volume claim (PVC) and then cloning the PVC when you create a VM by using the OKD web console.

Prerequisites
Procedure
  1. Upload the Windows image as a new PVC:

    1. Navigate to StoragePersistentVolumeClaims in the web console.

    2. Click Create PersistentVolumeClaimWith Data upload form.

    3. Browse to the Windows image and select it.

    4. Enter the PVC name, select the storage class and size and then click Upload.

      The Windows image is uploaded to a PVC.

  2. Configure a new VM by cloning the uploaded PVC:

    1. Navigate to VirtualizationCatalog.

    2. Select a Windows template tile and click Customize VirtualMachine.

    3. Select Clone (clone PVC) from the Disk source list.

    4. Select the PVC project, the Windows image PVC, and the disk size.

  3. Apply the answer file to the VM:

    1. Click Customize VirtualMachine parameters.

    2. On the Sysprep section of the Scripts tab, click Edit.

    3. Browse to the autounattend.xml answer file and click Save.

  4. Set the run strategy of the VM:

    1. Clear Start this VirtualMachine after creation so that the VM does not start immediately.

    2. Click Create VirtualMachine.

    3. On the YAML tab, replace running:false with runStrategy: RerunOnFailure and click Save.

  5. Click the options menu kebab and select Start.

    The VM boots from the sysprep disk containing the autounattend.xml answer file.

Generalizing a Windows VM image

You can generalize a Windows operating system image to remove all system-specific configuration data before you use the image to create a new virtual machine (VM).

Before generalizing the VM, you must ensure the sysprep tool cannot detect an answer file after the unattended Windows installation.

Prerequisites
  • A running Windows VM with the QEMU guest agent installed.

Procedure
  1. In the OKD console, click VirtualizationVirtualMachines.

  2. Select a Windows VM to open the VirtualMachine details page.

  3. Click ConfigurationDisks.

  4. Click the Options menu kebab beside the sysprep disk and select Detach.

  5. Click Detach.

  6. Rename C:\Windows\Panther\unattend.xml to avoid detection by the sysprep tool.

  7. Start the sysprep program by running the following command:

    %WINDIR%\System32\Sysprep\sysprep.exe /generalize /shutdown /oobe /mode:vm
  8. After the sysprep tool completes, the Windows VM shuts down. The disk image of the VM is now available to use as an installation image for Windows VMs.

You can now specialize the VM.

Specializing a Windows VM image

Specializing a Windows virtual machine (VM) configures the computer-specific information from a generalized Windows image onto the VM.

Prerequisites
  • You must have a generalized Windows disk image.

  • You must create an unattend.xml answer file. See the Microsoft documentation for details.

Procedure
  1. In the OKD console, click VirtualizationCatalog.

  2. Select a Windows template and click Customize VirtualMachine.

  3. Select PVC (clone PVC) from the Disk source list.

  4. Select the PVC project and PVC name of the generalized Windows image.

  5. Click Customize VirtualMachine parameters.

  6. Click the Scripts tab.

  7. In the Sysprep section, click Edit, browse to the unattend.xml answer file, and click Save.

  8. Click Create VirtualMachine.

During the initial boot, Windows uses the unattend.xml answer file to specialize the VM. The VM is now ready to use.

Creating a VM from an uploaded image by using the command line

You can upload an operating system image by using the virtctl command line tool. You can use an existing data volume or create a new data volume for the image.

Prerequisites
  • You must have an ISO, IMG, or QCOW2 operating system image file.

  • For best performance, compress the image file by using the virt-sparsify tool or the xz or gzip utilities.

  • You must have virtctl installed.

  • The client machine must be configured to trust the OKD router’s certificate.

Procedure
  1. Upload the image by running the virtctl image-upload command:

    $ virtctl image-upload dv <datavolume_name> \ (1)
      --size=<datavolume_size> \ (2)
      --image-path=</path/to/image> \ (3)
    1 The name of the data volume.
    2 The size of the data volume. For example: --size=500Mi, --size=1G
    3 The file path of the image.
    • If you do not want to create a new data volume, omit the --size parameter and include the --no-create flag.

    • When uploading a disk image to a PVC, the PVC size must be larger than the size of the uncompressed virtual disk.

    • To allow insecure server connections when using HTTPS, use the --insecure parameter. When you use the --insecure flag, the authenticity of the upload endpoint is not verified.

  2. Optional. To verify that a data volume was created, view all data volumes by running the following command:

    $ oc get dvs