Creating, deleting, and deprecating custom images


You can create custom images from source disks, images, snapshots, or images stored in Cloud Storage. You can use these images to create virtual machine (VM) instances. This is ideal for situations where you have created and modified a persistent boot disk or specific image to a certain state and need to save that state for creating instances.

Alternatively, you can use the virtual disk import tool to import boot disk images to Compute Engine from your existing systems and add them to your custom images list.

Before you begin

Creating a custom image

These instructions describe how to create a custom image on a Linux instance. For instructions for creating a Windows image, see Creating a Windows image.

You must use Identity and Access Management (IAM) permissions to share images with other projects.

Selecting an image storage 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 stores your image in the multi-region closest to the image source.

To see the location where an image is currently stored, use the images describe command from gcloud compute:

gcloud compute images describe image-name --project project-id

⋮
storageLocations:
- us-central1

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.

Preparing your instance for an image

You can create an image from a disk even while it is attached to a running VM instance. However, your image will be more reliable if you put the instance in a state that is easier for the image to capture. Use one of the following processes to prepare your boot disk for the image:

  • Stop the instance so that it can shut down and stop writing any data to the persistent disk.

  • If you can't stop your instance before you create the image, minimize the amount of writes to the disk and sync your file system.

    1. Pause apps or operating system processes that write data to that persistent disk.
    2. Run an app flush to disk if necessary. For example, MySQL has a FLUSH statement. Other apps might have similar processes.
    3. Stop your apps from writing to your persistent disk.
    4. Run sudo sync.

After you prepare the instance, create the image.

Creating the 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
  • A compressed RAW image in Cloud Storage

You can create a disk image once every ten minutes. If you want to issue a burst of requests to create a disk image, you can issue at most 6 requests in 60 minutes. For more information, see Snapshot frequency limits.

Console

  1. In the Google Cloud Console, go to the Create an image page.
    Go to the Create an image page
  2. Specify the Name of your image.
  3. Specify the Source from which you want to create an image. This can be a persistent disk, a snapshot, another image, or a disk.raw file in Cloud Storage.
  4. Specify the Location at which to store your image. Choose your image storage location from the Based on source disk location (default) drop-down list. For example, specify us to store the image in the us multi-region, or us-central1 to store it in the us-central1 region. If you don't make a selection, Compute Engine stores the image in the multi-region closest to your image's source location.
  5. 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.
  6. Click Create to create the image.

gcloud

In the gcloud command-line tool, use the gcloud compute images create command to create a custom image.

Create an image from a source disk:

gcloud compute images create image-name \
  --source-disk source-disk \
  --source-disk-zone zone \
  --family image-family \
  --storage-location location \
  --force

Replace the following:

  • image-name: A name for the new image.
  • source-disk: The disk from which you want to create the image.
  • zone: The zone where the disk is located.
  • image-family: An optional flag that specifies which image family this image belongs to.
  • location: An optional flag that lets you designate the region or multi-region where your image is going to be stored. For example, specify us to store the image in the us multi-region, or us-central1 to store it in the us-central1 region. If you don't make a selection, Compute Engine stores the image in the multi-region closest to your image's source location.
  • [--force]: An optional flag that allows you to create the image from a running instance. By default, you cannot create images from running instances. Specify this flag only if you are sure that you want to create the image while the instance is running.

Create an image from a source image:

gcloud compute images create image-name \
  --source-image source-image \
  --source-image-project image-project \
  --family image-family \
  --storage-location location

Replace the following:

  • image-name: A name for the new image.
  • source-image: The image from which you want to create the new image.
  • image-project: An optional parameter that specifies which project the source image is located in. Use this parameter if you want to copy an image from another project.
  • image-family: An optional flag that specifies which image family this new image belongs to.
  • location: An optional flag that allows you to designate the region or multi-region where your image is going to be stored. For example, specify us to store the image in the us multi-region, or us-central1 to store it in the us-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.

