> [!WARNING]
> **Preview:** Minimize the VM start time is a Preview feature that is available as-is and is not recommended for production environments. Google provides no Service-Level agreements (SLA) or technical support commitments for Preview features.

If you require your VMs to boot as quickly as possible, minimize your virtual
machine (VM) start time with the instructions on this page. Minimizing the start
time comes at the cost of resource efficiency---your project consumes additional
resources, and has an increased security surface.

## Before you begin

To use `gdcloud` command-line interface (CLI) commands, ensure that you have downloaded, installed,
and configured the [`gdcloud` CLI](https://docs.cloud.google.com/distributed-cloud/hosted/docs/latest/appliance/resources/gdcloud-overview).
All commands for GDC air-gapped appliance use the `gdcloud` or
`kubectl` CLI, and require an operating system (OS) environment.

### Get the kubeconfig file path

To run commands against the Management API server, ensure you have the following
resources:

1. Locate the Management API server name, or ask your Platform Administrator (PA)
   what the server name is.

2. [Sign in and generate](https://docs.cloud.google.com/distributed-cloud/hosted/docs/latest/appliance/application/ao-user/iam/sign-in#cli) the
   kubeconfig file for the Management API server if you don't have one.

3. Use the path to replace `MANAGEMENT_API_SERVER{"</var>"}}` in these instructions.

## Keep disk connections alive

When a VM starts, initiating a connection from the VM's node to the VM's disk
takes a few seconds. To make the VM start up faster, the disk connection must be
kept alive when the VM is shut down so that the disk connection doesn't
reinitiate on subsequent VM starts. To achieve this, when you [run the command](https://docs.cloud.google.com/distributed-cloud/hosted/docs/latest/appliance/application/ao-user/vms/manage-vms/operations-and-lifecycle/minimize-vm-start#enable-keep-alive)
to enable disk connection keep-alive the system automatically creates a dummy pod
that mounts all the VM's disks.

### Enable disk connection keep-alive

To keep disk connections alive for a VM called `VM_NAME`
in the project `PROJECT`, run
the following command. When you do, the system automatically creates the dummy
pod:

    kubectl --kubeconfig MANAGEMENT_API_SERVER patch virtualmachines.virtualmachine.gdc.goog VM_NAME -n PROJECT --type merge --patch $'
    metadata:
      annotations:
        disk.virtualmachine.gdc.goog/enable-connection-keep-alive: "true"
    '

Replace the variables throughout these instructions, using the following
definitions.

<br />

| Variable | Definition |
|---|---|
| `MANAGEMENT_API_SERVER` | The Management API server `kubeconfig` file. |
| `VM_NAME` | The name of the VM. |
| `PROJECT` | The GDC project in which the VM resides. |

<br />

When the disk connection keep-alive is enabled, a pod named
`disk-connection-keep-alive-VM_NAME` is created in the same
project as the VM. The next VM restart is faster, as are subsequent start times,
because the VM's disk connections are kept alive by the pod.

### Set up disk connection keep-alive affinity

The Kubernetes scheduler might select a different node for the VM when it restarts.
To reduce the chances of that happening, configure an
inter-VM affinity rule between the VM and the keep-alive pod. Configure this to happen automatically:

    kubectl --kubeconfig MANAGEMENT_API_SERVER patch virtualmachines.virtualmachine.gdc.goog VM_NAME -n PROJECT --type merge --patch $'
    metadata:
      annotations:
        disk.virtualmachine.gdc.goog/add-connection-keep-alive-affinity: "true"
    '

This adds a preferred-affinity setting on the VM to the keep-alive pod.

### Caveats

There are two caveats to keeping disk connections alive:

- The keep-alive pod incurs additional resource usage:
  - It counts towards the limit of the number of pods per node.
  - It uses an additional IP address that is assigned by Kubernetes.
  - It uses a negligible additional amount of CPU and memory.
- The security surface increases, because the node where the keep-alive pod is present always has the VM's disks attached, even when the VM is shut down.

## Use BIOS firmware

In GDC, starting a VM with Unified Extensible
Firmware Interface (UEFI) firmware is slower than starting a VM with BIOS
firmware.

1. To ensure that the start time is minimal, set the VM's firmware type to
   BIOS:

       kubectl --kubeconfig MANAGEMENT_API_SERVER patch virtualmachines.virtualmachine.gdc.goog VM_NAME -n PROJECT --type merge --patch $'
       spec:
         firmware:
           type: bios
           enableSecureBoot:
       '

2. If the VM is running, restart it using the instructions to
   [restart the VM](https://docs.cloud.google.com/distributed-cloud/hosted/docs/latest/appliance/application/ao-user/vms/manage-vms/operations-and-lifecycle/start-and-stop-vm#restart-a-vm).

### Caveats

The caveat to using BIOS firmware is that it doesn't support [secure boot](https://docs.cloud.google.com/distributed-cloud/hosted/docs/latest/appliance/application/ao-user/vms/manage-vms/secure-vms/secure-boot).

## Use a large boot disk

To minimize the VM start time, attach a boot disk with a size of 500 GB or
greater to the VM.