1. Home
  2. Cloud Servers
  3. Using the firstboot script

Using the firstboot script

If you want to set up a lot of cloud servers in the same way, Bytemark Cloud’s firstboot facility is a simple way to achieve that.

A firstboot script is a normal shell script that you supply when you create the server. Bytemark’s servers run it as part of the imaging process.

You can use it to install system packages or make other configuration changes, and your servers should come up in the same way.

How to set up a first boot script

The easiest way to supply a firstboot script is to Add A Cloud Server in the control panel. You’ll see the option to turn on firstboot which looks like this:

Once this box is visible, you paste the shell script you’d like to use, and it will be run the first time your server is booted, after you confirm adding the server.

firstboot from the command line

If you install the command line client you can put your script into a file called firstboot.sh and then run e.g.

bytemark add server myserver1 --firstboot-script-file=firstboot.sh

Watch out for…

When using firstboot you should watch out for the following:

  1. The only way to check on progress of your firstboot script is to log into the server and look at the contents of the /var/log/firstboot.log file. If it fails, you’ll see the error here.
  2. Your script runs during the setup process, not right at the end. So you might find that running apt or dpkg might fail temporarily (see below for a way to work around this).
  3. Your script is copied into /firstboot and then removed once it has finished, whether it has failed or not. If you need to test whether the firstboot script is still running, you can check to see if this file still exists.

Example: Installing Docker

Here is a firstboot script that you can use to reliably install Docker Community Edition onto a standard Debian server:

#!/bin/sh
#
# This sets up a Debian host
export DEBIAN_FRONTEND=noninteractive

# wait for dpkg to come available
while ! apt-get -qq check 2>/dev/null ; do sleep 1; done; echo hi

apt-get install -yq \
apt-transport-https \
ca-certificates \
curl \
software-properties-common \


curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | \
apt-key add -

add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
$(lsb_release -cs) \
stable"

apt-get update

apt-get install -yq docker-ce

# Not sure why this is necessary for Docker
sleep 5
apt-get -f install
apt-get -f install

# install only depenencies for docker-compose...
apt-get install -yq $(apt-cache depends docker-compose | grep Depends | sed "s/.*ends:\ //" | tr '\n' ' ' | sed -e "s/.*ends:\ //" -e 's/<[^>]*>//g')

# ...then install latest from github
curl -L https://github.com/docker/compose/releases/download/1.19.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
Updated on July 25, 2018

Was this article helpful?

Related Articles

Have you tried Kubernetes?
Kubernetes (K8s) is helping enterprises to ship faster & scale their business. Sounds good? Let us build a K8s solution for your needs.
Register your interest