Vultr Startup Scripts Quickstart Guide
You can add startup scripts to your Vultr cloud server instances in the Customer Portal or through the Vultr API. This guide explains the different types of scripts available at Vultr and how to use them.
Script Types
Vultr supports several types of startup scripts:
- Linux systems use cloud-init user-data. See Deploy a Vultr Server with Cloud-Init User-Data for full details.
- Fedora CoreOS uses Ignition. See our Ignition user guide and the Fedora CoreOS documentation.
- Windows and *BSD systems use boot scripts.
- iPXE scripts automatically install operating systems.
How to use Boot Scripts
Boot scripts are standard shell scripts executed by your server instance. The server's operating system determines where the script is stored, what script interpreter is used, and where the log output is saved.
Boot Scripts on *BSD
- The script is saved to
/tmp/firstboot.exec
. - It is executed with
/bin/sh
as the root user. - The output is saved to
/tmp/firstboot.log
.
Boot Scripts on Windows
- The script is saved to
C:\image\firstboot.cmd
. - It is executed with
cmd.exe
as the Administrator. - The output is saved to
C:\image\firstboot.log
Boot scripts use a two-step process. First, you add a script to your account, then assign that script to an instance.
Add a Script
You can add a script to your account through the customer portal:
- Navigate to the Add Startup Script page.
- Choose a name for your script.
- Select Boot for the type.
- Replace the example with your script.
- Click Add Script.
You can also add a script to your account through the Vultr API with the create-startup-script
endpoint.
Assign the Script
After adding the script, you can assign it when you deploy a new instance through the customer portal. Choose your script from the list, or if you need to add a new script, use the Manage link or the Add New button.
You can also assign a script to a new instance with the Vultr API by passing the script_id
to the create-instance
endpoint.
BSD Boot Script Example: Query Instance Metadata
Boot scripts may query the Vultr Metadata API to discover information about the instance. This example script logs the server's metadata to /tmp/metadata.json
during the first boot.
#/bin/sh
curl -o /tmp/metadata.json http://169.254.169.254/v1.json
This could be useful if you parse the JSON metadata with tools such as jq, Python, sed, awk, or grep. For example, you could use the metadata to discover your IP address and generate configuration files automatically on the first boot.
BSD Boot Script Example: Pre-Load SSH Public Key
This example installs a public key for SSH authentication. Replace "ssh-rsa AA... youremail@example.com" with your SSH public key.
#!/bin/sh
mkdir -p /root/.ssh
chmod 700 /root/.ssh
echo ssh-rsa AA... youremail@example.com > /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
Other common uses for boot scripts are installing software, running updates, and adding users. It's possible to fully configure a system with boot scripts with a little creativity.
How to use iPXE Scripts
An iPXE script automates the installation of a custom operating system. An iPXE script is executed by iPXE each time the server starts if no operating system is installed on the server's disk. After an operating system is installed, iPXE scripts do not run.
Requirements
- Must be a valid iPXE script.
- You can select an iPXE script when deploying an instance under the Upload ISO option on the deploy page.
See the article iPXE Boot Feature for more information.
iPXE Script Example: Boot CoreOS
This is an example that boots CoreOS. You need to add your SSH key before this will work.
#!ipxe
set base-url http://stable.release.core-os.net/amd64-usr/current
kernel ${base-url}/coreos_production_pxe.vmlinuz sshkey="ssh-rsa AAAA..." cloud-config-url=http://169.254.169.254/2014-09-12/coreos-init
initrd ${base-url}/coreos_production_pxe_image.cpio.gz
boot