Create an image from a snapshot:

gcloud compute images create image-name \
  --source-snapshot source-snapshot \
  --storage-location location

Replace the following:

  • image-name: A name for the new image.
  • source-snapshot: The snapshot from which you want to create the image.
  • location: An optional flag that allows you to designate the region or multi-region where your image is going to be stored. For example, specify us to store the image in the us multi-region, or us-central1 to store it in the us-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.

View an image location:

Use the gcloud compute images describe command to view an image location. Replace image-name with the name of your image that you want to review.

gcloud compute images describe image-name

API

Make a POST request to the images().insert method, a URL in the request body that points to the source object from which you want to create the image. Specify URLs to your resources using your own project ID and resource names.

Create an image from a persistent disk:

POST https://compute.googleapis.com/compute/v1/projects/project-id/global/images

{
  "name": "image-name",
  "sourceDisk": "/zones/zone/disks/source-disk",
  "storageLocations": "location",
  "forceCreate": "TRUE"
}

Replace the following:

  • project-id: The project to which the image belongs.
  • image-name: A name for the new image that you want to create.
  • zone: The zone where the source disk is located.
  • source-disk: The disk from which you want to create the image.
  • location: An optional parameter that lets you select the storage location of your image. For example, specify us to store the image in the us multi-region, or us-central1 to store it in the us-central1 region. If you don't make a selection, Compute Engine stores the image in the multi-region closest to your image's source location.
  • [FORCE_CREATE]: An optional parameter that lets you create the image from a running instance. Specify TRUE only if you are sure that you want to create the image from a running instance. The default value if you do not specify this parameter is FALSE.

Create an image from another image:

POST https://compute.googleapis.com/compute/v1/projects/project-id/global/images

{
  "name": "image-name",
  "sourceImage": "/global/images/source-image",
  "storageLocations": "location"
}

Replace the following:

  • project-id: The project to which the image belongs.
  • image-name: A name for the new image that you want to create.
  • source-image: The image from which you want to create the image.
  • location: An optional parameter that allows you to select the storage location of your image. For example, specify us to store the image in the us multi-region, or us-central1 to store it in the us-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.

Create an image from a snapshot:

POST https://compute.googleapis.com/compute/v1/projects/project-id/global/images
{
  "name": "image-name",
  "sourceSnapshot": "/source-project-id/global/snapshots/source-snapshot",
  "storageLocations": "location"
}

Replace the following:

  • project-id: The project to which the image belongs.
  • image-name: A name for the new image that you want to create.
  • source-snapshot: The snapshot from which you want to create the image.
  • source-project-id: An optional variable that specifies which project the snapshot is located in. You must have permission to access the snapshot resource in that project.
  • location: An optional parameter that allows you to select the storage location of your image. For example, specify us to store the image in the us multi-region, or us-central1 to store it in the us-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.

Deprecating an image

Compute Engine lets you deprecate a custom image that you own by setting the deprecation status on the image. Each deprecation status causes a different response from the server, helping you transition users away from unsupported images in a manageable way. Use the console, gcloud command, or the Compute Engine API method to deprecate an image.

Deprecation states

The following deprecation states are supported:

  • ACTIVE: The image is active and can be used as normal. Image families point to the most recent and active image in a family.
  • DEPRECATED: The image is marked deprecated, but can still be used. If you use an image that is deprecated, the request succeeds with a warning. New links to this image is allowed. Image families no longer point to this image even if it is the most recent image in the family.
  • OBSOLETE: The image is marked obsolete and is no longer available for use. An error message is returned if you try to use this image in a request. Existing links to this image are still allowed.
  • DELETED: This image is deleted. An error message is returned if you try to use a deleted image.

You can revert a deprecation (make an image active again), by changing the deprecation state to ACTIVE.

Console

  1. In the Google Cloud Console, go to the Images page.
    Go to the Images page
  2. Check the box to the left of the image you want to deprecate.
  3. Click Deprecate at the top of the page. Your image is deprecated.

