# Create a Windows Image from an ISO

This guide provides step-by-step instructions for creating a Windows VM using an ISO.

This method creates a Windows VM image on an Ubuntu machine first, using the ISO, then creates a virtual machine using that image. If you'd like a more direct recipe to create a Windows VM from an ISO, follow [this tutorial instead.](https://docs.platform9.com/private-cloud-director/tutorials/create-windows-vm-from-iso/creating-a-windows-virtual-machine--vm--from-an-iso-image)

## Prerequisites

* A Ubuntu 22.04 host - we will use this to prepare the Windows image using the ISO.
* GUI access for the Ubuntu machine is required to follow the Windows installation prompts.
* A Windows ISO image

## Step 1: Download the Stable VirtIO Driver ISO

Windows requires VirtIO drivers for better performance on a Linux (QEMU-KVM) hypervisor. Download the latest stable VirtIO driver ISO on your Ubuntu host by running the following command:

{% tabs %}
{% tab title="Bash" %}

```bash
wget 'https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso' -O virtio.iso
```

{% endtab %}
{% endtabs %}

This ISO contains drivers for storage, networking, and other virtual devices required during the Windows installation process.

## Step 2: Install Required Packages

Install QEMU-KVM, TPM emulator, and other required packages on the Ubuntu host machine.

{% tabs %}
{% tab title="Bash" %}

```bash
sudo apt update && sudo apt install qemu-kvm swtpm swtpm-tools
```

{% endtab %}
{% endtabs %}

* `qemu-kvm`: Virtual machine manager.
* `swtpm`, `swtpm-tools`: Software TPM emulator for Windows security features.

## Step 3: Start the TPM Emulator

Windows 11 requires a TPM. Create a directory for the TPM emulator on your host:

{% tabs %}
{% tab title="Bash" %}

```bash
mkdir -p /tmp/emulated_tpm
```

{% endtab %}
{% endtabs %}

This directory will be used to store TPM-related files required for Windows installation.

Now run the following command on the host to start the TPM emulator in the background or a separate terminal.

{% tabs %}
{% tab title="Bash" %}

```bash
sudo swtpm socket --tpmstate dir=/tmp/emulated_tpm --ctrl type=unixio,path=/tmp/emulated_tpm/swtpm-sock --log level=20 --tpm2 --daemon
```

{% endtab %}
{% endtabs %}

This command initializes a TPM 2.0 emulation environment needed for Windows installation.

## Step 4: Create a Blank qcow2 Disk Image

Now create a `qcow2` disk image on the Ubuntu host. We will use this for Windows installation.

{% tabs %}
{% tab title="Bash" %}

```bash
qemu-img create -f qcow2 <VIRTUAL_DISK_FILE_NAME> <VIRTUAL_DISK_SIZE>
```

{% endtab %}
{% endtabs %}

* `VIRTUAL_DISK_FILE_NAME`: Name of the virtual disk file.
* `VIRTUAL_DISK_SIZE`: Size of the disk (adjust as needed).

## Step 5: Start the Windows Installation

Now use QEMU to start the installation process on the host, using the Windows ISO.

{% tabs %}
{% tab title="Bash" %}

```bash
sudo qemu-system-x86_64 -cdrom test.iso -cpu Skylake-Client-v3 -enable-kvm -m 4096 \
    --chardev socket,id=chrtpm,path=/tmp/emulated_tpm/swtpm-sock \
    -tpmdev emulator,id=tpm0,chardev=chrtpm \
    -device tpm-tis,tpmdev=tpm0 -smp 2 -device intel-hda -device hda-duplex -usb \
    -nic user,ipv6=off,model=rtl8139,mac=84:1b:77:c9:03:a6 -bios /usr/share/ovmf/OVMF.fd \
    -drive if=virtio,file=win11,format=qcow2 -drive file=virtio.iso,index=1,media=cdrom
```

{% endtab %}
{% endtabs %}

* `-cdrom test.iso`: Mounts the Windows installation ISO.
* `-cpu Skylake-Client-v3 -enable-kvm`: Enables hardware acceleration.
* `-m 4096`: Allocates 4GB RAM to the VM.
* `-smp 2`: Allocates 2 CPU cores.
* `-device tpm-tis,tpmdev=tpm0`: Enables TPM 2.0 emulation.
* `-drive if=virtio,file=win11,format=qcow2`: Attaches the previously created disk.
* `-drive file=virtio.iso,index=1,media=cdrom`: Mounts the VirtIO driver ISO.

## Step 6: Install VirtIO Drivers During Windows Setup

During installation:

* Click Load Drivers when prompted.
* Browse to the mounted VirtIO ISO and select the appropriate drivers.
* Proceed with the installation.

## Step 7: Shut down the VM and Prepare for Deployment

Once the Windows installation is complete, shut down the VM.

The Windows image is now ready for use within <code class="expression">space.vars.product\_name</code>.

## Uploading the Image

To deploy the image in <code class="expression">space.vars.product\_name</code>:

* Make sure the image is in `qcow2` format for <code class="expression">space.vars.product\_name</code> use.
* Upload the image using <code class="expression">space.vars.product\_name</code> Image Library UI or CLI. Follow [Import Images into Image Library](https://docs.platform9.com/private-cloud-director/virtualized-clusters/image-library---images#import-images-into-image-library) for steps to upload the image.
