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 20.04 all the software that comes with a vanilla Ubuntu 20.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. 


Please 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


Please Note: Installing the driver will take about 4-5 minutes after the instance is active. This means in the first 4-5 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.


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.


+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.129.06   Driver Version: 470.129.06   CUDA Version: 11.4     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  Off  | 00000000:00:05.0 Off |                  N/A |
|  0%   30C    P0     1W / 350W |      0MiB / 24268MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+



Via the Compute Dashboard


To install the NVIDIA® GPU driver version 470 on your instance just toggle the installation slider on the Instance Configuration section of the Instance creation flow.




Via the public Compute API


To install the NVIDIA® GPU driver version 470 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 470, we use the following script, which we then convert to a JSON string with


jq -Rs . < your-startup-script.sh >

and then pass the JSON string to the metadata.startup_script parameter. The 470 version works for RTX GPUs only.


Startup script in clean bash

#!/bin/bash

set -eux

__is_driver_installed=false
__is_module_loaded=false
NVIDIA_MAJOR_VERSION=470

apt_fetch_install() {
    echo "APT installation of Nvidia Driver ${NVIDIA_MAJOR_VERSION}"
    echo "Preparing install ..."
    apt-get update
    apt-get install -y --no-install-recommends "linux-headers-$(uname -r)" 

    echo "Start installing the NVIDIA driver..."
    apt-get install -y --no-install-recommends nvidia-dkms-${NVIDIA_MAJOR_VERSION} nvidia-utils-${NVIDIA_MAJOR_VERSION} 

    __is_driver_installed=true
}

remove_nouveau_module() {
    if lsmod | grep nouveau; then
        rmmod -v nouveau
    fi
    echo "blacklist nouveau" >/etc/modprobe.d/nouveau.conf
}
 
load_nvidia_module() {
    # log insertion of the nvidia module
    # this should always succeed on customer instances
    if modprobe -vi nvidia; then
        nvidia-smi
        modinfo nvidia
        __is_module_loaded=true
    else
        __is_module_loaded=false
    fi
}

main() {
    # Fetch deb packages
    apt_fetch_install

    # Check if driver was installed successfully
    if [ "${__is_driver_installed}" != true ]; then
        echo "NVIDIA driver has NOT been installed."
        return 1
    fi
    echo "NVIDIA driver has been successfully installed."

    # remove the module if it is inserted and blacklist it
    remove_nouveau_module
 
    # Try to load Nvidia module
    load_nvidia_module
    if [ "${__is_module_loaded}" != true ]; then
        echo "WARNING: NVIDIA module failed loading"
        return 1
    fi
    echo "NVIDIA module is found and ready"
}

main

 

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

"metadata": {
        "startup_script": "#!/bin/bash\nset -eux\n\n__is_driver_installed=false\n__is_module_loaded=false\nNVIDIA_MAJOR_VERSION=470\n\napt_fetch_install() {\n    echo \"APT installation of Nvidia Driver ${NVIDIA_MAJOR_VERSION}\"\n\n    echo \"Preparing install ...\"\n    apt-get update\n    apt-get install -y --no-install-recommends \"linux-headers-$(uname -r)\"\n\n    echo \"Start installing the NVIDIA driver...\"\n    apt-get install -y --no-install-recommends nvidia-dkms-${NVIDIA_MAJOR_VERSION} nvidia-utils-${NVIDIA_MAJOR_VERSION}\n\n    __is_driver_installed=true\n}\n\nremove_nouveau_module() {\n    if lsmod | grep nouveau; then\n        rmmod -v nouveau\n    fi\n    echo \"blacklist nouveau\" >/etc/modprobe.d/nouveau.conf\n}\n\nload_nvidia_module() {\n    # log insertion of the nvidia module\n    # this should always succeed on customer instances\n    if modprobe -vi nvidia; then\n        nvidia-smi\n        modinfo nvidia\n        __is_module_loaded=true\n    else\n        __is_module_loaded=false\n    fi\n}\n\nmain() {\n    # Fetch deb packages\n    apt_fetch_install\n\n    # Check if driver was installed successfully\n    if [ \"${__is_driver_installed}\" != true ]; then\n        echo \"NVIDIA driver has NOT been installed.\"\n        return 1\n    fi\n    echo \"NVIDIA driver has been successfully installed.\"\n\n    # remove the module if it is inserted and blacklist it\n    remove_nouveau_module\n\n    # Try to load Nvidia module\n    load_nvidia_module\n    if [ \"${__is_module_loaded}\" != true ]; then\n        echo \"WARNING: NVIDIA module failed loading\"\n        return 1\n    fi\n    echo \"NVIDIA module is found and ready\"\n}\n\nmain\n"
}


Feature Requests

If you need a feature, which is not provided by us yet, please request it here.