VK Cloud logo
Updated at March 27, 2024   03:20 PM

Preparing a Windows OS image to create a VM

The Windows Server 2016 CORE edition image is used as an example, the commands are given in PowerShell.

Preparatory steps

  1. Make sure that you have installed and configured Git.

  2. Clone a repository with automated build scripts windows-imaging-tools.

  3. Clone the repository to update the system image WindowsUpdateCLI.

  4. Set up the toolkit:

  5. Download the ISO image of the operating system for which you plan to migrate to VK Cloud. It is recommended to use the en-US version of the image.

  6. Make sure that OpenStack client is installed and authenticate to the project.

1. Prepare the OS installation WIM file

  1. Connect the downloaded OS ISO image.

  2. Output a list of all Windows versions using the command executed on behalf of the administrator:

    Get-WindowsImage -ImagePath E:\sources\Install.wim

    Here E:\sources\Install.wim — full access to the system's WIM file on the mounted disk.

    A list of editions will appear indicating the ImageIndex of its number:

    ImageIndex      : 1ImageName       : Windows Server 2016 StandardImageDescription: This is the recommended option. It reduces management and maintenance by installing only what is required for most applications and server roles. It does not include a graphical user interface, but you can fully manage the server locally or remotely using Windows PowerShell or other tools. See the section "Windows Server Installation Options".ImageSize       : 9 146 079 566 bytesImageIndex      : 2ImageName       : Windows Server 2016 Standard (desktop features)ImageDescription: This option is suitable if you need a graphical user interface (for example, to ensure backward compatibility of an application that cannot work when installing the main server components). All server roles and components are supported. More detailed: "Windows Server Installation Options".ImageSize       : 15 219 002 744 bytes
  3. Export the revision with ImageIndex = 1 using the command:

    dism `/export-image `/SourceImageFile:E:\sources\Install.wim `/SourceIndex:1 `/DestinationImageFile:D:\Temp\install.wim `/Compress:max `/CheckIntegrity

    Here:

    • D:\Temp\install.wim — the full path on the local disk where the exported image will be saved;
    • SourceIndex:1 — index number of the required revision.

2. Configure the external switch in Hyper-V

Create virtual switch external with an Internet connection.

3. Build the image locally

  1. Go to the windows-imaging-tools directory and import the modules:

    pushd windows-openstack-imaging-toolsImport-Module .\WinImageBuilder.psm1Import-Module .\Config.psm1Import-Module .\UnattendResources\ini.psm1
  2. Transfer the contents of the directory WindowsUpdateCLI to windows-openstack-imaging-tools\UnattendResources\WindowsUpdates.

  3. Create a configuration file config.ini:

    $ConfigFilePath = ".\config.ini"New-WindowsImageConfig -ConfigFilePath $ConfigFilePath
  4. Open the created file and check the parameters:

    wim_file_path=D:\Temp\install.wimimage_name=Windows Server 2016 SERVERSTANDARDCOREimage_path=D:\Win_Server_2016_img.qcow2virtual_disk_format=QCOW2image_type=KVMexternal_switch=externalvirtio_iso_path="D:\Drivers\virtio.iso"time_zone="Russian Standard Time"install_qemu_ga=Trueinstall_updates=Truepurge_updates=Falsecompress_qcow2=True

    Here:

    • external_switch=external — name of the created switch;
    • virtio_iso_path="D:\Drivers\virtio.iso" — full path to the ISO file with VirtIO drivers;
    • time_zone="Russian Standard Time" — the time zone, you can find out using the command tzutil /l;
    • purge_updates=False — do not clear the WinSxS directory after installing updates.
  5. Run a local build of the image using the command:

    New-WindowsOnlineImage -ConfigFilePath $ConfigFilePath
  6. Wait for the operation to complete and make sure that the file D:\Win_Server_2016_img.qcow2 is created.

4. Import the image to the VK Cloud

Use the CLI to import an image:

openstack image create --private --container-format bare --disk-format qcow2 --file D:\Win_Server_2016_img.qcow2 --property hw_qemu_guest_agent=yes --property store=s3 --property min_ram=2048 --property os_require_quiesce=yes --property min_disk=40 --property os_type=windows --property os_admin_user=Administrator --property mcs:lic:mswinsrv=true --property mcs_name='Windows Server 2016 Standard (en)' --property mcs_os_distro='server' --property mcs_os_edition='std' --property mcs_os_type='windows' --property mcs_os_lang='en' --property mcs_os_type='windows' --property mcs_os_version='2016' --property os_distro='win2k16' <image name>

Wait for the operation to complete. After downloading the image, you will be able to create a VM by standard means of the VK Cloud platform.

Delete unused resources

If you no longer need the imported image, delete it.