Go to main content

Customizing Automated Installations With Manifests and Profiles

Exit Print View

Updated: November 2020
 
 

Manually Creating a Script to Run at First Boot

To know what source you can use for your script, you need to know what tools are installed on the AI client at first boot. The solaris-large-server group package is installed by default which includes tools that become available at first boot, such as Python, bash, and ksh. For a complete list of packages that are included in the group package, use the pkg contents command as described in Listing All Installable Packages in a Group Package in Updating Systems and Adding Software in Oracle Solaris 11.4. If you want to use a source for your script that is not available in the solaris-large-server package, identify the package you need and specify it in the AI manifest. For information about how to find the names of other packages that you might want to install, see Updating Systems and Adding Software in Oracle Solaris 11.4.


Tip  - 
  • Use only one first-boot script to avoid having different commands in different scripts that collide with one another.
  • Do not reboot in the first-boot script.

    Any first-boot script must perform the following foundational actions:

  • Load /lib/svc/share/smf_include.sh in order to use definitions such as SMF method exit codes.

  • Test whether the script already ran in a prior boot and if true, exit the process.

    The test is performed by the following line in the script:

    completed=`svcprop -p config/completed site/first-boot-script-svc:default`

    The test consists of two steps:

    • Obtain the current value of the config/completed property of the site/first-boot-script-svc service.

    • Assign that value to the local completed variable in the script.

    If the property's value is true, then an exit code is sent to end the script's process and disable the script. The exit signal is performed by the following line:

    smf_method_exit $SMF_EXIT_TEMP_DISABLE script_completed "Configuration completed"
  • Save a copy of the boot environment (BE) that was just created by the AI installation.

    The copy serves in recovery. If the first-boot script introduces problems to the system, simply reboot the system to the saved BE. Add the following line to the first-boot script.

    bename=`beadm list -Hd|nawk -F ';' '$3 ~ /R/ {print $1}'`
    beadm create ${bename}.orig
    echo "Original boot environment saved as ${bename}.orig"
  • After the script completes, set the value of the completed property to true, refresh the service with the new property value, exit the start method, and temporarily disable the service.

    Copy the previous test and exit lines and add these to the end of the script.

Example 7  Template First-Boot Script

By default, sh is ksh93.

#!/bin/sh

# Load SMF shell support definitions
. /lib/svc/share/smf_include.sh

# If nothing to do, exit with temporary disable
completed=`(svcprop -p config/completed site/first-boot-script-svc:default`
[ "${completed}" = "true" ] && \
    smf_method_exit $SMF_EXIT_TEMP_DISABLE completed "Configuration completed"

# Obtain the active BE name from beadm: The active BE on reboot has an R in
# the third column of 'beadm list' output. Its name is in column one.
bename=`beadm list -Hd|nawk -F ';' '$3 ~ /R/ {print $1}'`
beadm create ${bename}.orig
echo "Original boot environment saved as ${bename}.orig"

# Place your one-time configuration tasks here

# Record that this script's work is done
svccfg -s site/first-boot-script-svc:default setprop config/completed = true
svcadm refresh site/first-boot-script-svc:default

smf_method_exit $SMF_EXIT_TEMP_DISABLE method_completed "Configuration completed"

In the middle of the template, marked by the heading Place your one time configuration tasks here, you can add additional shell commands to perform other tasks. For example, to configure multiple IP interfaces, add the following lines:

# Create and configure addresses on two IP interfaces
/usr/sbin/ipadm create-ip net0
/usr/sbin/ipadm create-ip net1
/usr/sbin/ipadm create-addr -a 203.0.113.5/27 net0
/usr/sbin/ipadm create-addr -a 203.0.113.35/27 net1

# Add a default route with net0 as the gateway
/usr/sbin/route add default 203.0.113.1 -ifp net0

You can also add useradd commands to create multiple users on the system.


Tip  - Use the –n option to check for syntax errors in your script:
$ ksh -n first-boot-script.sh