2

gcp-console-startup-script

After I create a vm with startup script, where can I find startup script in vm ?

Will this startup script store in vm or outsite the vm ?

If I want to edit my startup script, how could it edit it ?

1
  • 1
    I found I can use gcloud compute instances add-metadata example-instance \ --metadata-from-file startup-script=path/to/file to update my startup-script
    – howie
    Commented Mar 8, 2019 at 7:03

1 Answer 1

4

The startup script is taken from the metadata server.

If you restart your instance, after it boots up it will connect to the metadata server and take the script from there and then execute it.

Therefore, you need to change the instance metadata in order to change your startup sript (uses the compute.instances.setMetadata permission).

You can do that straight from the UI, API or CLI tool. More info on all of the above here - Compute Engine Docs - Running Startup Scripts

After you change the startup script for an instance it will execute on the next (re)boot. The article above also provides a command you can use if you wanted to force its execution straight away:

$ sudo google_metadata_script_runner --script-type startup --debug
1
  • 1
    On a CentOS Stream 8 VM, the only version of this command that works now is sudo google_metadata_script_runner startup. Even the --debug flag doesn't work.
    – KJH
    Commented May 20, 2022 at 19:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.