A startup script is a file that contains commands that run when a virtual
machine (VM) instance boots. Compute Engine provides support for running
startup scripts on Linux VMs and Windows VMs.

## Prerequisites

To run scripts stored in metadata on a VM instance, the [guest environment](https://docs.cloud.google.com/compute/docs/images/guest-environment) must be installed and running.

- The guest environment includes the [guest agent](https://docs.cloud.google.com/compute/docs/images/guest-agent) (for example, google-guest-agent on Linux) that reads the script content or URL from the instance's metadata and initiates execution.
- All public Compute Engine images come with the guest environment preinstalled.
- If you create a custom image, you must [manually install the Google Guest Environment](https://docs.cloud.google.com/compute/docs/images/install-guest-environment) to ensure scripts from metadata and other Google Cloud features function properly.

The following table contains links to documentation that describes how to use
startup scripts.
Startup script task Best used for Link to procedure Pass a startup script directly Scripts up to 256 KB [Linux VMs](https://docs.cloud.google.com/compute/docs/instances/startup-scripts/linux#passing-directly) [Windows VMs](https://docs.cloud.google.com/compute/docs/instances/startup-scripts/windows#passing-directly) Pass a startup script from a local file Scripts up to 256 KB [Linux VMs](https://docs.cloud.google.com/compute/docs/instances/startup-scripts/linux#passing-local) [Windows VMs](https://docs.cloud.google.com/compute/docs/instances/startup-scripts/windows#passing-local) Pass a startup script from Cloud Storage Scripts greater than 256 KB [Linux VMs](https://docs.cloud.google.com/compute/docs/instances/startup-scripts/linux#passing-storage) [Windows VMs](https://docs.cloud.google.com/compute/docs/instances/startup-scripts/windows#passing-storage) Access metadata from a startup script Passing different values to each VM that uses the same script [Linux VMs](https://docs.cloud.google.com/compute/docs/instances/startup-scripts/linux#accessing-metadata) [Windows VMs](https://docs.cloud.google.com/compute/docs/instances/startup-scripts/windows#accessing-metadata) Rerun a startup script Running a script without restarting the VM [Linux VMs](https://docs.cloud.google.com/compute/docs/instances/startup-scripts/linux#rerunning) [Windows VMs](https://docs.cloud.google.com/compute/docs/instances/startup-scripts/windows#rerunning) View the output from a startup script Monitoring the progress of a script [Linux VMs](https://docs.cloud.google.com/compute/docs/instances/startup-scripts/linux#viewing-output) [Windows VMs](https://docs.cloud.google.com/compute/docs/instances/startup-scripts/windows#viewing-output)

## What's next

- Learn how to [add a shutdown script](https://docs.cloud.google.com/compute/docs/shutdownscript).
- Learn how to [use startup scripts on Linux VMs](https://docs.cloud.google.com/compute/docs/instances/startup-scripts/linux).
- Learn how to [use startup scripts on Windows VMs](https://docs.cloud.google.com/compute/docs/instances/startup-scripts/windows).