Solaris 10 JumpStart Begin and Finish Scripts: Derived Profiles, pkgadd -R /a and First-Boot Tasks

Solaris Admin Series, part 20. Previous: part 19, Solaris 10 JumpStart Profiles. Related: part 18, Solaris 10 JumpStart Server Setup (the rules file and the check script) and part 17, Solaris 10 sysidcfg. Next up: JumpStart with DHCP, x86 PXE and WAN boot (part 21).

A JumpStart rule has five fields, and so far this series has only used three of them. The two we skipped are the hooks that turn an unattended install into a finished server: the begin script, which runs before anything is written to disk, and the finish script, which runs after the Solaris packages are installed but before the first reboot. This post covers what each one can do, the environment they run in, the SI_ variables JumpStart gives them, derived profiles, and a set of finish-script recipes for the jobs people actually automate: extra packages, patches, a root password, configuration files and first-boot work.

Applies to: Solaris 10 only (SPARC and x86, up to Solaris 10 1/13). JumpStart does not exist in Solaris 11.4; the section near the end shows the Solaris 11.4 equivalents in the Automated Installer. The syntax and variables come from the Oracle Solaris 10 1/13 Installation Guide: JumpStart Installations (chapter 4, “Creating Custom JumpStart Optional Features”, and the custom JumpStart environment variables reference). The scripts below are written from that guide and were not run on SPARC or x86 hardware for this post, so dry-run them on a test client first.

Prerequisites

  • A working JumpStart server and directory as in part 18: /export/jumpstart on js01 (192.168.10.5), shared read-only over NFS, with the check script copied from Solaris_10/Misc/jumpstart_sample.
  • At least one tested profile from part 19 and a client that already installs hands-off with a sysidcfg file.
  • Root on the JumpStart server, and a console on the test client (ILOM, serial or a VM console) so you can watch the install.
  • Somewhere to keep extra software: in the examples a pkgs, patches and files directory under /export/jumpstart.

Where the scripts fit in a rule

Each line of the rules file is rule_keyword rule_value begin profile finish. A hyphen in the begin or finish field means “no script”, and = in the profile field means the begin script will create the profile (a derived profile, below). The script names are paths relative to the JumpStart directory:

# /export/jumpstart/rules
# keyword  value       begin        profile        finish
hostname   web01       -            web_prof       finish_web.sh
karch      sun4v       begin_t.sh   =              finish_common.sh
network    192.168.10.0 -           net_prof       finish_common.sh
any        -           -            default_prof   -

The installer reads the rules from top to bottom and uses the first one that matches. For that rule it runs the begin script, then reads the profile and installs, then runs the finish script, then reboots. After any change to rules, or to a begin or finish script name in it, run check again so rules.ok is regenerated, because the client only reads rules.ok:

js01# cd /export/jumpstart
js01# ./check
Validating rules...
Validating profile web_prof...
Validating profile net_prof...
Validating profile default_prof...
The custom JumpStart configuration is ok.

check validates syntax and that the profile files exist. It does not run or lint your begin and finish scripts, so a typo in a script only shows up during the install.

The environment the scripts run in

  • Both scripts are run by the Bourne shell (/sbin/sh) from the miniroot, not from the installed system. Write plain sh: no bash-only syntax, no [[ ]], no $(...) if you want to be safe with the old shell; backticks work everywhere.
  • The JumpStart directory is NFS-mounted on the client, and SI_CONFIG_DIR holds its path (the guide uses /tmp/install_config). Refer to your own files through ${SI_CONFIG_DIR}, never through the server path.
  • During the finish script, the newly installed system is mounted at /a. Anything you want on the final system has to be written under /a, or done with a tool that takes an alternate root such as pkgadd -R /a or patchadd -R /a.
  • The guide asks for the scripts to be owned by root with mode 644; they are read by sh, so the execute bit is not needed.
  • Output and errors go to /tmp/begin.log and /tmp/finish.log while the install runs, and are copied to /var/sadm/system/logs/begin.log and /var/sadm/system/logs/finish.log on the installed system.
  • Nothing is interactive. A command that waits for input (a pkgadd without an admin file, a passwd) hangs the install.
