Skip to main content

GCP - Cloning a secondary VM

This guide details the process of cloning a Google Cloud Platform (GCP) secondary VM instance. This method enables large-scale migrations by efficiently deploying numerous servers based on a pre-configured image.

1. Preparation for Cloning (on the VM to be cloned)

Before creating a clone, you must prepare the source VM. This involves running GCESysprep to generalize the Windows installation.

  1. Log on to the server you intend to clone.

  2. Open Command Prompt or PowerShell as an administrator.

  3. Run GCESysprep:

    • Type GCESysprep (without quotes).
    • Press Enter.
    Crucial Note: Failure to run GCESysprep will prevent the cloned VM instances (nodes) from communicating correctly. This command will automatically close your Remote Desktop Protocol (RDP) session and shut down the VM upon completion.

2. Setting Auto-Delete State of the Persistent Disk (in GCP Console)

To ensure the boot disk is preserved when the VM instance is deleted, you must configure its auto-delete setting.

  1. Navigate to VM instances: In the GCP Console, go to Compute Engine > VM instances from the left-hand navigation menu.
  2. Select the Sysprep-prepared VM from the list.
  3. Configure Boot Disk Deletion:
    • Locate the Storage section.
    • Under Boot disk, ensure 'When deleting instance' is set to 'Keep disk'.
    • If the setting is not 'Keep disk', click 'Edit' at the top of the page.
    • Change the 'When deleting instance' setting to 'Keep disk'.
  4. Save the changes.

3. Deleting the Instance (while keeping the disk)

After configuring the disk to be retained, you can safely delete the VM instance.

  1. Stay on the VM Instances page.

  2. Select the VM (the one you just Sysprepped and configured to keep its disk).

  3. Click 'Delete' at the top of the page.

    Note: Step 2 (setting 'Keep disk') ensures that deleting the VM instance preserves its associated boot disk, which is essential for creating a custom image.

4. Creating a Custom Image from the Disk

A custom image allows you to create new VM instances with the exact configuration of your Sysprep-prepared disk.

  1. Go to Storage > Images in the GCP Console.
  2. Click 'Create Image'.
  3. Configure the Image:
    • Name: Enter a descriptive name (e.g., custom-sysprepped-vm).
    • Source: Select 'Disk'.
    • Source Disk: Choose the disk associated with the deleted VM from the previous steps.
    • All other settings can typically be left as default.
  4. Click 'Create' to create the image.

5. Creating an Instance Template from the Custom Image

Instance templates define the machine type, boot disk, and other properties for VM instances created from them.

  1. Go to Virtual machines > Instance Templates in the GCP Console.
  2. Click 'Create Instance Template'.
  3. Select your desired machine type.
  4. Select your newly created custom image as the Boot disk.
  5. Configure Networking:
    • In Advanced options > Networking, select the Default network.
    • If you have created a custom Virtual Private Cloud (VPC) network, you may choose that instead.
  6. Click 'Create' to create the instance template.

6. Creating an Instance Group from the Instance Template

Instance groups allow you to manage and scale a collection of identical VM instances.

  1. Go to Instance Groups > Instance Groups in the GCP Console.
  2. Click 'Create Instance Group'.
  3. Select your new Instance template.
  4. Specify the number of VMs you wish to create in this group.
  5. Click 'Create' to create the instance group.
Was this article helpful?
0 out of 0 found this helpful