Article

Table of Contents
Theme:
Was this article helpful?
Try Vultr Today with

$50 Free on Us!

Want to contribute?

You could earn up to $300 by adding new articles!

Vultr Startup Scripts Quickstart Guide

Last Updated: Tue, Oct 6, 2020
Quickstart Guides System Admin

Script Types

Vultr allows you to assign two types of scripts to a server. Boot scripts configure new deployments, and PXE scripts automatically install operating systems. Assign startup scripts to your servers on your Startup Scripts page.

Boot Scripts

A boot script is executed on your server the very first time it starts. It will not run on subsequent reboots.

On Linux

  • The startup script is saved to /tmp/firstboot.exec.
  • It is executed with /bin/bash as root.
  • The output is saved to /tmp/firstboot.log.

On BSD

  • The startup script is saved to /tmp/firstboot.exec.
  • It is executed with /bin/sh as root.
  • The output is saved to /tmp/firstboot.log.

On Windows

  • The startup script is saved to C:\image\firstboot.cmd.
  • It is executed with cmd.exe as Administrator.
  • The output is saved to C:\image\firstboot.log

PXE Scripts

A PXE script automates installation of custom operating systems. A PXE script will be executed by iPXE every time your server starts, but only if there is no operating system installed to the server's disk.

Requirements

  • Must be a valid iPXE script.
  • PXE scripts are listed under the 'Upload ISO' option on the deploy page.
  • Not supported on Bare Metal.

Boot Script Example: Query Instance Metadata

Startup scripts may query the Vultr Metadata API to discover information about the instance. This script logs the metadata for the deployed instance to /tmp/metadata.json.

#/bin/sh

curl -o /tmp/metadata.json http://169.254.169.254/v1.json

Your script can manipulate 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 first boot.

Boot Script Example: Pre-Load SSH Public Key

This example installs a public key for SSH authorization. Replace "ssh-rsa AA... youremail@example.com" with your SSH public key info.

#!/bin/sh

mkdir -p /root/.ssh
chmod 600 /root/.ssh
echo ssh-rsa AA... youremail@example.com > /root/.ssh/authorized_keys
chmod 700 /root/.ssh/authorized_keys

PXE 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

Manage Startup Scripts via API

The Vultr API offers several endpoints to manage startup scripts.

  • Create a new startup script.
  • Get information for a startup script.
  • List all startup scripts.
  • Update a startup script.
  • Delete a startup script.

Want to contribute?

You could earn up to $300 by adding new articles