js01# cd /export/jumpstart
js01# chown root finish_common.sh begin_t.sh
js01# chmod 644 finish_common.sh begin_t.sh
js01# mkdir -p pkgs patches files

SI_ variables you will use most

VariableWhat it holds
SI_CONFIG_DIRPath to the mounted JumpStart directory
SI_PROFILEPath of the profile; a begin script writes a derived profile here
SI_HOSTNAMEHost name of the client
SI_ARCH / SI_KARCHInstruction set (sparc, i386) and kernel architecture (sun4u, sun4v, i86pc)
SI_MODELPlatform name, as matched by the model rule keyword
SI_MEMSIZEPhysical memory in MB
SI_DISKLIST / SI_NUMDISKS / SI_TOTALDISKDisk names found, how many, and total size in MB

The full list is in the “Custom JumpStart Environment Variables” reference of the installation guide; the probe keywords that set them are the same ones the rule keywords use.

Begin scripts and derived profiles

A begin script runs before the profile is read. Two jobs fit it well: saving something from the old disk before it is overwritten (for example a copy of /etc/hosts or the old host keys to the JumpStart server, if your policy allows it), and building a derived profile on the fly. Put = in the rule’s profile field, and the begin script must write a profile to the file named by SI_PROFILE:

#!/sbin/sh
# /export/jumpstart/begin_t.sh - derived profile for sun4v machines
# Picks the swap size from memory and mirrors the root pool when
# a second disk is present.
set -x
MEM=${SI_MEMSIZE}
if [ "$MEM" -ge 32768 ]; then SWAP=16g; else SWAP=8g; fi

set -- ${SI_DISKLIST}
D1=$1; D2=$2

echo "install_type initial_install"            >  ${SI_PROFILE}
echo "cluster SUNWCreq"                         >> ${SI_PROFILE}
if [ -n "$D2" ]; then
  echo "pool rpool auto ${SWAP} auto mirror ${D1}s0 ${D2}s0" >> ${SI_PROFILE}
else
  echo "pool rpool auto ${SWAP} auto ${D1}s0"   >> ${SI_PROFILE}
fi
echo "bootenv installbe bename s10be"           >> ${SI_PROFILE}
echo "---- derived profile ----"; cat ${SI_PROFILE}

The keywords are the same as in part 19: pool with size, swap, dump and vdevs, then bootenv installbe. Because the profile does not exist until install time, check cannot validate it and pfinstall cannot dry-run it. Generate one by hand first (export the SI_ variables in a shell on the server and run the script with SI_PROFILE=/tmp/test_prof), then dry-run that file with pfinstall -D as in part 19.

The rule that uses it:

karch sun4v begin_t.sh = finish_common.sh

Finish scripts: recipes

A finish script is where you add everything the software group does not: site packages, patches, configuration, and anything that has to happen once on first boot. Keep one common finish script and call small per-role pieces from it, so every host gets the baseline.

1. Add packages non-interactively with an admin file

pkgadd asks questions unless an admin file answers them. Keep one in the JumpStart directory:

# /export/jumpstart/files/admin.noask
mail=
instance=overwrite
partial=nocheck
runlevel=nocheck
idepend=nocheck
rdepend=nocheck
space=nocheck
setuid=nocheck
conflict=nocheck
action=nocheck
basedir=default
# in finish_common.sh
ADMIN=${SI_CONFIG_DIR}/files/admin.noask
PKGDIR=${SI_CONFIG_DIR}/pkgs
for p in SITEbase SITEmon; do
  echo "adding $p"
  pkgadd -n -a ${ADMIN} -R /a -d ${PKGDIR} $p
done

-R /a installs into the new root instead of the miniroot, and -n makes pkgadd non-interactive. A datastream package (a single .pkg file) is added the same way with -d ${PKGDIR}/SITEbase.pkg.

2. Apply patches

