Skip to content

Preparing a Windows Image ​

Frostmoln does not recommend proprietary operating systems

Frostmoln does not recommend proprietary operating system images such as Windows, because they may not align with European requirements under GDPR and NIS2. This guide shows that it is possible to run a Windows instance on Frostmoln. Running one is your own responsibility: Frostmoln is not involved in your Windows image or its licence, and cannot guarantee how it works or that it meets your regulatory obligations.

Frostmoln does not supply Windows images. To run Windows, build an image from your own installation media and licence, then upload it as a custom image. This guide covers the whole process, from an empty disk to a running instance you can log in to.

The examples build Windows Server 2022 on a Debian instance on Frostmoln. The examples use Windows Server 2022 lists what to change for another version.

Windows images on the custom-images page lists what the platform requires of a Windows image. This page shows how to build one that meets those requirements, using cloudbase-init so that each instance gets its own credential at launch. If the two pages ever disagree about a requirement, the custom-images page applies.

Before you start ​

Licensing is yours ​

Frostmoln provides no Windows licence, product key or activation service. You must bring your own and comply with its terms.

  • Check that your licence allows this kind of hosting. Your instances run on shared cloud infrastructure, and not every Microsoft licence permits that. Rights depend on your agreement: for example, whether it includes Software Assurance or subscription licences, and which edition you have. Ask your licensing partner if you are unsure. Frostmoln cannot advise on your agreement.
  • Plan for activation with a MAK, or a KMS your instances can reach. An image captured while activated against your on-premises KMS loses its activation once it can no longer reach that KMS.

Which Windows versions work ​

Instances boot with a legacy BIOS. UEFI and Secure Boot are not available, and there is no virtual TPM. That decides which versions you can use:

VersionWorks?Note
Windows Server 2016, 2019, 2022, 2025YesRecommended. Use the Standard or Datacenter edition.
Windows 10YesCheck your licence (see above). Each vCPU appears as a separate CPU socket, and client editions use at most two, so larger flavors leave vCPUs idle.
Windows 11NoRequires UEFI, Secure Boot and a TPM.

What you need ​

  • A build machine. The steps below run on a Debian instance on Frostmoln, set up in Step 0. It runs the Windows build VM with QEMU/KVM, which can present the virtio disk, virtio network card and BIOS firmware a Frostmoln instance uses. A Debian machine of your own with QEMU/KVM works the same way: skip Step 0 and install the packages from Step 0, item C. Any other hypervisor works too if it can attach a virtio disk and a virtio network card, and boot with BIOS.
  • Your Windows installation ISO.
  • The virtio-win driver ISO. These are the open-source Windows drivers for virtio disks and network cards, published by the Fedora project. Use a current stable release that has a driver folder for your Windows version. For example, Windows Server 2025 needs a release with a 2k25 folder.
  • About 50 GB of free disk space for the ISOs, the build disk, its converted copy and a test copy. The build instance's 80 GB disk is enough.
  • About an hour and a half. Step 0 takes about 10 minutes, Steps 1 to 6 about 40, and converting, uploading and importing about 40 more.

Build fresh rather than converting an existing VM

An existing VM exported from Hyper-V or VMware is usually UEFI-booted and has no virtio storage driver bound to its boot disk. It will not boot here even after conversion. A fresh installation on virtio hardware, as described below, is the reliable route.

The examples use Windows Server 2022 ​

Every command and file name below uses Windows Server 2022 as the example. For another version, change these values wherever they appear:

Windows versionvirtio-win driver foldervirt-install --os-variantImage --os-version
Windows Server 20162k16win2k162016
Windows Server 20192k19win2k192019
Windows Server 20222k22win2k222022
Windows Server 20252k25win2k252025
Windows 10w10win1010

The file names (win2022.qcow2, win2022-build and so on) are only names; pick your own if you like. Name the ISO and the image (windows-server-2022) after your version too.

Where each command runs ​

Commands run in three places, and each step says which:

  • Your computer: fm commands (except the upload in Step 9, which runs on the build instance), ssh, scp and the VNC viewer.
  • The build instance: qemu-img, virt-install and virsh, always with sudo and in /var/lib/libvirt/images.
  • The Windows build VM: PowerShell, typed at the VM's screen.

