# Create Windows VM Image from Scratch

This tutorial describes how to create and deploy Windows virtual machine images using Platform9.

Platform9 currently does not support creating a new virtual machine from scratch. You need to use the KVM utility called "Virtual Machine Manager" to do this. This tutorial goes over the process of creating a Windows virtual machine image from scratch using Virtual Machine Manager, and get it configured with cloud-init scripts. Once this is done, you can check the image into Platform9 image catalog. From that point onwards, any new virtual machines can be created using this image.

This tutorial uses Windows 2008 R2 evaluation version as an example.

### Step 1 - Get Prerequisites

Get the ISO Image for the Windows distribution you wish to deploy for the virtual machine. Microsoft makes a 180 days evaluation version of Windows 2008 R2 available. You can download it here [Windows 2008 R2 Evaluation Image](http://www.microsoft.com/en-us/download/details.aspx?id=11093)

Download the VirtIO driver ISO file for Windows from here: <https://fedoraproject.org/wiki/Windows_Virtio_Drivers#Direct_download>

Next step is to download the cloud-init installation package for Windows. Cloud-init is the de-facto multi-distribution package that handles early initialization of a cloud instance. For more information on cloud-init, read [here](https://cloudinit.readthedocs.org/en/latest/).

Download Cloudbase Cloud-init package for Windows here: <https://www.cloudbase.it/downloads/CloudbaseInitSetup_Beta_x64.msi>

Install Virtual Machine Manager on your Linux server that you plan to use to create this Windows virtual machine image.

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

```bash
sudo yum install virt-manager
{% endtab %}
{% tab language="bash" title="Ubuntu" %}
apt-get install virt-manager
```

{% endtab %}
{% endtabs %}

### Step 2 - Create Virtual Machine

With the prerequisites, now we are ready to start deploying the Windows virtual machine.

Create a new virtual machine using Virtual Machine Manager. Select the Local Install Media option for the operating system.

<figure><img src="https://1126553421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ8EciOmTwpkZCkUOCYd9%2Fuploads%2Fgit-blob-ab0f906b624ca6dcf90550c33c5db5e20fb9854d%2F1605292079.png?alt=media" alt=""><figcaption></figcaption></figure>

Select Windows for the operating system type and select the appropriate version.

<figure><img src="https://1126553421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ8EciOmTwpkZCkUOCYd9%2Fuploads%2Fgit-blob-585254d012396feceea72a41a2a36fdce31b3777%2F1605292101.png?alt=media" alt=""><figcaption></figcaption></figure>

Select appropriate options for number of CPUs and memory.

<figure><img src="https://1126553421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ8EciOmTwpkZCkUOCYd9%2Fuploads%2Fgit-blob-53db5272c40d053ccc8cdc1f8b81d11fc565971b%2F1605292140.png?alt=media" alt=""><figcaption></figcaption></figure>

Select at least 12 GB for disk size.

<figure><img src="https://1126553421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ8EciOmTwpkZCkUOCYd9%2Fuploads%2Fgit-blob-3d116674d0011e398fb3ac8e6ab7bf8fcf820ab6%2F1605292162.png?alt=media" alt=""><figcaption></figcaption></figure>

In the last option, make sure to select the "Customize configuration before install" option. This option will allow you to do advance changes to the disk and network device types before the virtual machine creation begins.

<figure><img src="https://1126553421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ8EciOmTwpkZCkUOCYd9%2Fuploads%2Fgit-blob-58a59584ef8c8506ec8aaf0d112a01a834f32b5f%2F1605292188.png?alt=media" alt=""><figcaption></figcaption></figure>

In the virtual machine configuration wizard that opens up next, select the disk, select Advance options and choose "Virtio" as the value for Disk bus.

<figure><img src="https://1126553421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ8EciOmTwpkZCkUOCYd9%2Fuploads%2Fgit-blob-2c42e8060c333b194cd5a018fc97df1c763621a7%2F1605292214.png?alt=media" alt=""><figcaption></figcaption></figure>

Next, select NIC, then under Device model: select "virtio".

<figure><img src="https://1126553421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ8EciOmTwpkZCkUOCYd9%2Fuploads%2Fgit-blob-15d16d5a680f0e9892f00bd6d6ed513a694a8999%2F1605292239.png?alt=media" alt=""><figcaption></figcaption></figure>

Finally, add two CDROM devices to the virtual machine. Attach the Windows ISO and the ISO for the VirtIO driver to those two CDROMs.

{% hint style="success" %}
**Tip**

You can do this with one CDROM too, but you will need to switch during installation
{% endhint %}

Now press "Begin Installation" and the standard Windows installation will begin.

### Step 3 - Install the Windows Operating System

During the installation, you will be prompted to load drivers for disk and network. Please load VirtIO storage and network drivers from the VirtIO ISO mounted on one of the CDROM.

Once installation completes, power on the virtual machine. Configure the operating system to **enable Remote Desktop Access**. Make sure to also change the Windows firewall setting to allow incoming RDP traffic.

Copy netkvm.\* from the virtio folder (win8/amd64/netkvm.\*) to c:windowsinf folder. This is the VIRTIO network driver. This step is necessary because sysprep can remove some non-standard drivers during generalization process.

(Optional) Download the SDelete utility from Windows Sysinternals here <http://technet.microsoft.com/en-us/sysinternals/bb897443.aspx> to clean up and zero fill unused disk space for the Virtual Machine.

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

```none
sdelete -z -c <drive letter>
```

{% endtab %}
{% endtabs %}

Finally, install and run the cloud-init package that we downloaded above. Pick the Network Adapter to be "Red Hat VirtIO Ethernet Adapter"

<figure><img src="https://1126553421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ8EciOmTwpkZCkUOCYd9%2Fuploads%2Fgit-blob-be2c0dd5d244d974b30bb06edaeec540c995f5ff%2F1605292300.png?alt=media" alt=""><figcaption></figcaption></figure>

At the end of cloud-init installation, you will be prompted to run Sysprep package to create a generalized image. Select this option as well as the option to shutdown the instance when Sysprep terminates.

<figure><img src="https://1126553421-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZ8EciOmTwpkZCkUOCYd9%2Fuploads%2Fgit-blob-b8b49dca6104ca750ef5f300bd59f1f4df26a820%2F1605292324.png?alt=media" alt=""><figcaption></figcaption></figure>

When Sysprep finishes running, the virtual machine will be shut down. At this point your Windows virtual machine creation is done! You can copy over the image to Platform9 Glance image catalog to get started.

{% hint style="info" %}
**Note**

Convert the virtual machine to qcow2 format to trim the physical size of the disk.
{% endhint %}
