Preparing your own images with Microsoft products
You can prepare your own images of Microsoft products to use them in Yandex Cloud with your own license. Make sure to contact Microsoft and confirm that your license is suitable for cloud environments. We recommend building images on Linux.
Preparing an image
To prepare an image ready for use in Yandex Cloud:
-
Download the archive with Packer configurations
and unpack it to the relevant directory, such aswindows-packer
. -
Download the image with drivers
and open it. Move the foldersNetKVM
,vioserial
, andviostor
to the folderwindows-packer/drivers
. The folders contain drivers for different operating systems, so make sure to use the appropriate drivers. -
Select the appropriate Packer configuration for your Microsoft product and make the following changes to the configuration file:
-
Specify the path to your distribution in the
iso_url
parameter. -
In the
cd_files
block, specify paths to unpacked drivers for your OS version. For example:cd_files = [ "../drivers/NetKVM/2k19/amd64/*", "../drivers/viostor/2k19/amd64/*", "../drivers/vioserial/2k19/amd64/*", "../scripts/qemu/*", "Autounattend.xml" ]
Please keep in mind that Packer is case-sensitive. If you put folders with drivers elsewhere, specify the appropriate paths.
-
Find out the checksum of your distribution (for example, execute
openssl dgst -sha256 <path to distribution>
). Insert the obtained value into theiso_checksum
parameter aftersha256:
. -
(Optional) With MacOS, you need to replace the
accelerator = "kvm"
value withaccelerator = "hvf"
.
-
-
Set a password for the
Administrator
user. To do this, in theAutounattend.xml
file, add theUserAccounts
section to theoobeSystem
section, specifying the password inside theValue
tag:<settings pass="oobeSystem"> <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <OOBE> <HideEULAPage>true</HideEULAPage> <HideLocalAccountScreen>true</HideLocalAccountScreen> <HideOEMRegistrationScreen>true</HideOEMRegistrationScreen> <HideOnlineAccountScreens>true</HideOnlineAccountScreens> <HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE> <ProtectYourPC>1</ProtectYourPC> </OOBE> <RegisteredOwner /> <TimeZone>UTC</TimeZone> <UserAccounts> <AdministratorPassword> <Value><administrator_password></Value> <PlainText>true</PlainText> </AdministratorPassword> </UserAccounts> </component> </settings>
-
Go to the folder with the required image configuration (e.g.,
external-windows-packer/ws22gui-qemu
) and run thepacker build .
command.
Note
To monitor image build and see the errors, you can connect to the VM via VNC, e.g., using a VNC client by RealVNC
After command execution, a disk image is created in .qcow2
format.
Upload the image to Object Storage
Upload the created image to Object Storage using one of the supported tools.
Import the image to Compute Cloud
Using the Compute Cloud API, you can import the image to the service:
yc compute image create --name <image name> --description <image description> --os-type windows --source-uri <link to image in Object Storage>
curl -H "Authorization: Bearer `yc iam create-token`" -H "accept: application/json" -X POST https://compute.api.cloud.yandex.net/compute/v1/images -d '{"folderId": "<ID of your folder>", "name": "<image name>", "description": "<image description>", "os": {"type": "WINDOWS"}, "pooled": false, "uri": "<link to image in Object Storage>"}'
function Create-YCImage {
param(
[ValidateNotNullOrEmpty()]
[string]$folderId = "",
[ValidateNotNullOrEmpty()]
[string]$name = "",
[string]$description = "",
[ValidateNotNullOrEmpty()]
[string]$os_type = "WINDOWS",
[int64]$minDiskSizeGb = 50GB,
[ValidateNotNullOrEmpty()]
[string]$uri = ""
)
$body = @"
{
"folderId": "$folderId",
"name": "$name",
"description": "$description",
"os.type": "$os_type",
"minDiskSize": "$minDiskSizeGb",
"os": {
"type": "$os_type"
},
"uri": "$uri"
}
"@
Invoke-WebRequest `
-Method POST `
-URI https://compute.api.cloud.yandex.net/compute/v1/images `
-header @{ "Authorization" = "Bearer $(& yc iam create-token)" } `
-ContentType 'Application/json' `
-body $body
}
$folderId = "<ID of your folder>"
Create-YCImage `
-folderId $folderId `
-name "<image name>" `
-uri "<link to image in Object Storage>"
You can use the imported image to create a VM boot disk.