Skip to content

Instantly share code, notes, and snippets.

@kamarton
Last active March 15, 2025 15:54
Show Gist options
  • Save kamarton/aa80eb06b4b931c7edfb7124f103a503 to your computer and use it in GitHub Desktop.
Save kamarton/aa80eb06b4b931c7edfb7124f103a503 to your computer and use it in GitHub Desktop.
Create disk from snapshot attach to compute engine and start it (GCP, CLI, GCLOUD)
#!/usr/bin/env bash
PROJECT=<project>
ZONE=<zone>
INSTANCE=<compute-engine-instance>
DISK=<disk-name>
SNAPSHOT=<snapshot-name>
REGION=<region>
echo create disk from snapshot - - - - - - - - - - - - - - -
gcloud compute disks create $DISK \
--source-snapshot $SNAPSHOT \
--zone $ZONE \
--type pd-ssd \ # disk type
--project=$PROJECT
echo attach to vm - - - - - - - - - - - - - - - - - - - - - -
gcloud compute instances attach-disk $INSTANCE \
--disk $DISK --boot \
--project=$PROJECT \
--zone $ZONE
echo start vm - - - - - - - - - - - - - - - - - - - - - -
gcloud compute instances start $INSTANCE \
--zone $ZONE \
--project=$PROJECT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment