Building your virtual machine (VM) image

This page helps you create a public machine image for your product to run on Compute Engine.

An image contains a boot loader, an operating system, and a root file system that is necessary for starting an instance. You can configure the image with a set of apps and services for your product. The image is used by customers to launch a virtual machine (VM) instance in the cloud.

We recommend you start with creating an image in your development project, and then move it to your public project after your Google Partner Engineer has verified the image.

Before you begin

  1. Download the Google Cloud SDK.

Create the base product VM

To create a custom machine image for Google Cloud Marketplace, you need to complete these steps (described in the sections that follow):

Create a licensed VM image

  1. Use gcloud to set defaults for the Cloud SDK:

    gcloud config set project <project_id>
    gcloud config set compute/zone <zone>
  2. Create a primary instance that will be used to install your software, and later, converted to an image to use on Google Cloud Marketplace. For more information about creating an instance, see Creating and starting an instance.

    gcloud compute instances create ${INSTANCE} --scopes 
  3. Install and customize your software. Include any startup scripts required, such as those for creating authorization credentials.

    To create authorization credentials using secure randomized passwords, follow the steps in Creating authorization credentials, on this page.

  4. Add open source license text files and source code on the VM (if applicable). Refer to the open source compliance document for requirements.

    When you've created and customized the primary instance, prepare the disk which is needed to create a VM image.

  5. Clean up your disk. Creating a VM image directly from your VM will also transfer your user directories and SSH keys into your customers' VMs, so you must clean the disk that is used as the input disk when creating your VM image. To clean the disk:

    1. In the Compute Engine VM Instances menu, click the name of the instance you want to clean up, and then click Edit.

    2. Scroll down and uncheck Delete boot disk when instance is deleted and click Save. You'll need the disk to create the image.

    3. Delete the VM while preserving the disk. You will be prompted to confirm the deletion. Do not select Also delete boot disk.

    4. Next, you need to create a new VM Instance. Expand the Management, disk, networking, SSH keys options.

    5. Under disk, attach the disk from your previous instance as an additional data disk. Ensure that Keep disk is selected for When deleting instance.

      You can now SSH into the instance and remove any home directories or other temporary files created during the software installation process. You will need to mount the data disk before you can access it. For more information on mounting disks, see Adding or Resizing Persistent Disks.

    6. When you're done, shutdown and delete the instance while preserving your updated data disk. Now you can create a VM image by completing the following steps.

  6. Get the license name for your product in Partner Portal by using these steps:

    1. Click the solution ID for your product.

    2. Click to edit the Solution Metadata.

    3. In the solution metadata, in the Licensing & Pricing section, under License name, note your license name. You use this license name later, when you use gcloud to create your image.

  7. Create a licensed image by running the following gcloud command:

    gcloud compute images create CREATE_IMAGE_NAME \
     --project PUBLIC_PROJECT_NAME \
     --source-disk projects/DEV_PROJECT_NAME/zones/SOURCE_DISK_ZONE/disks/SOURCE_DISK_NAME \
     --licenses projects/PUBLIC_PROJECT_NAME/global/licenses/LICENSE_NAME \
     --description ADD_DESCRIPTION

Creating authorization credentials

If your product is a simple deployment of a single VM instance with basic firewall rules, then you can automatically include a secure randomized password when you configure your deployment package directly in Partner Portal.

If you plan to create your deployment package by using the open source mpdev tool, which we recommend for most use cases, then you can use mpdev to automatically include multiple secure randomized passwords.

After your product has been deployed, to obtain the values of any passwords that you created, use the following command from within your VM instance:

curl -H "Metadata-Flavor: Google" \

Test the VM image

Create a VM instance with your newly created image, and verify the functionality.

Also, to verify the license ID, SSH into the instance and verify that valid licenses are attached:

curl -s -H "Metadata-Flavor: Google"

Verify that Python 2.6 or greater is installed:

python -V

Verify that the following packages are installed:

gcloud --version
gsutil --version
ssh -V
ps aux | grep sshd
curl -V
ps aux | grep dhcp

Check to ensure that there are no other user directories installed on the instance except for your own, and that there are not any remaining user directories and credentials other than your own.