gcloud

Use the gcloud compute images deprecate command to set the deprecation status of an image.

gcloud compute images deprecate image-name \
    --state state \
    --replacement replacement

Replace the following:

  • image-name: The name of the image to deprecate.
  • state: The deprecation state.
  • replacement: The image to replace the one that is deprecated.

API

Make a POST request to the images().deprecate method. Specify the name of the image you want to deprecate.

POST https://compute.googleapis.com/compute/v1/projects/project-id/global/images/resource-id/deprecate

{
  "state": "state",
  "replacement": "replacement"
}

Replace the following:

  • project-id: The project to which the image belongs.
  • resource-id: The name of the image that you are deprecating.
  • state: The deprecation state of this resource.
  • replacement: The image to replace the one that is deprecated.

Deleting an image

You can only delete custom images that you, or someone who has access to the project, have added. Use the console, gcloud command, or the Compute Engine API method to delete the image.

Console

  1. In the Google Cloud Console, go to the Images page.
    Go to the Images page
  2. Check the box to the left of the image you want to delete.
  3. Click Delete at the top of the page. Your image is deleted.

gcloud

Use the gcloud compute images delete command to delete an image. Replace image-name with the name of the image to delete.

gcloud compute images delete image-name

API

Make a POST request to images().delete method. Specify the name of the image you want to delete.

POST https://compute.googleapis.com/compute/v1/projects/project-id/global/images/resource-id

Replace the following:

  • project-id: The project to which the image belongs.
  • resource-id: The name of the image that you want to delete.

Setting image versions in an image family

Use image families to simplify image versioning. Add an image to an image family to set it as the most recent image version. If you determine that you must roll back the image family to a previous image version, deprecate the most recent image in the family.

For best practices when working with image families, see Image families best practices.

Optionally, you can specify the image's storage location, using the console, the gcloud compute images create command with the --storageLocation flag, or the images().insert API method.

For example, create an image named image-v1 as part of an image family.

Console

  1. In the Google Cloud Console, go to the Create an image page.
    Go to the Create an image page
  2. Specify the Name of your image.
  3. Specify the Source from which you want to create an image. This can be a persistent disk, a snapshot, another image, or a disk.raw file in Google Cloud Storage.
  4. Specify the Location where you will store your image. Choose your image storage location from the Based on source disk location (default) drop-down menu. For example, specify us to store the image in the us multi-region, or us-central1 to store it in the us-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.

  5. Specify the properties for your image. For example, you can specify the image family name my-image-family for your image to organize this image as part of an image family.

  6. If you are creating an image from a disk attached to a running image, check "Force creation from running instance" to confirm that you want to create the image while the instance is running.

  7. Click Create to create the image.

gcloud

gcloud compute images create image-v1 \
    --source-disk disk-1 \
    --source-disk-zone us-central1-f \
    --family my-image-family

The image family points to image-v1. Add a second image to the family:

gcloud compute images create image-v2 \
    --source-disk disk-2 \
    --source-disk-zone us-central1-f \
    --family my-image-family

API

Make a POST request to the images().insert method. Specify the image family in the request body.

POST https://compute.googleapis.com/compute/v1/projects/project-id/global/images

{
  "name": "image-v2",
  "sourceDisk": "/zones/us-central1-f/disks/disk-2",
  "family":"my-image-family",

}

The image family points to image-v2 because it is the most recent image that you added to the image family.

gcloud

You can see which image a family points to by running the gcloud compute images describe-from-family command.

For example:

gcloud compute images describe-from-family my-image-family

family: my-image-family
id: '8904691942610171306'
kind: compute#image
name: image-v2
selfLink: https://compute.googleapis.com/compute/v1/projects/my-project/global/images/image-v2
sourceDisk: https://compute.googleapis.com/compute/v1/projects/my-project/zones/us-central1-f/disks/disk-v2
sourceDiskId: '1677449456001963379'
sourceType: RAW
status: READY

