Startup scripts allow you to configure and setup your instance, meaning automatically running scripts or installing software as soon as the instance has booted for the first time. 


We offer both, predefined installer scripts like the NVIDIA® GPU driver in the dashboard or the possibility to run any custom user-defined startup script via the API.


Let's first take one step back. When you create a new instance it contains all the software that comes with the image that you selected. For example, in the case of Ubuntu 24.04 all the software that comes with a vanilla Ubuntu 24.04 installation.


For a lot of applications, especially GPU applications you will need additional software to be installed in order to successfully run those applications. 


For example, to install and run TensorFlow on a NVIDIA® GPU, you will also need a NVIDIA® GPU driver, NVIDIA® CUDA and of course installing TensorFlow itself. In order to set up the most common types of software like the GPU driver, we will provide predefined startup scripts to make it easier to be up and running.


With startup scripts, you can inject a script that is automatically executed after the instance becomes active. Under the hood, it uses a mechanism called cloud-init that is also used to deploy your public SSH key on the instance. 


Note: The startup script is executed after the instance is booted and active, meaning if you log in to your instance the execution might still happen in the background.


Please don't snapshot, shutdown or restart your instance while a startup script is running.


You can check the logs of your startup scripts via

tail -f /var/log/cloud-init-output.log


Also, you can check the status of your startup script with

cloud-init status

Installing a NVIDIA® GPU Driver


Note: Installing the driver will take about 6-7 minutes after the instance is active. This means in the first 6-7 minutes you will not be able to use the GPU. Please also don't snapshot or restart the instance during this time. This will fail the driver installation.


First you should wait until the installation is done:

cloud-init status --wait


You can verify the NVIDIA driver installation using the NVIDIA System Management Interface utility by running:

nvidia-smi


Once the installation is done you should see a nvidia-smi response like this one.

Account Creation and Login

Nvidia-smi response 


Via the Compute Dashboard


Currently, we support many versions of NVIDIA® Data Center GPU Driver. You can install any version of your choice on the instance, just select the version you would like to install, on the Instance creation flow.


Under the Drivers section, you can select to install the desired Nvidia GPU driver

Under the Drivers section, you can select to install the desired NVIDIA® Data Center GPU Driver


Via the public Compute API


To install the NVIDIA® GPU driver version 535 on your instance via the public Compute API you can pass the following shell script as startup_script in your create instance request metadata parameter. To install the driver version 535, we use the following script, which we then convert to a JSON string with

cat your-startup-script.sh | jq -Rs

and then pass the JSON string to the metadata.startup_script parameter. 


If you use httpie or a similar program that supports httpie nested JSON syntax you can simplify this even further:

metadata[startup_script]="$(cat your-startup-script.sh)"

Startup script in clean bash

#!/bin/bash

set -eo pipefail


NVIDIA_MAJOR_VERSION=535

export DEBIAN_FRONTEND=noninteractive


# remove nouveau module if present

if lsmod | grep -q nouveau; then

    rmmod -v nouveau

fi


apt-get update

apt-get install --no-install-recommends -y nvidia-driver-$NVIDIA_MAJOR_VERSION-server


nvidia-smi # loads the driver modules


sed -i 's/--no-persistence-mode/--persistence-mode/g' /lib/systemd/system/nvidia-persistenced.service

systemctl daemon-reload


systemctl restart nvidia-persistenced.service


Startup script as JSON string passed to the public API as metadata parameter

"metadata": {"startup_script": "#!/bin/bash\nset -eo pipefail\n\nNVIDIA_MAJOR_VERSION=535\nexport DEBIAN_FRONTEND=noninteractive\n\n# remove nouveau module if present\nif lsmod | grep -q nouveau; then\n    rmmod -v nouveau\nfi\n\napt-get update\napt-get install --no-install-recommends -y nvidia-driver-$NVIDIA_MAJOR_VERSION-server\n\nnvidia-smi # loads the driver modules\n\nsed -i 's/--no-persistence-mode/--persistence-mode/g' /lib/systemd/system/nvidia-persistenced.service\nsystemctl daemon-reload\n\nsystemctl restart nvidia-persistenced.service\n"}


In order to install different 'NVIDIA® Data Center GPU Driver' version, you just need to replace the value of NVIDIA_MAJOR_VERSION in the script.