Installing Oracle® Solaris 11.2 Systems

Exit Print View

Updated: July 2014
 
 

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 client system at first boot. The solaris-large-server package is installed by default. If you installed that group package, you have Python, bash, ksh, and other tools available to you at first boot. For a complete list of packages that are included in the solaris-large-server group package, use the pkg contents command as described in Listing All Installable Packages in a Group Package in Adding and Updating Software in Oracle Solaris 11.2 . 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 Adding and Updating Software in Oracle Solaris 11.2 .


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.

Example 13-1  Template First-Boot Script

    This example shows operations that should be done in any first-boot script.

  • A first-boot script must load /lib/svc/share/smf_include.sh in order to use definitions such as SMF method exit codes.

  • The script should test whether it already ran in a prior boot. If the completed property is already set to true, then exit the start method and temporarily disable the service.

    The following line in the script gets the value of the completed property in the config property group in the site/first-boot-script-svc:default service instance and assigns that value to the local completed variable.

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

    The following line in the script sends the SMF_EXIT_TEMP_DISABLE exit code to the service start method, with method_completed as the short reason for the exit and "Configuration completed" as the longer description of the reason for the exit.

    smf_method_exit $SMF_EXIT_TEMP_DISABLE script_completed "Configuration completed"
  • A first-boot script should save a copy of the boot environment (BE) that was just created by the AI installation. Saving a copy of the BE before the first-boot script modifies it enables you to easily recover from any problems introduced by the script by booting into the saved BE.

  • When the script has finished its work, the script must set the value of the completed property to true, refresh the service with the new property value, and exit the start method and temporarily disable the service. Use the svccfg command to set the completed property to true, and use the svcadm command to refresh the service.

Remember that 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"

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

Example 13-2  First-Boot Script that Configures Multiple IP Interfaces

This example shows a first-boot script named first-boot-script.sh that configures addresses on two IP interfaces and adds a default route.

#!/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"

# 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 10.153.125.222/24 net0
/usr/sbin/ipadm create-addr -a 169.254.182.77/24 net1

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

# 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"

Another good use of a first-boot script is to use the useradd command to configure multiple initial users on the system.