Step 0: Set up a build instance on Frostmoln ​

A Debian instance on Frostmoln runs the Windows build VM, downloads the ISOs and uploads the finished image over a fast connection. You only need SSH from your own computer.

  • A. Create the instance. On your computer, find the ID of the Debian 13 image with fm compute image list --os-distro debian. Pick a security group that allows SSH (TCP 22) from your own address only, and a flavor with at least 4 vCPUs, 16 GB of memory and 80 GB of disk, for example gp1.large:

    bash
    fm compute instance create --name win-builder --flavor gp1.large \
      --image <debian-13-image-id> --ssh-key my-key \
      --vpc <vpc-id> --subnet <subnet-id> --security-group <sg-id>
    fm network public-ip allocate
    fm network public-ip associate <public-ip-id> <instance-id>
  • B. Check that it can run VMs. Log in with ssh debian@<public-ip> and run ls -l /dev/kvm. The device must exist. Without it the build VM runs without hardware acceleration and takes many hours; contact support if it is missing.

  • C. Install the tools. On the build instance:

    bash
    sudo apt-get update
    sudo apt-get install -y qemu-system-x86 qemu-utils libvirt-daemon-system \
      virtinst libosinfo-bin
    sudo virsh net-autostart default
    sudo virsh net-start default

    If apt-get update stops making progress, force IPv4 and run it again: echo 'Acquire::ForceIPv4 "true";' | sudo tee /etc/apt/apt.conf.d/99force-ipv4.

  • D. Get the ISOs onto the build instance. If your Windows ISO is on your own computer, copy it up from your computer, then move it into place on the build instance:

    bash
    # On your computer
    scp windows-server-2022.iso debian@<public-ip>:
    bash
    # On the build instance
    sudo mv ~/windows-server-2022.iso /var/lib/libvirt/images/

    If your licensing portal gives you a direct download link, download it on the build instance instead with sudo wget -O /var/lib/libvirt/images/windows-server-2022.iso '<download-url>'. If the portal publishes a SHA-256 checksum, compare it with sha256sum /var/lib/libvirt/images/windows-server-2022.iso.

    For a trial, Microsoft's Evaluation Center offers evaluation media. It is not for production: it expires after 180 days, and it must be converted to a licensed edition before your product key can activate it. Build production images from your licensed media.

    Then fetch the drivers on the build instance:

    bash
    sudo wget -O /var/lib/libvirt/images/virtio-win.iso \
      https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso
  • E. Delete the instance and its public IP when you are done. Both are billed for as long as they exist: fm compute instance delete <instance-id> and fm network public-ip release <public-ip-id>.

Step 1: Create the build disk ​

On the build instance. The virtual size of the disk counts against the 35 GiB import limit, not the size of the file. Create the disk at 32 GiB or less:

bash
cd /var/lib/libvirt/images
sudo qemu-img create -f qcow2 win2022.qcow2 32G

Instances from this image need a root disk of at least 32 GiB. A larger flavor disk is fine: cloudbase-init grows C: to fill it at first boot (Step 5).

Step 2: Start the build VM ​

On the build instance, boot the installer with a virtio disk, a virtio network card, BIOS firmware, and both ISOs attached as CD-ROMs. Replace windows-server-2022.iso with the name of your ISO:

bash
cd /var/lib/libvirt/images
sudo virt-install \
  --name win2022-build \
  --memory 4096 --vcpus 2 \
  --machine pc \
  --disk path=/var/lib/libvirt/images/win2022.qcow2,format=qcow2,bus=virtio \
  --network network=default,model=virtio \
  --cdrom /var/lib/libvirt/images/windows-server-2022.iso \
  --disk path=/var/lib/libvirt/images/virtio-win.iso,device=cdrom \
  --os-variant win2k22 \
  --graphics vnc \
  --noautoconsole

--machine pc gives the VM the classic PC chipset with a BIOS, which matches a Frostmoln instance. Do not ask for UEFI: a UEFI installation creates a GPT disk that Frostmoln cannot boot. To confirm the VM is not using UEFI, run sudo virsh dumpxml win2022-build | grep -i -e loader -e efi. It must print nothing. Use --os-variant to name the closest version your virt-install knows about; osinfo-query os lists them.

