When working with Google Compute Engine (GCE), you often need to automate tasks like installing software, configuring firewalls, or running custom commands as soon as your VM boots up. This is where Startup Scripts come in.
🔹 What is a VM Startup Script?
A startup script is a file containing commands that automatically run when a VM instance boots.
- Supported on both Linux VMs and Windows VMs.
- Can be configured at VM-level or Project-level.
- VM-level startup scripts override project-level scripts.
👉 Example use case: If you want all VMs in a project to have the same script applied (like installing antivirus or monitoring agents), you can configure a project-level startup script.
🐧 Linux Startup Scripts
Types of Scripts
- Bash Scripts (most common).
- Non-Bash Scripts — supported if you specify an interpreter.
Example:
#! /usr/bin/python3
print("Hello from Python startup script")
What Happens Behind the Scenes?
When you provide a startup script:
- Compute Engine copies the script to the VM.
- It sets run permissions on the script.
- The script runs as root user when the VM boots.
📌 VM Startup Scripts – Key Details
✅ How many startup scripts can you use per VM?
You can configure multiple startup scripts.
✅ Order of Execution
Metadata Key: startup-script
- Scripts provided directly in metadata or locally → run first.
Metadata Key: startup-script-url
- Scripts stored in Cloud Storage (GCS) → run second.
✅ Script Size Limit
- Maximum allowed size: 256 KB
💡 Why Use Startup Scripts?
- Automatically install software (Apache, Nginx, Databases).
- Configure monitoring agents and logging tools.
- Apply project-wide policies without manually configuring each VM.
- Speed up provisioning by automating boot-time tasks.
📢 Play Games & Earn Money for FREE!
Want to make money without spending a single penny?
✅ FREE Sign - Up Bonus : Get $10 instantly when you sign up !
🎯 No investments need - just play and start earning today !
Sign up :
listwr.com/o75kZJ