1
votes

How do I start instance on GCE again after power off. Instance shows TERMINATED , but has PERSISTENT disk type.

if I use add instance with the same instance name it asks me for the Select an new image with only choice of OS level, not my existing disk. then fails with

ERROR: RESOURCE_ALREADY_EXISTS: The resource XXXX already exists

Is there way to start (or clone) copy of image once stopped? Anything similar to AWS stop/start. I don't care about instance state or scratch to be saved, just start since I have boot disk stored and payed for.

2

2 Answers

3
votes

Success, below is stop/start procedure, assuming that $PROJECT and $INSTANCE are set appropriately:

#--------- stop instance -----
#connect and shutdown
gcutil --project=$PROJECT ssh $INSTANCE
sudo shutdown -h now
# check
gcutil listinstances --project $PROJECT
#delete instance/keep boot disk , use -f to avoid confirmation
gcutil --project=$PROJECT deleteinstance $INSTANCE --nodelete_boot_pd
# check disks
gcutil listdisks --project=$PROJECT
#--------- start new instance -----
# launch instance using the existing disk (has to be in the same zone!)
gcutil --project=$PROJECT addinstance $INSTANCE --disk=$DISK,boot --zone=$ZONE --machine_type=n1-standard-1
#check that it's running
gcutil listinstances --project $PROJECT

0
votes

You're on the right track. You just need to delete the existing TERMINATED instance before adding it again.

Even though the instance isn't running when it is TERMINATED, the resources (such as Persistent Disk) are still allocated to it.

Also, if this instance was created before December 5th, (when Compute Engine went GA), you'll need to add a kernel to the disk or it won't boot. See the transition guide for details.

(For a temporary work around to upgrading the kernel, see this Q/A: My Google Compute Engine instances hang during boot using the v1 API)