Open the VM's screen from your computer. The display listens only on the build instance itself, so reach it through SSH. On the build instance, sudo virsh vncdisplay win2022-build shows the display number (:0 means port 5900). Then, on your computer, forward that port and open any VNC viewer on localhost:5900:

bash
ssh -L 5900:127.0.0.1:5900 debian@<public-ip>

Do not open VNC in the security group.

When the installer restarts the VM for the first time, virt-install may stop it instead. Start it again with sudo virsh start win2022-build; the installation continues from the disk.

Step 3: Install Windows ​

In the build VM's screen:

  1. On the first screen, keep Keyboard or input method: US. When you type a password at the browser console later, symbols can land on different keys if your own keyboard and the image's layout differ. You can change the layout inside an instance once you have another way in.
  2. Enter your product key, or choose I don't have a product key and activate each instance later. Choose a Standard or Datacenter edition with Desktop Experience unless you plan to manage the server entirely remotely.
  3. At Where do you want to install Windows? no disk is shown, because Windows has no driver for the virtio disk yet. Click Load driver, browse to the virtio-win CD and select viostor\<version>\amd64, for example viostor\2k22\amd64. Install the Red Hat VirtIO SCSI controller driver.
  4. Click Load driver again and load NetKVM\<version>\amd64 too, so the network card works after the first boot.
  5. The disk now appears. Select the unallocated space and continue. Because the VM booted with BIOS, Windows partitions the disk as MBR automatically.
  6. Set a temporary Administrator password when asked. Make it strong and don't reuse it. It does not carry over into instances, because cloudbase-init replaces it at each instance's first boot.

Step 4: Configure Windows ​

Log in at the VM's console and work through this list. Everything you change now ends up in every instance launched from the image.

Install the rest of the virtio drivers. From the virtio-win CD, run virtio-win-gt-x64.msi. It installs all the drivers (network, balloon, serial and so on) without a guest agent. You do not need the guest agent.

Set the hardware clock to UTC. Frostmoln's virtual hardware clock runs on UTC, while Windows assumes local time. Without this setting every instance starts with its clock off by your time-zone offset:

powershell
reg add "HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation" `
  /v RealTimeIsUniversal /t REG_DWORD /d 1 /f

Remove a recovery partition that blocks growing C:. Check the layout in Disk Management. If a Recovery partition sits after C:, C: cannot grow into the larger disk an instance gets. Disable the recovery environment, delete that partition, and re-enable the environment (it moves onto C:):

powershell
reagentc /disable
# Find the recovery partition number after C: on disk 0
Get-Partition -DiskNumber 0
Remove-Partition -DiskNumber 0 -PartitionNumber <number> -Confirm:$false
reagentc /enable

Install OpenSSH Server (optional, recommended). It gives you key-based access that needs no password in the image or in user data. See Option A below.

Do not use Add-WindowsCapability (Settings, Optional features) for this. It downloads OpenSSH from Windows Update, and on fresh installation media that download can fail with error 0x80072f8f while the service still appears to be installed. Sysprep then removes the half-installed server, and the image ships without it.

Install it from Microsoft's Win32-OpenSSH installer package instead. In the build VM's browser, open the Releases page of the PowerShell/Win32-OpenSSH project on GitHub and download OpenSSH-Win64-…msi from the release marked Latest. The project puts Preview or Beta in every release name; that is its naming, and the Latest release is the one to use. Then run this in an elevated PowerShell in the folder you saved it to, usually Downloads:

powershell
$msi = (Get-ChildItem .\OpenSSH-Win64-*.msi | Sort-Object LastWriteTime -Descending | Select-Object -First 1).FullName
Get-AuthenticodeSignature $msi | Format-List Status, SignerCertificate
Start-Process msiexec.exe -Wait -ArgumentList "/i `"$msi`" /qn /norestart"
Stop-Service sshd -ErrorAction SilentlyContinue
Set-Service sshd -StartupType Manual
Remove-Item C:\ProgramData\ssh\ssh_host_* -ErrorAction SilentlyContinue
Get-Service sshd