# patches listed in order in files/patch_order
PATCHDIR=${SI_CONFIG_DIR}/patches
for id in `cat ${SI_CONFIG_DIR}/files/patch_order`; do
  echo "patchadd $id"
  patchadd -R /a ${PATCHDIR}/$id
done

Patches need a valid support contract to download, and a full recommended patch cluster is better installed after first boot with its own installer, where it can be logged and retried. Use the finish script for a short, known list.

3. Copy configuration files

cp ${SI_CONFIG_DIR}/files/resolv.conf   /a/etc/resolv.conf
cp ${SI_CONFIG_DIR}/files/nsswitch.dns  /a/etc/nsswitch.conf
cp ${SI_CONFIG_DIR}/files/ntp.conf      /a/etc/inet/ntp.conf
chmod 644 /a/etc/resolv.conf /a/etc/nsswitch.conf /a/etc/inet/ntp.conf
# keep a record of what JumpStart did
echo "jumpstart `date` rule finish_common.sh" >> /a/etc/motd

Check the ownership and mode of anything you copy: cp in the miniroot runs as root, and the files keep whatever mode the server copy had.

4. Set the root password

The installation guide’s own sample (set_root_pw) edits /a/etc/shadow and puts an already-encrypted password in the root entry. The pattern is:

# files/root.hash holds ONE line: an encrypted root password string
# copied from a reference system's /etc/shadow (never plain text)
PASSWD=`cat ${SI_CONFIG_DIR}/files/root.hash`
mv /a/etc/shadow /a/etc/shadow.orig
nawk -F: -v p="$PASSWD" 'BEGIN {OFS=":"}
  $1 == "root" { $2 = p }
  { print }' /a/etc/shadow.orig > /a/etc/shadow
chmod 400 /a/etc/shadow
chown root:sys /a/etc/shadow
rm /a/etc/shadow.orig

The JumpStart directory is exported read-only to the install network, so anyone who can mount it can read root.hash. Restrict the share to the install subnet, or set root_password in sysidcfg instead (also an encrypted string) and leave the finish script out of it.

5. Work that must run on first boot

Some things cannot run in the miniroot because the services are not running yet: enabling and configuring SMF services with svccfg, registering with a monitoring server, joining a directory. Drop a one-shot legacy run-control script into the new system and have it remove itself. Run level 3 is the normal multi-user state (see part 10):

cat > /a/etc/rc3.d/S99firstboot <<'EOF'
#!/sbin/sh
# runs once on the first boot after JumpStart
LOG=/var/sadm/system/logs/firstboot.log
{
  /usr/sbin/svcadm disable svc:/network/telnet:default
  /usr/sbin/svcadm enable  svc:/network/ntp:default
  /usr/sbin/svcs -xv
} >> $LOG 2>&1
rm -f /etc/rc3.d/S99firstboot
EOF
chmod 744 /a/etc/rc3.d/S99firstboot
chown root:sys /a/etc/rc3.d/S99firstboot

On Solaris 10, legacy /etc/rc3.d scripts are still run by SMF (through svc:/milestone/multi-user-server), and svcs lists them as lrc: entries.

Putting it together

#!/sbin/sh
# /export/jumpstart/finish_common.sh
echo "finish_common.sh starting for ${SI_HOSTNAME} (${SI_KARCH})"
F=${SI_CONFIG_DIR}/files

# 1 site packages
for p in SITEbase SITEmon; do
  pkgadd -n -a $F/admin.noask -R /a -d ${SI_CONFIG_DIR}/pkgs $p || echo "pkgadd $p FAILED"
done

# 2 configuration
cp $F/resolv.conf /a/etc/resolv.conf
cp $F/nsswitch.dns /a/etc/nsswitch.conf

# 3 role-specific piece, if one exists for this host
if [ -f ${SI_CONFIG_DIR}/finish.d/${SI_HOSTNAME}.sh ]; then
  . ${SI_CONFIG_DIR}/finish.d/${SI_HOSTNAME}.sh
fi

echo "finish_common.sh done"

Sourcing the per-host piece with . keeps the SI_ variables and F available to it. Failures are echoed but do not stop the script, so one bad package does not leave a host that never reboots; read the log afterwards.

