Prerequisite is that you have a working local repository that can be used to install the client.
Creating a First-Boot Package
We need to create a package to go into the repository. Since there are no post-install scripts with the Image Packaging System, we will create an SMF service that will be automatically enabled so that it will run when the system boots. One technique used with Jumpstart was to install a script into /etc/rc3.d that would run late in the boot sequence and would then remove itself so that it would only run on the first boot. We will take a similar path with our first-boot service. We will have it disable itself so that it doesn't continue to run on each boot. There are two parts to creating this simple package. First, we have to create the manifest for the service, and second, we have to create the script that will be used as the start method within the service. This area is covered in more depth in the OpenSolaris Migration Hub paper on Creating a First Boot Service. In fact, we will use the manifest from that paper.
Creating the Manifest
We will use the manifest from Creating a First Boot Service directly and call it finish-script-manifest.xml. The main points to see here are
the service is enabled automatically when we import the manifest
the service is dependent on svc:/milestone/multi-user so that it won't run until the system is in the Solaris 11 Express equivalent of run level 3.
the script /usr/bin/finish-script.sh, which we will provide, is going to be run as the start method when the service begins.
finish-script-manifest.xml:
Creating the Script
In this example, we will create a trivial finish script. All it will do is log that it has run and then disable itself. You could go so far as to have the finish script uninstall itself. However, rather than do that we will just disable the service. Certainly, you could have a much more expansive finish script, with multiple files and multiple functions. Our script is short and simple:
finish-script.sh:
#!/usr/bin/bash
svcadm disable finish-script
#pkg uninstall pkg:/finish
echo "Completed Finish Script" > /var/tmp/finish_log.$$
exit 0
Adding Packages to Repository
Now that we have created the finish script and the manifest for the first-boot service, we have to insert these into the package repository that we created earlier. Take a look at the pkgsend man page for a lot more details about how all of this works. It's possible with pkgsend to add SVR4 package bundles into the repository, as well as tar-balls and directories full of files. Since our package is simple, we will just insert each package.
When we open the package in the repository, we have to specify the version number. Take a good look at the pkg(5) man page to understand the version numbering and the various actions that could be part of the package. Since I have been working on this script, I have decided that it is version 0.3. We start by opening the package for insertion. Then, we add each file to the package in the repository, specifying file ownership, permissions, and path. Once all the pieces have been added, we close the package and the FMRI for the package is returned.
# eval `pkgsend -s http://localhost:9000/ open finish@0.3`
# pkgsend -s http://localhost:9000/ add file finish-script-manifest.xml mode=0555 owner=root group=bin path=/var/svc/manifest/system/finish-script-manifest.xml restart_fmri=svc:/system/manifest-import:default
# pkgsend -s http://localhost:9000/ add file finish-script.sh mode=0555 owner=root group=bin path=/usr/bin/finish-script.sh
# pkgsend -s http://localhost:9000/ close
PUBLISHED
pkg://local-pkgs/finish@0.3,5.11:20101220T174741Z
Updating the AI Manifest
Now that the repository is created, we can add the new repository as a publisher to verify that it has the contents we expect. On the package server, itself, we can add this publisher. Remember that we set the prefix for the publisher to local-pkgs and that we specified it should run on port 9000. This name could be anything that makes sense for your enterprise - perhaps the domain for the company or something that will identify it as local rather than part of Solaris is a good choice.
# pkg set-publisher -p http://localhost:9000 local-pkgs
pkg set-publisher:
Added publisher(s): local-pkgs
# pkg list -n "pkg://local-pkgs/\*"
NAME (PUBLISHER) VERSION STATE UFOXI
finish (local-pkgs) 0.3 known -----
Now that we know the repository is on-line and contains the packages that we want to deploy, we have to update the AI manifest to reflect both the new publisher and the new packages to install. First, to update the publisher, beneath the section that specifies the default publisher, add a second source for this new publisher:
Then, add the packages to the list of packages to install. Depending on how you named your package, you may not need to specify the repository for installation. IPS will search the path of repositories to find each package. However, it's not a bad idea to be specific.
Now, when you install the system using this manifest, in addition to the regular Solaris bits being installed, and the system configuration services executing, the finish script included in your package will be run on the first boot. Since the script called by the service turns itself off, it will not continue to run on subsequent boots. You can do whatever sort of additional configuration that you might need to do. But, before you spend a long time converting all of your old Jumpstart scripts into a first-boot service, take a look at the built-in capabilities of AI and of Solaris 11 Express in general. It may be that much of the work you had to code yourself before is no longer required. For example, IP interface configuration is simple and persistent with ipadm. Other new functions in Solaris 11 Express remove the need to write custom code, too. But for the cases where you need custom code, this sort of first-boot service gives you a hook so that you can do what you need.