You can create customized Windows Server images from existing Compute Engine Windows Server images. Use these custom images to create instances with boot disks that are the same as your existing instances.
These custom images are useful for saving the operating system configuration of your existing instances and reusing the same configuration to create other instances.
The following tasks are not covered in this section:
- Create a VM from a public image or a custom image; instead see Creating a new Windows instance.
- Schedule a backup of your persistent disks; instead see persistent disk snapshots.
- Import Windows Server or SQL Server systems; instead use the VM migration service.
Before you begin
-
If you haven't already, then set up authentication.
Authentication is
the process by which your identity is verified for access to Google Cloud services and APIs.
To run code or samples from a local development environment, you can authenticate to
Compute Engine by selecting one of the following options:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
-
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
- Set a default region and zone.
Go
To use the Go samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
For more information, see Set up authentication for a local development environment.
Java
To use the Java samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
For more information, see Set up authentication for a local development environment.
Node.js
To use the Node.js samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
For more information, see Set up authentication for a local development environment.
Python
To use the Python samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
For more information, see Set up authentication for a local development environment.
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
-
Prepare to create a Windows Server image
Before you create the image, run GCESysprep
on the instance to prepare it for
the image creation process.
GCESysprep
prepares an instance for becoming a Compute Engine image by
completing the following steps:
- Disables the
GCEStartup
scheduled task. - Deletes all files from temp folder location.
- Clears all Windows event logs.
- Runs sysprep.exe /generalize /oobe /quit /unattend
- Configures
instance_setup.ps1
to run on the first boot of the VM instance. - Deletes the RDP Certificate.
- Removes the stored list of persistent disks.
- Enables RDP and WinRM firewall rules.
- Disables the Google OS Config service.
- Shuts down the instance.
GCESysprep
operations are logged to the Windows event log and serial port 1.
Sysprep writes to multiple
log files.
How to create a Compute Engine image using GCESysprep
:
Run
GCESysprep
with administrative rights.GCESysprep
Specify an image location
When creating a custom image, you can specify the image's Cloud Storage location, excluding dual-region locations. By specifying the image storage location, you can meet your regulatory and compliance requirements for data locality as well as your high availability needs by ensuring redundancy across regions.
The storage location feature is optional. If you do not select a location, Compute Engine will store your image in the multi-region closest to the image source. You can create custom images from source disks, images, snapshots, or images stored in Cloud Storage. You can use these images to create new VM instances.
All of your existing images prior to this feature launch remain where they are. The only change is that you can view the image location of all your images. If you have an existing image you want to move, you must recreate it in the desired location.
Create a Windows image
You can create disk images from the following sources:
- A persistent disk, even while that disk is attached to an instance
- A snapshot of a persistent disk
- Another image in your project
- An image that is shared from another project
An imported image stored in Cloud Storage
Console
- In the Google Cloud console, go to the Create a new image page.
- Specify the image Name.
- Choose a Source disk with a Windows operating system from which you want to create an image.
- Specify the Location to store the image. Choose an image
location from the Based on source disk location (default)
drop-down menu. For example, specify
us
to store the image in theus
multi-region, orus-central1
to store it in theus-central1
region. If you do not make a selection, Compute Engine will store the image in the multi-region closest to your image's source location. - Specify the properties for your image. For example, you can specify an image family name for your image to organize this image as part of an image family.
- Click Create.
gcloud
Use the gcloud compute
with
images create
, and provide
the source persistent disk from which you want to create an image.
Optionally, include the --force
flag to create the image even if it is
attached to a running instance.
gcloud compute images create example-image --source-disk [DISK_NAME] \
--source-disk-zone [ZONE] \
--storage-location [LOCATION] \
[--force]
[DISK_NAME]
is the name of the source disk to create the image from.[ZONE]
is the zone of the disk.[LOCATION]
is an optional flag that allows you to designate the region or multi-region where your image is going to be stored. For example, specifyus
to store the image in theus
multi-region, orus-central1
to store it in theus-central1
region. If you do not make a selection, Compute Engine will store the image in the multi-region closest to your image's source location.--force
is an optional flag that creates the image even if the disk is attached to an instance that is still running. This option might compromise the integrity of your image. Stop the instance before you create the image if possible.
When you run this command, gcloud compute
creates a new image based on
the persistent disk you provided and adds it to your collection. You can
confirm that your image was successfully created by running:
gcloud compute images list
Go
Before trying this sample, follow the Go setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Go API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
Before trying this sample, follow the Java setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Java API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
Node.js
Before trying this sample, follow the Node.js setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Node.js API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
Python
Before trying this sample, follow the Python setup instructions in the Compute Engine quickstart using client libraries. For more information, see the Compute Engine Python API reference documentation.
To authenticate to Compute Engine, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
REST
Make a POST
request to the
images().insert
method, with a sourceDisk
URL in the request body.
POST https://compute.googleapis.com/compute/v1/projects/[PROJECT_ID]/global/images?[FORCE_OPTION]
{
"name": "[IMAGE_NAME]",
"sourceDisk": "zones/[ZONE]/disks/[DISK_NAME]",
"storageLocations": "[LOCATION]",
}
where:
[PROJECT_ID]
is the project ID for this request.[FORCE_OPTION]
is an option to create the image even if the source disk is attached to a running instance. SpecifyforceCreate=true
at the end of your POST line to set this option. This option might compromise the integrity of your image. Stop the instance before you create the image if possible.[IMAGE_NAME]
is the name to give this image.[ZONE]
is the zone of the source disk to create an image from.[DISK_NAME]
is the name of the source disk.[LOCATION]
is an optional parameter that allows you to select the multi-region or a region storage location of your image. For example, specifyus
to store the image in theus
multi-region, orus-central1
to store it in theus-central1
region. If you do not make a selection, Compute Engine will store the image in the multi-region closest to your image's source location.
For more information about adding images, see the images reference.
Update Windows agents and scripts
Compute Engine occasionally releases new Windows images with the latest agents and scripts. These items assist Windows instances with startup and shutdown processes, account management, and address management.
Since Windows image version v20160112
, the Windows agent updates itself with
upstream releases. You can disable these agent updates by setting the
disable-agent-updates
instance metadata key to true
. If you have instances
that are based on older image releases, you can
manually update the Windows agent of those instances.