Check two things in the output. The signature Status must be Valid, with Microsoft Corporation in the signer's subject; if it is not, stop and download the file again. The last line must show a service named sshd with status Stopped. If it reports that no such service exists, the installation failed; do not continue until it works, or every instance will come up with no way in.

The installer starts the service right away, sets it to start automatically, creates SSH host keys and adds a firewall rule for port 22. The commands above undo the first three on purpose: the service stays on Manual and stopped, with no host keys. Keys created in the build VM would be shared by every instance. The user-data script at launch starts the service on each instance, which then creates its own keys. The installer's firewall rule stays in the image; it does nothing while the service is stopped.

Install updates and your own software. Run Windows Update until nothing is left, and install any agents, roles and features you want in every instance. The image is frozen at upload: nothing patches it afterwards, so keep Windows Update (or your WSUS) running on every instance.

While the VM is online, Microsoft Edge also updates itself in the background, for the logged-in user only. Sysprep refuses an app installed for just one user, so Step 6 takes the VM offline and removes that copy before it runs.

Leave out secrets. Do not add domain-join credentials, saved RDP connections, Credential Manager entries, API keys or a product key that is not meant to be in every instance. The Administrator profile survives Sysprep, so clear Edge's browsing data (history, cookies, saved passwords) if you signed in to anything. The script in Step 6 also empties Downloads and clears your PowerShell history. Do not enable AutoAdminLogon: it stores the password in clear text in the registry. Do not set up a WinRM HTTPS listener or certificate in the image either, because every instance would share it. Configure WinRM per instance after launch.

Step 5: Install cloudbase-init ​

cloudbase-init is the Windows counterpart of cloud-init. At first boot it reads the instance's configuration from a small read-only drive attached to the instance, then sets the host name, grows C: to fill the disk, and runs your user data. Frostmoln does not give you a password for a Windows guest, so cloudbase-init running your user data is how a new instance gets its first way in.

  1. In the build VM's browser, download CloudbaseInitSetup_Stable_x64.msi from the cloudbase-init download page, https://cloudbase.it/cloudbase-init/. Before you run it, check its signature in PowerShell: Get-AuthenticodeSignature .\CloudbaseInitSetup_Stable_x64.msi | Format-List Status, SignerCertificate. Status must be Valid, with Cloudbase Solutions Srl in the signer's subject. Then run it.

  2. On the configuration screen set:

    • Username: Administrator. cloudbase-init then manages the built-in account instead of creating a second one.
    • Serial port for logging: COM1.
    • Run cloudbase-init service as LocalSystem: checked.
  3. On the last screen, leave Run Sysprep to create a generalized imageunticked and click Finish. You run Sysprep yourself in Step 6, because two things must happen first that the wizard does not do.

  4. Open Notepad with Run as administrator (files under Program Files cannot be saved otherwise), then use File → Open on both files in C:\Program Files\Cloudbase Solutions\Cloudbase-Init\conf\. In each one, put these lines under [DEFAULT], and delete any existing line that starts with the same name.

    In cloudbase-init.conf, four lines. The plugins= line is long; copy it as one single line:

    ini
    metadata_services=cloudbaseinit.metadata.services.configdrive.ConfigDriveService
    plugins=cloudbaseinit.plugins.common.mtu.MTUPlugin,cloudbaseinit.plugins.windows.ntpclient.NTPClientPlugin,cloudbaseinit.plugins.common.sethostname.SetHostNamePlugin,cloudbaseinit.plugins.windows.createuser.CreateUserPlugin,cloudbaseinit.plugins.common.networkconfig.NetworkConfigPlugin,cloudbaseinit.plugins.windows.extendvolumes.ExtendVolumesPlugin,cloudbaseinit.plugins.common.userdata.UserDataPlugin,cloudbaseinit.plugins.common.localscripts.LocalScriptsPlugin
    real_time_clock_utc=true
    check_latest_version=false

    In cloudbase-init-unattend.conf, one line:

    ini
    metadata_services=cloudbaseinit.metadata.services.configdrive.ConfigDriveService

    What each line does:

    • metadata_services: your instance's configuration always arrives on the configuration drive. Without this line, cloudbase-init first tries other sources, and every first boot waits for them to time out.
    • plugins: the point of this list is what it leaves out. cloudbase-init's password plugin runs after your user data by default and would overwrite the password your user data sets, leaving you locked out (Option B). The WinRM plugins are left out too. They would open a WinRM listener with a shared configuration on every instance; set up remote access yourself after launch instead.
    • real_time_clock_utc: keeps the UTC clock setting from Step 4. Without it, cloudbase-init switches the hardware clock back to local time at first boot and restarts the instance, which leaves every instance's clock off by your time-zone offset.
    • check_latest_version: stops every instance from contacting the cloudbase-init project's website to check for a newer version.