Verification

  1. Run ./check after every change to rules. It must end with “The custom JumpStart configuration is ok.”
  2. Boot the test client (ok boot net - install on SPARC, PXE on x86 as in part 21) and watch the console. The finish script runs after the “Installation complete” package summary and before the reboot.
  3. After the reboot, read the logs on the installed system:
web01# ls -l /var/sadm/system/logs/
-rw-r--r--   1 root     root        1204 ... begin.log
-rw-r--r--   1 root     root        3570 ... finish.log
-rw-r--r--   1 root     root      812345 ... install_log
web01# grep -i fail /var/sadm/system/logs/finish.log
web01# pkginfo SITEbase SITEmon
application SITEbase   Site baseline
application SITEmon    Site monitoring agent
  1. Check the first-boot script removed itself (ls /etc/rc3.d/S99firstboot should fail) and read /var/sadm/system/logs/firstboot.log.
  2. For derived profiles, the begin log should contain the profile the script generated (the example prints it).

Solaris 10 versus Solaris 11.4

JobSolaris 10 JumpStartSolaris 11.4 Automated Installer
Choose settings at install timeBegin script writing a derived profile (= in rules)Derived manifest: a script run on the client that builds the AI manifest with aimanifest, added with installadm create-manifest
Add softwarepkgadd -R /a in the finish scriptList IPS packages in the manifest; site software goes into an IPS repository
Post-install configurationFinish script writing under /aSystem configuration profiles (SMF properties) plus a first-boot SMF service delivered in an IPS package
Run-once work/etc/rc3.d script that deletes itselfFirst-boot SMF service that disables itself when done

js2ai converts JumpStart rules and profiles (and sysidcfg) into AI criteria, manifests and configuration profiles, but it does not convert begin or finish scripts. Plan to rewrite what they do as packages, manifests and a first-boot service. The Solaris 11.4 AI posts later in this series cover that path.

Troubleshooting

SymptomLikely cause and fix
Install stops and waits after the package phaseA command in the finish script is prompting. Add -n -a admin to pkgadd, never call passwd, redirect stdin from /dev/null for anything else.
Script changes are ignoredThe client reads rules.ok. Run ./check again; confirm you edited the file under the JumpStart directory the client mounts.
Files land in the miniroot, not on the diskMissing /a prefix or missing -R /a. After reboot the file is not there.
“not found” for a file under the JumpStart directoryUsed the server path (/export/jumpstart/...) instead of ${SI_CONFIG_DIR}.
Derived profile install fails at profile parseThe begin script wrote an invalid line. Read /tmp/begin.log on the client console (or the copy in /var/sadm/system/logs on a retry) and dry-run the generated file with pfinstall -D.
Syntax error in the scriptbash syntax in a /sbin/sh script. Test with /sbin/sh -n script on a Solaris 10 box.

What was tested

This is a reference post. The rules syntax, variable names, log locations and the root-password pattern are from the Oracle Solaris 10 1/13 JumpStart guide; the shell was checked for Bourne-shell syntax, but the scripts were not run through a real JumpStart install on SPARC or x86 for this post. Package names SITEbase and SITEmon are placeholders for your own packages.

Where this fits in the series

Solaris Admin Series, part 20. Previous: part 19, Solaris 10 JumpStart Profiles. Catch up with part 18, Solaris 10 JumpStart Server Setup, part 17, Solaris 10 sysidcfg and part 16, Solaris 10 Software Groups. Next up: JumpStart with DHCP, x86 PXE clients and WAN boot (part 21), then Flash Archives (part 22).

References: Oracle Solaris 10 1/13 Installation Guide: JumpStart Installations (Creating Begin Scripts, Creating Derived Profiles With a Begin Script, Creating Finish Scripts, Custom JumpStart Environment Variables); Converting Rules and Profile Files (js2ai, Solaris 11); the pkgadd(1M), admin(4) and patchadd(1M) manual pages.

Leave a Reply

Your email address will not be published. Required fields are marked *