– By Dwane Pottratz, Senior Solutions Architect at ORock Technologies –

When transitioning to the cloud, one of the first things that a software engineer runs into is the need for a cloud-friendly image. This blog will address how you can create cloud-friendly images for windows. While there are a lot of cloud-friendly images for Linux Distros, there are precious few for windows.

What is a cloud-friendly image?

A cloud-friendly image includes a few basics. First, the cloud provides drivers for virtual devices. After you choose the correct drivers, your cloud-friendly image will have a small footprint. Since the footprint is small, there usually isn’t a lot of disk space for other applications or additional data.
When creating an instance in the cloud you define the block storage. A cloud-friendly image will expand the block storage to utilize the entire image. Beyond those basics, you should have an image updated with the latest patches, made possible with the setting in the configuration file we will use.

How is creating a cloud-friendly windows image accomplished?

There are different ways to create the image. I will outline the steps for one of the more popular ways to create images for the cloud. We will be using tools found in the cloud and in Windows 10 pro, but this can also be done with any version of windows that provides Hyper-V.

Tools needed

Here are the tools that you will need:

Setup Windows 10 Pro

The first thing that we need to do is setup Hyper-V in our Windows 10 Pro. This is a feature of the operating system.

  1. Click on the start and start type ‘Windows Features’ and click on ‘Turn Windows feature on or off’.
  2. Find ‘Hyper-V’ in the list and check the box to turn it on.
  3. Restart if requested.
  4. Create a network named ‘external’.
      • Start ‘Hyper-V manager’ and click on your desktop name on the left side.
      • Click on ‘Virtual Switch Manager…’ on the right side.
      • Click on ‘New virtual network switch’.
      • Make sure ‘External’ is selected.
      • Click the ‘Create Virtual Switch’ button.
      • Name the switch ‘external’. This name is used in the configuration file.
      • In the connection type, make sure that ‘External network:’ is selected. Make sure that a network adaptor that has a connection to the internet is select from the drop list so that we can download updates. Leave the ‘Allow management operation system to share this network adapter’ selected.
      • Click ‘OK’ and okay for any warnings.

Install git for Windows

We need to setup git for windows. For windows 64 bit (does anyone use 32 anymore?!?!) download the installer https://github.com/git-for-windows/git/releases/download/v2.31.0.windows.1/Git-2.31.0-64-bit.exe and install git with the default options.

Create a directory to work in

We need to create a directory to work in. I am going to use c:\images. Create this using File Explorer.

Download the Windows images

Go to the windows evaluation images.

Fill out the information need to download the evaluation images. I renamed the images.

  • Windows server 2016 -> win2k16.iso
  • Windows server 2019 -> win2k19.iso
  • Windows 10 enterprise -> win10ent.iso

Copy the images to c:\images

Download the virtIO drivers

Sync the image tools project with git

  • Open a PowerShell as an Administrator.
  • Click start. Type ‘powershell’. Right click on ‘Windows PowerShell’ and then ‘Run as administrator’. Click ‘yes’ to pop dialog.
  • Change to the c:\image directory: ‘cd c:\images’
  • Clone the git project: ‘git clone https://github.com/cloudbase/windows-openstack-imaging-tools’
  • Change to the project directory: ‘cd .\windows-openstack-imaging-tools\’
  • Clone the subprojects: ‘git submodule update –init’

Load the shell modules

While still in the c:\images\windows-openstack-imaging-tools\ directory run these commands:

  • Set-ExecutionPolicy -ExecutionPolicy RemoteSigned (only need to run the first time)
  • Import-Module .\WinImageBuilder.psm1
  • Import-Module .\Config.psm1
  • Import-Module .\UnattendResources\ini.psm1

Create the config file

While still in the c:\images\windows-openstack-imaging-tools\ directory run this command:

  • New-WindowsImageConfig -ConfigFilePath C:\images\config.ini

Modify the config file to your liking

You can modify the config to your liking. There are several configuration options that are required to modify. The conifg.ini file has information in it as to what the options are. There is more information here: https://cloudbase-init.readthedocs.io/en/latest/index.html

I am going to create a QCOW2 image for OpenStack, so I will modify the config.ini accordingly.

Required Option

  • image_name= (There is more information on how find the name in the config file)
    • Windows Server 2016: “Windows Server 2016 SERVERSTANDARD”
    • Windows Server 2019: “Windows Server 2019 SERVERSTANDARD”
    • Windows 10 enterprise: “Windows 10 Enterprise Evaluation”
  • image_path= (Where you would like to put the image with file extension). I use QCOW2 images and put the image in the c:\images directory.
    • Windows Server 2016: “C:\images\windows-2k16.qcow2”
    • Windows Server 2019: “C:\images\windows-2k19.qcow2”
    • Windows 10 enterprise: “C:\images\windows-10-ent.qcow2”
    • virtual_disk_format=QCOW2
    • image_type=KVM
    • virtio_iso_path=”c:\images\virtio-win-0.1.185.iso” (Should be the same name that you downloaded)

Addition Options I use

  • enable_custom_wallpaper=False
  • compress_qcow2=True
  • zero_unused_volume_sectors=True
  • enable_shutdown_without_logon=True
  • enable_ping_requests=True
  • enable_active_mode=True
  • cpu_count=2
  • install_updates=True
  • purge_updates=True
  • clean_updates_offline=True
  • unattend_xml_path=””
  • disable_swap=True

Create the image

Now we are going to create the image. It takes a while.

Mount the windows image by double clicking it. Make sure the drive letter is the same in your config file as the config option “wim_file_path”. If it is not, then change the drive letter in the config file.

While still in the c:\images\windows-openstack-imaging-tools\ directory run this command:

  • New-WindowsOnlineImage -ConfigFilePath C:\images\config.ini

If everything is configured correctly you should eventually see a virtual machine created in Hyper-V Manager. You can log on the instance by double clicking it and using the username ‘administrator’ and the password in the config file “administrator_password”.

Now you should have a windows image that you can upload to OpenStack and create instances from. There are many customizations that can be done. You can also use a windows sysprep unattended.xml file to further customize the image.

Good luck and contact me at dpottratz@orocktech.com if you have any questions about these steps.

Request more information about ORock Technologies or schedule a demo.

Loading...

Share This