Step 6: Generalize with Sysprep ​

This is the step most likely to go wrong, so do it in this order.

1. Take the VM offline. On the build instance:

bash
sudo virsh domif-setlink win2022-build "$(sudo virsh domiflist win2022-build | awk '/network/{print $1}')" down

(In virt-manager: the VM's network card, untick Link state: active.) This stops Edge from updating itself while Sysprep runs.

2. Run this in an elevated PowerShell inside the VM. It stops Edge's updater, removes any copy of Edge installed for a single user, empties Downloads and your PowerShell history, lets cloudbase-init start only after Windows setup has finished, and then runs Sysprep with cloudbase-init's answer file. The VM shuts down by itself when Sysprep is done.

powershell
Stop-Service edgeupdate, edgeupdatem -Force -ErrorAction SilentlyContinue
Get-AppxPackage -AllUsers -Name Microsoft.MicrosoftEdge.Stable |
  ForEach-Object { Remove-AppxPackage -Package $_.PackageFullName -AllUsers }
Remove-Item "$env:USERPROFILE\Downloads\*" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item "$env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt" -ErrorAction SilentlyContinue
$cb = 'C:\Program Files\Cloudbase Solutions\Cloudbase-Init'
& "$cb\bin\SetSetupComplete.cmd"
& C:\Windows\System32\Sysprep\sysprep.exe /generalize /oobe /shutdown "/unattend:$cb\conf\Unattend.xml"

Sysprep takes a few minutes. When it has finished, sudo virsh list --all on the build instance shows win2022-build as shut off.

Do not start the build VM again

The next boot runs the first-boot setup and turns the disk back into a specific machine. If you need to change something, build the image again from Step 1. To test the image, use a copy (see Step 8).

SetSetupComplete.cmd is the step people miss when they run Sysprep themselves. It comes with cloudbase-init and holds the cloudbase-init service back until Windows setup has finished. Without it, the service starts during the instance's first-boot setup, restarts the machine halfway through, and every instance stops at "The computer restarted unexpectedly or encountered an unexpected error".

If Sysprep reports a fatal error, read C:\Windows\System32\Sysprep\Panther\setuperr.log. Do not keep retrying on the same VM: a failed Sysprep can leave Windows half-prepared and the Administrator password reset. Fix the cause and build the image again from Step 1.

Generalizing gives every instance its own SID, RDP certificate and machine keys. Without it, all instances launched from the image share one identity.

Step 7: Convert and check the image ​

On the build instance, flatten and compress the disk into the file you will upload. Compression takes 10 to 15 minutes:

bash
cd /var/lib/libvirt/images
sudo qemu-img convert -O qcow2 -c win2022.qcow2 win2022-upload.qcow2
sudo qemu-img info win2022-upload.qcow2

Check three things in the qemu-img info output:

  • virtual size is 35 GiB or less, or the import is refused.
  • file format is qcow2 and there is no backing file line.
  • disk size is no more than 35 GiB. This is what you upload.

The platform stores and bills the image at its full virtual size; see the size that counts.

Uploading and importing a 32 GiB image takes well over half an hour, and a local boot catches most mistakes in ten minutes. On the build instance, boot a copy, never the upload file:

bash
cd /var/lib/libvirt/images
sudo cp win2022-upload.qcow2 win2022-test.qcow2
sudo virt-install --name win2022-test --memory 4096 --vcpus 2 \
  --machine pc --import \
  --disk path=/var/lib/libvirt/images/win2022-test.qcow2,format=qcow2,bus=virtio \
  --network network=default,model=virtio \
  --os-variant win2k22 --graphics vnc --noautoconsole

Open its screen the same way as in Step 2. It has its own display number: sudo virsh vncdisplay win2022-test shows it, and :1 means port 5901.

The copy runs Windows' first-boot setup (Getting ready, which can take several minutes), restarts once, and must end at the login screen without a blue screen or an error dialog. cloudbase-init finds no configuration drive locally, so do not expect it to set anything up: this test checks Windows itself, and Step 10 checks cloudbase-init. Then delete the test VM and its copy:

bash
sudo virsh destroy win2022-test
sudo virsh undefine win2022-test
sudo rm /var/lib/libvirt/images/win2022-test.qcow2

Step 9: Upload the image ​

Upload from the build instance, so the file goes straight to Frostmoln without passing through your own connection. Install the fm CLI on the build instance and sign in with fm auth login --no-browser.

Upload win2022-upload.qcow2 as described in Custom Images. Set the OS distribution to windows. It cannot be changed later, and it is the setting that tells the platform the image is Windows.

bash
fm compute image create \
  --name windows-server-2022 \
  --description "WS2022 Standard, built 2026-10, cloudbase-init" \
  --file /var/lib/libvirt/images/win2022-upload.qcow2 \
  --disk-format qcow2 \
  --os-distro windows \
  --os-version 2022 \
  --arch x86_64 \
  --wait --timeout 60m
hcl
resource "frostmoln_image" "windows" {
  name             = "windows-server-2022"
  description      = "WS2022 Standard, built 2026-10, cloudbase-init"
  source_file      = "/var/lib/libvirt/images/win2022-upload.qcow2"
  source_file_hash = filesha256("/var/lib/libvirt/images/win2022-upload.qcow2")
  disk_format      = "qcow2"
  os_distro        = "windows"
  os_version       = "2022"
  architecture     = "x86_64"
}

Run Terraform where the file is, for example on the build instance. In the portal: Compute → Images → Upload image, with OS distribution set to windows; the file then uploads from your computer.

Note in the description which build the image comes from. The platform lists the image as raw once the import finishes and keeps no record of the original file.

Expect the upload and import to take a while: a 6 GB file takes around 10 to 15 minutes to upload from a Frostmoln instance. The import converts the full virtual disk, so a 32 GiB image stays in Importing for around 20 to 30 minutes before it becomes Active. If --wait gives up first, the import carries on; fm compute image get <image-id> shows when it is Active.

When the image is Active, you can delete the build instance and its public IP (Step 0, item E).

Step 10: Launch an instance ​

Launch from the image as usual, with three Windows-specific rules:

  • Do not attach an SSH key from your account (--ssh-key, or a key chosen in the portal). No key reaches a Windows guest that way, and attaching one stops your user-data script from running. Option A puts your key in the user data instead.
  • Do not set a console password. A launch that asks for one is refused for a Windows image.
  • Do not enable instance access (--instance-access). The managed agent runs on Linux only, and enabling it also stops your user-data script from running.

Choose a flavor with at least 4 GB of memory and a root disk at least as large as the image. Then give the instance its first credential through user data, using one of the options below.

An instance launched without user data has no way in

At first boot cloudbase-init sets the Administrator password to a random value that nobody knows. With the plugin list from Step 5, your user data runs after that, so whatever it sets is what you log in with. Without user data, re-create the instance.

If you baked an account into the image instead, as described under Getting in, Options A and B do not apply.

Requires OpenSSH Server in the image (Step 4). The user data installs your public key for the Administrator account and starts the SSH service, with SSH password logins turned off. A public key is not a secret, so nothing sensitive is stored in the user data.

Save this script as windows-ssh.ps1 on your computer. Replace the $key value with the whole contents of your public key file, for example the output of cat ~/.ssh/id_ed25519.pub:

powershell
#ps1_sysnative
# Windows 10 ships with Administrator disabled; harmless on Server
net user Administrator /active:yes
# The first start creates this instance's own host keys
Set-Service sshd -StartupType Automatic
Start-Service sshd
# Key logins only: no SSH password logins, even after you set a password
$cfg = 'C:\ProgramData\ssh\sshd_config'
if (Test-Path $cfg) {
  (Get-Content $cfg) -replace '^#?\s*PasswordAuthentication\s.*', 'PasswordAuthentication no' |
    Set-Content $cfg -Encoding ascii
  Restart-Service sshd
}
$key  = 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA... you@laptop'
$file = 'C:\ProgramData\ssh\administrators_authorized_keys'
Set-Content -Path $file -Value $key -Encoding ascii
# SIDs for Administrators and SYSTEM, so this also works on non-English Windows
icacls.exe $file /inheritance:r /grant '*S-1-5-32-544:F' /grant '*S-1-5-18:F'
# Allow SSH through the Windows firewall with a rule of known name
if (Get-NetFirewallRule -Name OpenSSH-Server-In-TCP -ErrorAction SilentlyContinue) {
  Enable-NetFirewallRule -Name OpenSSH-Server-In-TCP
} else {
  New-NetFirewallRule -Name OpenSSH-Server-In-TCP -DisplayName 'OpenSSH Server (sshd)' `
    -Direction Inbound -Protocol TCP -LocalPort 22 -Action Allow | Out-Null
}

Pick a security group that allows TCP 22 from your own address only. Find your image's ID with fm compute image list, then launch the instance and give it a public IP:

bash
fm compute instance create \
  --name win-01 \
  --image <image-id> \
  --flavor gp1.medium \
  --vpc <vpc-id> \
  --subnet <subnet-id> \
  --security-group <sg-id> \
  --user-data @windows-ssh.ps1
fm network public-ip allocate
fm network public-ip associate <public-ip-id> <instance-id>

After about five minutes, connect with ssh Administrator@<public-ip>. If you want a password for the console too, set one once you are in: net user Administrator *. SSH keeps accepting keys only.

Option B: a bootstrap password ​

The user data sets the Administrator password and forces a change at first login. Generate a new password for every instance, of letters and digits only and at least 16 characters long, and never reuse the example. Symbols and characters such as å, ä and ö can land on different keys at the console, depending on your keyboard and the image's layout.

Save this script as windows-password.ps1 on your computer:

powershell
#ps1_sysnative
# Windows 10 ships with Administrator disabled; harmless on Server
net user Administrator /active:yes
net user Administrator 'ReplaceWithAUniquePassword2026'
# cloudbase-init marks the password as never expiring, and Windows ignores
# "must change at next logon" for such an account, so clear that first
Set-LocalUser -Name Administrator -PasswordNeverExpires $false
net user Administrator /logonpasswordchg:yes

Launch the instance with the same command as in Option A, but with --user-data @windows-password.ps1. A public IP is optional here, because you log in at the console.

Log in at the console (portal: Console on the instance, or fm compute instance console <instance-id>). Use the console's Send CtrlAltDel button to get the sign-in screen, sign in as Administrator with the password from your script, and choose a new password when Windows asks. Until you do, RDP and SSH password logins are refused, because the password must be changed first.

If the sign-in screen shows Caps Lock is on, press Caps Lock once before you type. The console can start with Caps Lock on in the instance even when it is off on your keyboard.

The Set-LocalUser line makes the Administrator password follow the machine's password-expiry policy. If you want it to never expire again, run Set-LocalUser -Name Administrator -PasswordNeverExpires $true after you have changed it.

User data is readable inside the instance

The configuration drive is an ordinary CD-ROM inside Windows, so treat a password sent in user data as known to anyone who can log in to the instance. cloudbase-init writes whatever your script prints to its log and to the instance's console output, which members of your tenant can read, so never print the password. Change it at first login, delete your local copy of the script, and do not put it in a launch template, whose user data everyone in your tenant can read.

Open remote access narrowly ​

After the first login, set up the access you will use day to day: RDP, WinRM over HTTPS (port 5986, never plain HTTP on 5985) or SSH. Then open only that port in a security group, to your own address only. Better still, reach the instance on its private address over a VPN or a bastion. Nothing is open by default; never open RDP to 0.0.0.0/0. Keep Network Level Authentication enabled for RDP.

Windows Server already listens for WinRM over plain HTTP on 5985 for its own subnet. If you do not use it, remove that listener with winrm delete winrm/config/Listener?Address=*+Transport=HTTP, or keep port 5985 closed in your security groups.

The name Administrator is the same on every Windows machine, and by default it is never locked out after failed logins. Create your own named administrator account, then disable the built-in one, or turn on lockout for it.

Useful settings after first login ​

A few settings worth applying once you are in, from an elevated PowerShell:

powershell
# Set the time zone (list the IDs with Get-TimeZone -ListAvailable)
Set-TimeZone -Id "W. Europe Standard Time"
Restart-Service w32time -Force

# Make the OpenSSH Server inbound firewall rule apply to all network profiles
Set-NetFirewallRule -Name OpenSSH-Server-In-TCP -Profile Any

# Set the network profile to Private (Windows defaults to Public)
Get-NetAdapter | Where-Object { $_.Status -eq "Up" } | Set-NetConnectionProfile -NetworkCategory Private
  • The clock stays right across reboots only with RealTimeIsUniversal set in the image (Step 4).
  • The firewall line widens the rule that Option A enables; it exists only if OpenSSH Server is installed. The security group still decides who can reach port 22.
  • Private also turns on every inbound rule scoped to Private, such as file sharing, network discovery and, on Windows Server, WinRM over plain HTTP on 5985. List what is open with Get-NetFirewallRule -Direction Inbound -Enabled True | Where-Object { $_.Profile -match 'Private|Any' }, disable what you don't use, and keep your security groups narrow.
  • Joining a domain may switch the network profile to Domain.

Troubleshooting ​

SymptomCause and fix
virt-install fails with Unable to find 'bios' firmwareYour virt-install command uses --boot firmware=bios. Remove it and use --machine pc (Step 2).
Sysprep shows A fatal error occurred while trying to sysprep the machineRead C:\Windows\System32\Sysprep\Panther\setuperr.log. If it names Microsoft.MicrosoftEdge.Stable as installed for a user, but not provisioned for all users, the VM was online while Sysprep ran. Rebuild and follow Step 6 in order.
Every instance stops at The computer restarted unexpectedly or encountered an unexpected error and restarts in a loopThe cloudbase-init service ran during Windows' first-boot setup, because SetSetupComplete.cmd was not run before Sysprep. Rebuild and follow Step 6.
Console shows no bootable deviceThe image was installed with UEFI (GPT disk). Rebuild with --machine pc and check that sudo virsh dumpxml shows no loader (Step 2).
Blue screen INACCESSIBLE_BOOT_DEVICE (0x7B)The virtio storage driver is missing. Rebuild, loading viostor during setup (Step 3). There is no way to fix an uploaded image.
Instance boots but has no networkThe NetKVM driver is missing. Install virtio-win-gt-x64.msi before Sysprep.
Import fails (Import failed) although the file is smallThe disk's virtual size is over 35 GiB. Rebuild with a 32 GiB disk (Step 1).
Clock is off by a few hoursRealTimeIsUniversal is not set (Step 4), or real_time_clock_utc=true is missing from cloudbase-init.conf, so cloudbase-init switched the clock back to local time (Step 5).
C: did not grow to the flavor's disk sizeA recovery partition follows C: (Step 4), or cloudbase-init is not installed.
First boot takes several minutes before anything happensmetadata_services was not restricted to the configuration drive (Step 5).
Your user data did not runThe script must start with #ps1_sysnative on the first line, and neither an SSH key nor instance access may be attached to the instance. cloudbase-init's log is C:\Program Files\Cloudbase Solutions\Cloudbase-Init\log\.
The instance reaches the login screen, but SSH to it times outThe image has no OpenSSH Server, so the user-data script could not start it. Check Step 4: install it from the Win32-OpenSSH package and confirm Get-Service sshd shows it before Sysprep. Also check that your security group allows TCP 22 from where you connect.
The password from your user data is rejected, or Windows demands a change with a password you don't knowcloudbase-init's password plugin ran after your user data. Use the plugins= list from Step 5 and rebuild the image.
Password is rejected at the consoleCaps Lock is on in the instance (the sign-in screen says so; press Caps Lock once), or a symbol in the password landed on a different key. Use Option A, or re-create the instance with a password of letters and digits only.
Windows reports it is not activatedThe image was activated against a KMS your instance cannot reach. Activate with a MAK, or point the instance at a KMS it can reach.