To run a post-installation script an official procedure so called “first boot script” was introduced In last article and you may wonder if there’s any “finish script” we used before in Jumpstart. Official answer is NO but you can refer to the followings to make your own “finish script”.
Remember how we created the install service?
# installadm create-service \
-n i386-11_2 \
-a i386 \
-p solaris=http://pkg.oracle.com/solaris/release \
-s pkg:/install-image/solaris-auto-instal@5.11,5.11-0.175.2.0.0.42.2 \
-d /work/jumpstart/os-image/Install-i386-11-11.2/mini_root
In this command we put mini root to the directory /work/jumpstart/os-image/Install-i386-11-11.2/mini_root and this can be also verified by
# installadm list -v -n i386-11_2
Service Name Status Arch Type Secure Alias Aliases Clients Profiles Manifests
———— —— —- —- —— —– ——- ——- ——– ———
i386-11_2 on i386 iso no no 1 5 5 6
Image Path …….. /work/jumpstart/os-image/Install-i386-11-11.2/mini_root
Let’s check its content,
# ls /work/jumpstart/os-image/Install-i386-11-11.2/mini_root
auto_install/ dev/ grub.cfg mnt/ reconfigure solaris.zlib tmp/
bin@ devices/ home/ platform/ root/ solarismisc.zlib zvboot
boot/ export/ jack/ proc/ sbin@ system/
The file “solaris.zlib” is an ISO file that will be mounted as /usr during installation and AI client will run /usr/bin/auto-install to install packages. What we need to do is to modify that file to run an additional script we prepared.
# mkdir /root/solaris.zlib.i386-11.2
# mount -F hsfs /work/jumpstart/os-image/Install-i386-11-11.2/mini_root/solaris.zlib /mnt
# cd /mnt
# find . |cpio -pud /root/solaris.zlib.i386-11.2/
# cd
# umount /mnt
# vi /root/solaris.zlib.i386-11.2/bin/auto-install
You will see this line,
ai.perform_autoinstall()
add two more lines so that it looks like this,
ai.perform_autoinstall()
import os
os.system(“/usr/bin/AI_finish.sh”)
Then create this file /root/solaris.zlib.i386-11.2/bin/AI_finish.sh,
# vi /root/solaris.zlib.i386-11.2/bin/AI_finish.sh
and put the content into that file,
#!/bin/sh
SERVER_IP=`grep “AI service: ” /system/volatile/ai_sd_log | awk -F: ‘{ print $4}’| awk ‘{ print $1}’`
MAC=`grep “mac = ” /system/volatile/ai_sd_log | nawk ‘NF==3{ print $3}’`
if [ -f /net/$SERVER_IP/work/jumpstart/config/AI_begin_finish_script/$MAC/finish.sh ]
then
cd /net/$SERVER_IP/work/jumpstart/config/AI_begin_finish_script/$MAC
./finish.sh $SERVER_IP $MAC
fi
Let’s proceed to “re-pack” solaris.zlib,
# cd /root/solaris.zlib.i386.11.2
# mkisofs -o /solaris.zlib-i386-11.2 -quiet -N -l -R -U -allow-multidot -no-iso-translate \
-cache-inodes -d -D -V “compress” .
# lofiadm -C lzma /solaris.zlib-i386-11.2
# mv /work/jumpstart/os-image/Install-i386-11-11.2/mini_root/solaris.zlib \
/work/jumpstart/os-image/Install-i386-11-11.2/mini_root/solaris.zlib.orig
# mv /solaris.zlib-i386-11.2 /work/jumpstart/os-image/Install-i386-11-11.2/mini_root/solaris.zlib
We also need to enable NFS share for the directory /work/jumpstart/config/AI_begin_finish_script/ as we will put our finish script under this directory. So let’s check share and svcs output,
# share
rpool_work_jumpstart /work/jumpstart nfs anon=0,sec=sys,ro
IPC$ smb – Remote IPC
# svcs nfs/server
STATE STIME FMRI
online 9:59:34 svc:/network/nfs/server:default
No problem, nfs server is enabled and /work/jumpstart is shared.
Above is a one-time setting and can be applied to Solaris 11.1 and 11 11/11. After we configure it once we can focus on our finish script.
Now, it’s time to write a finish script for my AI client with mac address 08:00:27:82:9D:49,
# mkdir -p /work/jumpstart/config/AI_begin_finish_script/08:00:27:82:9D:49
# cd /work/jumpstart/config/AI_begin_finish_script/08:00:27:82:9D:49
# vi finish.sh
# chmod +x finish.sh
Here’s is a sample finish.sh. In this sample file we still create a first boot script /etc/rc3.d/S99first_boot_script
#!/bin/sh
echo “\n\nFinish script is beginning at `date`”
# Here we are mounting ZFS root pool to /a so and we will put all changes to /a
echo ” Mounting ZFS root pool …”
zfs list -rH rpool | awk ‘index($5,”/” ) == 1 { printf( “zfs mount -o mountpoint=/a%s %s\n”, $5, $1 ) }’ > /tmp/mount_root.sh
sh /tmp/mount_root.sh >> /dev/null 2>&1
echo ” Permitting SSH root login …”
(echo ‘1,$s/^PermitRootLogin.*$/PermitRootLogin yes/’; echo w; echo q) | ed /a/etc/ssh/sshd_config >> /dev/null
echo ” Permitting FTP root login …”
(echo ‘1,$s/^#RootLogin on$/RootLogin on/’; echo w; echo q) | ed /a/etc/proftpd.conf >> /dev/null
(echo ‘1,$s/root/#root/’; echo w; echo q) | ed /a/etc/ftpd/ftpusers >> /dev/null
echo ” Setting FQDN to test. by updating /etc/hosts …”
( echo ‘1,$s/[ \t][ \t]*loghost[ \t]*$/ test test. loghost/’ ; echo w ; echo q ) | ed /a/etc/hosts >> /dev/null
echo ” This will copy files from Files to AI client”
cd Files; find . | cpio -pud /a
echo ” Here we are creating a first boot script /etc/rc3.d/S99first_boot_script …”
echo ” (This will take effect in the first boot)”
# even in this finish script, we can still create a first boot script by creating /a/etc/rc3.d/S99first_boot_script
echo “#!/bin/sh\n” > /a/etc/rc3.d/S99first_boot_script
# this will enable ftp server
echo “svcadm enable network/ftp:default\n” >> /a/etc/rc3.d/S99first_boot_script
# this will disable graphical login, i.e., to use command line regularly and enable it manually if necessary
echo “svcadm disable graphical-login/gdm:default\n” >> /a/etc/rc3.d/S99first_boot_script
# this script will remove itself after execution
echo “/usr/bin/rm /etc/rc3.d/S99first_boot_script\n” >> /a/etc/rc3.d/S99first_boot_script
echo “Finish script is ending at `date`”
# not sure why but the installation log file /var/log/install/application-auto-installer:default.log will be
# truncated so we manually copy the log file. we can see output of this finish.sh in that log file
cp /var/svc/log/application-auto-installer:default.log /a/var/log/install
That’s all. After a standard setup of a client with installadm create-manifest, create-profile, create-client, you can boot up the client from network and above finish script will be executed once OS installation is completed.