API

Make a GET request to the images().getFromFamily method. Specify the image family in the request body.

GET https://compute.googleapis.com/compute/v1/projects/project-id/global/images/family

{
  "resourceId":"my-image-family",

}

If you determine that you must roll back the image family so that it no longer points to image-v2, deprecate image-v2 and the family will again point to image-v1.

gcloud compute images deprecate image-v2 \
    --state DEPRECATED \
    --replacement image-v1

Check to make sure that the image family is pointing to image-v1.

gcloud compute images describe-from-family my-image-family

family: my-image-family
id: '2741732787056801255'
kind: compute#image
name: image-v1
selfLink: https://compute.googleapis.com/compute/v1/projects/my-project/global/images/image-v1
sourceDisk: https://compute.googleapis.com/compute/v1/projects/my-project/zones/us-central1-f/disks/disk-v1
sourceDiskId: '1677449456001963379'
sourceType: RAW
status: READY

Enabling guest operating system features on custom images

Guest operating system features let you configure the following networking, security, storage, and operating system options on custom images that will also be used as boot disks:

  • Multi-IP subnets: For configuring interfaces with a netmask other than /32
  • UEFI compatibility: For booting with UEFI firmware and the following Shielded VM features:
  • Multiqueue SCSI on local SSD devices as an alternative to NVMe:
    • For Linux images, you can enable multiqueue SCSI on local SSD devices on images with kernel versions 3.17 and later.
    • For Windows images, you can enable multiqueue SCSI on local SSD devices on images with driver version 1.2.0.1621 or higher.
  • Windows support: You must tag Windows Server custom boot images as Windows images.

gcloud

Use the gcloud compute images create command with the --guest-os-features flag to create a new custom image from an existing custom image.

gcloud compute images create IMAGE_NAME --source-image SOURCE_IMAGE --source-image-project IMAGE_PROJECT --guest-os-features="FEATURES,..." --storage-location LOCATION

Replace the following:

  • IMAGE_NAME: Name for the new image.
  • SOURCE_IMAGE: Image to base the new image on.
  • IMAGE_PROJECT: Optional: Project containing the source image. Use this parameter to copy an image from another project.
  • FEATURES: IDs, separated by commas, of guest OS features to enable for the image. Set to one or more of: MULTI_IP_SUBNET, UEFI_COMPATIBLE, VIRTIO_SCSI_MULTIQUEUE, WINDOWS.
  • LOCATION: Optional: Region or multi-region to store the image. For example, specify us to store the image in the us multi-region, or us-central1 to store it in the us-central1 region. If you don't make a selection, Compute Engine stores the image in the multi-region closest to your image's source location.

API

Use the images().insert method with the guestOsFeatures flag to create a new custom image from an existing custom image.


POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images

{
 "name": "IMAGE_NAME",
 "sourceImage": "projects/IMAGE_PROJECT/global/images/SOURCE_IMAGE",
 "storageLocations": "LOCATION",
 "guestOsFeatures": [
  {
   "type": "FEATURES"
  }
 ]
}

Replace the following:

  • PROJECT_ID: ID of the project to create the new image in.
  • IMAGE_NAME: Name for the new image.
  • SOURCE_IMAGE: Image to base the new image on.
  • IMAGE_PROJECT: Optional: Project containing the source image. Use this parameter to copy an image from another project.
  • LOCATION: Optional: Region or multi-region to store the image. For example, specify us to store the image in the us multi-region, or us-central1 to store it in the us-central1 region. If you don't make a selection, Compute Engine stores the image in the multi-region closest to your image's source location.
  • FEATURES: IDs, separated by commas, of guest OS features to enable for the image. Set to one or more of: MULTI_IP_SUBNET, UEFI_COMPATIBLE, VIRTIO_SCSI_MULTIQUEUE, WINDOWS.

What's next