Skip to main content

Running Custom Scripts

In this tutorial, we will build on the Hello World tutorial and learn how to add custom scripts, so that we can execute custom logic during the installation.

Introduction

Trident has several script hooks to allow users to customize the install and update process. Here, we will create a postConfigure script that will run from within the chroot of the target OS after the system has been installed and configured.

Prerequisites

The prerequisites are the same as for the Hello World tutorial.

Instructions

Step 1: Follow Step 1 of the Hello World Tutorial

Follow Step 1 of the Hello World Tutorial which will create several files, including the Host Configuration file: $HOME/staging/host-config.yaml

Step 2: Update the Host Configuration to Use the Script

Edit the Host Configuration file ($HOME/staging/host-config.yaml) by appending the following to the end of the file:

scripts:
postConfigure:
- content: |
echo "Hello from the post-configure script!" > /root/post-configure.log

We define the post-configure script contents inline using the content field for simplicity, but you could also use the path field to reference a script file from the servicing OS filesystem.

Step 3: Follow Steps 2-6 of the Hello World Tutorial

Follow Steps 2-6 of the Hello World Tutorial to create the Servicing ISO, boot the target system from the ISO, and install Azure Linux.

Step 4: Verify the Script Ran

# From your host machine:
ssh tutorial-user@<system-ip-address> sudo cat /root/post-configure.log

You should see the expected message: Hello from the post-configure script!