Importing a Generation 2 Disk image on GCP

Uploading and importing the image on GCP 

  1. Upload the VHD you just created on the GCP S3 bucket. 

  2. After the upload is completed, run the following SDK command to import into a GCP custom image. Please note the flag “UEFI_COMPATIBLE" which should be metioned for UEFI enabled images. 

> gcloud compute images import win10-21h1-gen2 --os=windows-10-x64-byol --source-file="gs://customer-success-images/win10-21h1-gen2.vhd" --project "training-294104" --network=wsbeta-gcp-vpc --subnet=wstraining-usc1 --guest-os-features="UEFI_COMPATIBLE" 

Deploying a VM from the newly imported base image: 

Create an instance by using the gcloud compute instances create command, and use the --image and --image-project flag to specify the image name and the project where the image resides:  

gcloud compute instances create [INSTANCE_NAME] --image [IMAGE] --image-project [IMAGE_PROJECT]  

Example:   

gcloud compute instances create win10-21h1-gen2v1 --project=training-294104 --zone=us-east5-c --machine-type=n2-standard-2 --network-interface=network-tier=PREMIUM,stack-type=IPV4_ONLY,subnet=wstraining-useast5 --maintenance-policy=TERMINATE --provisioning-model=STANDARD --service-account=38893795949-compute@developer.gserviceaccount.com --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append --enable-display-device --create-disk=auto-delete=yes,boot=yes,device-name=win10-21h1-gen2v1,image=projects/training-294104/global/images/win10-21h1-gen2,mode=rw,size=127,type=projects/training-294104/zones/us-east5-c/diskTypes/pd-balanced --no-shielded-secure-boot --shielded-vtpm --shielded-integrity-monitoring --labels=goog-ec-src=vm_add-gcloud --reservation-affinity=any 

Please note that in the above example we enabled vTPM and Shielded-integrity-monitoring on this VM. 

Gcloud Article - https://cloud.google.com/compute/docs/instances/create-start-instance#creating_an_instance_from_a_custom_image

Installing Google Guest Environment packages: 

Once the VM is deployed login and Install the core packages google-compute-engine-windows, google-compute-engine-metadata-scripts,google-compute-engine-sysprep, and google-compute-engine-vss.  

googet -noconfirm install google-compute-engine-windows google-compute-engine-sysprep google-compute-engine-metadata-scripts google-compute-engine-vss  

Additionally you should also install the The Network Drivers for the NIC – NetKVM Drivers and Optionally GGA Display Drivers in case you are enabling “Use Display Adapter” (Refer : https://cloud.google.com/compute/docs/instances/enable-instance-virtual-display) on the VM Edit page on Gcloud console. Give the following command to install the drivers  

Googet install google-compute-engine-driver-netkvm  

Googet install google-compute-engine-driver-gga.googet   

C:\windows\system32>  googet -noconfirm install google-compute-engine-driver-netkvm google-compute-engine-driver-vioscsi google-compute-engine-driver-pvpanic google-osconfig-agent google-compute-engine-driver-balloon google-compute-engine-driver-gga  

GCloud Article: https://cloud.google.com/compute/docs/images/install-guest-environment  

Install Workspot Template Agent  

Please follow the regular steps to install the Workspot Template Agent and Configure it. 

Along with it, please proceed with installing your applications and making the cusotm changes that this template is required to have.  

Creating Template:  

Once the agent is registered and other customizations done as per requirement, we must now convert the VM into a template, for this we should first deploy an Image from the template VM Disk and then create an Instance Template.  

Create an Image from the template disk  

In the Google Cloud Console, Click on Images on the left window, Click on Create an image.  

SDK Command: 

gcloud compute images create win10-gen2-ti \ 

    --project=training-294104 \ 

    --family=windows \ 

    --source-disk=win10-21h1-gen2 \ 

    --source-disk-zone=us-east5-c \ 

    --storage-location=us 

Create an Instance Template from this Template image:  

Create an instance Template from this new template image by using the gcloud compute instances create command, and use the --image and --image-project flag to specify the image name and the project where the image resides:  

gcloud compute instance-templates create [INSTANCE-TEMPLATE_NAME] –image [IMAGE] –image-project [IMAGE_PROJECT]  
  • Make sure you provide the Instance Template name exactly as that of the Template VM 

  • This is important because control would not be able to register it unless the name is the same. 

Example: 

C:\Program Files (x86)\Google\Cloud SDK>gcloud compute instance-templates create win10-21h1-gen2v1 --project=training-294104 --machine-type=n2-standard-4 --network-interface=subnet=wstraining-usw1,no-address --maintenance-policy=TERMINATE --provisioning-model=STANDARD --service-account=38893795949-compute@developer.gserviceaccount.com --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append --region=us-west1 --create-disk=auto-delete=yes,boot=yes,device-name=win10-21h1-gen2v1,image=projects/training-294104/global/images/win10--gen2v1-t,mode=rw,size=127,type=pd-balanced --no-shielded-secure-boot --shielded-vtpm --shielded-integrity-monitoring