Tutorial
Build IBM AIX installp packages
A comprehensive guide to create your own installp packagesIntroduction
IBM AIX uses its own packaging format known as installp for installing, uninstalling, and managing software packages. You can use the installp command to install filesets from an installation package. All the software that are part of the AIX base image are packaged in the installp format.
This tutorial describes the process of creating your own AIX installp packages. Building installp packages on AIX is a straightforward task with the help of the /usr/sbin/mkinstallp command. mkinstallp belongs to the bos.adt.insttools fileset from the bos.adt package, which is available in the AIX Base media. It is important to note that root privileges are necessary to build a package.
Step-by-step guide to build an installp package
To understand the process of creating an installp package, let us create a simple example package.
Create a directory for the package
Begin by setting up a directory structure where your package will reside.
# mkdir -p /sandboxPrepare the files that need to be installed
Let's create a simple shell script, clean_tmp that will be included in your package. The clean_tmp script is designated for installation under /usr/bin, which will clean the files under the /tmp directory. To ensure seamless deployment, it is crucial that the files within /sandbox maintain the same relative structure as they will in the root directory. This involves meticulously setting up directories within /sandbox and copying clean_tmp to /usr/bin within this structure. This meticulous setup guarantees that upon installation, the script is correctly positioned and readily accessible on the system.
# mkdir -p /sandbox/usr/bin # cat /sandbox/usr/bin/clean_tmp #!/bin/ksh print "Cleaning up /tmp" rm –rf /tmp/* > /dev/null 2>&1 # chmod a+x /sandbox/usr/bin/clean_tmp # ls -lrt /sandbox/usr/bin/clean_tmp -rwxr-xr-x 1 root system 70 Jul 05 13:46 /sandbox/usr/bin/clean_tmp #Run pre- and post-installation scripts
The package being created here is fairly simple, but often you might need to run scripts during the installation and the uninstallation processes. This is easy to achieve.
I do not have much task to do in the pre-installation script. So, let’s keep it simple.
Note: Having a pre-installation script is not mandatory. I am adding this script here for demo purpose only.
# echo ‘echo PRE INSTALL’ > /sandbox/pre_install.shIn the post-installation script, I will be adding an entry to the /var/spool/cron/crontab file to run the clean_tmp script once every day.# cat /sandbox/post_install.sh #!/bin/ksh TMPFILE=$ echo '0 0 * * * /usr/bin/clean_tmp' > /tmp/$TMPFILE /usr/bin/crontab /tmp/$TMPFILE if [ $? != 0 ]; then rm /tmp/$TMPFILE exit 1 fi rm /tmp/$TMPFILE exit 0 #In the pre_deinst script, delete the crontab entry before uninstalling the fileset.
# cat /sandbox/pre_deinst.sh #!/bin/ksh /usr/bin/crontab -l | grep -v clean_tmp | crontab if [ $? != 0 ]; then exit 1 fi # # chmod u+x /sandbox/pre_install.sh /sandbox/post_install.sh /sandbox/pre_deinst.shIt is important to provide the full path for the scripts. It is not mandatory for them to be part of your build package directory.
Build the package
Navigate to your build directory and run the
mkinstallpcommand to initiate the package creation process. Themkinstallpcommand provides you with an interactive prompt to guide you through the process.# cd /sandbox # mkinstallp Using /sandbox as the base package directory. Cannot find /sandbox/.info. Attempting to create. Using /sandbox/.info to store package control files. Cleaning intermediate files from /sandbox/.info. ************************************************************ | Beginning interactive package input | | * - required; () - example value; [] - default value | ************************************************************ * Package Name (xyz.net) []: clean * Package VRMF (1.0.0.0) []: 1.0.0.0 Update (Y/N) [N]: N Number of filesets in clean (1) [1]: Gathering info for new fileset (1 remaining) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * Fileset Name (clean.rte) []: clean.rte * Fileset VRMF (1.0.0.0) []: 1.0.0.0 * Fileset Description (some text) []: Cleans /tmp directory Do you want to include a copyright file for this fileset? (Y/N) [N]: N Entering information for the USER part liblpp files Do you want to include an installp pre_i/u script for this fileset? (Y/N) [N]: Y Enter the absolute path of the pre_i/u script to include []: /sandbox/pre_install.sh Do you want to include an installp unpre_i/u script for this fileset? (Y/N) [N]: N Do you want to include an installp post_i/u script for this fileset? (Y/N) [N]: Y Enter the absolute path of the post_i/u script []: /sandbox/post_install.sh Do you want to include an installp unpost_i/u script for this fileset? (Y/N) [N]: N Do you want to include a pre-deinstall Script for this fileset? (Y/N) [N]: Y Enter the absolute path of the pre-deinstall Script to include []: /sandbox/pre_deinst.sh Do you want to include an installp pre_rm script for this fileset? (Y/N) [N]: N Do you want to include an installp config script for this fileset? (Y/N) [N]: N Would you like to create ROOT part? (Y/N) [N]: N Bosboot required (Y/N) [N]: N License agreement acceptance required (Y/N) [N]: N Include license files for clean.rte in this package (Y/N) [N]: N Do you want to specify Requisites using a file for this fileset? (Y/N) [N]: N Number of Requisites for clean.rte (1) [0]: Number of filesystems requiring additional space for clean.rte [0]: You should include any directories that you are creating in the file count. (ie: For /usr/proj/myFile, enter 2; 1 for /usr/proj and 1 for /usr/proj/myFile) Number of USR part files in clean.rte (1) [0]: 1 * 1 of 1. Directory or File Path (/usr/proj/myFile) []: /usr/bin/clean_tmp Do you want to make this fileset relocatable? (Y/N) [N]: N Do you want to include an override inventory file for this fileset? (Y/N) [N]: N Do you want to add WPAR attributes to your fileset? (Y/N) [N]: N Using /sandbox/.info/clean.template as the template file. clean 1.0.0.0 I processing clean.rte creating ./.info/liblpp.a creating ./tmp/clean.1.0.0.0.bff #After the package is built, you can find it in the tmp directory:
# ls -lrt /sandbox/tmp/clean.1.0.0.0.bff -rw-r--r-- 1 root system 3072 Jul 05 15:05 /sandbox/tmp/clean.1.0.0.0.bff #The
mkinstallpcommand also generates a template file for the created package, which can be modified as per the requirement to create a customized package.# cat /sandbox/.info/clean.template Package Name: clean Package VRMF: 1.0.0.0 Update: N Fileset Fileset Name: clean.rte Fileset VRMF: 1.0.0.0 Fileset Description: Cleans /tmp directory USRLIBLPPFiles Pre-installation Script: /sandbox/pre_install.sh Post-installation Script: /sandbox/post_install.sh Pre-deinstall Script: /sandbox/pre_deinst.sh EOUSRLIBLPPFiles Bosboot required: N License agreement acceptance required: N Include license files in this package: N Requisites: USRFiles /usr/bin/clean_tmp EOUSRFiles ROOT Part: N ROOTFiles EOROOTFiles Relocatable: N EOFileset #Install the package
You can now use the package generated by the
mkinstallpcommand to install the software:# pwd /sandbox/tmp # ls -lrt total 8 -rw-r--r-- 1 root system 3072 Jul 05 15:05 clean.1.0.0.0.bff # installp -ad . clean.rte +-----------------------------------------------------------------------------+ Pre-installation Verification... +-----------------------------------------------------------------------------+ Verifying selections...done Verifying requisites...done Results... SUCCESSES --------- Filesets listed in this section passed pre-installation verification and will be installed. Selected Filesets ----------------- clean.rte 1.0.0.0 # Cleans /tmp directory << End of Success Section >> +-----------------------------------------------------------------------------+ BUILDDATE Verification ... +-----------------------------------------------------------------------------+ Verifying build dates...done FILESET STATISTICS ------------------ 1 Selected to be installed, of which: 1 Passed pre-installation verification ---- 1 Total to be installed +-----------------------------------------------------------------------------+ Installing Software... +-----------------------------------------------------------------------------+ installp: APPLYING software for: clean.rte 1.0.0.0 PRE INSTALL Finished processing all filesets. (Total time: 1 secs). +-----------------------------------------------------------------------------+ Summaries: +-----------------------------------------------------------------------------+ Installation Summary -------------------- Name Level Part Event Result ------------------------------------------------------------------------------- clean.rte 1.0.0.0 USR APPLY SUCCESS # crontab -l 0 0 * * * /usr/bin/clean_tmp # ls -lrt /usr/bin/clean_tmp -rwxr-xr-x 1 root system 70 Jul 05 13:46 /usr/bin/clean_tmp #Uninstall the fileset and verify if it is removed. Then, ensure that the pre-deinstallation script was invoked and the cleanup was performed.
# installp -u clean.rte +-----------------------------------------------------------------------------+ Pre-deinstall Verification... +-----------------------------------------------------------------------------+ Verifying selections...done Verifying requisites...done Results... SUCCESSES --------- Filesets listed in this section passed pre-deinstall verification and will be removed. Selected Filesets ----------------- clean.rte 1.0.0.0 # Cleans /tmp directory << End of Success Section >> FILESET STATISTICS ------------------ 1 Selected to be deinstalled, of which: 1 Passed pre-deinstall verification ---- 1 Total to be deinstalled +-----------------------------------------------------------------------------+ Deinstalling Software... +-----------------------------------------------------------------------------+ installp: DEINSTALLING software for: clean.rte 1.0.0.0 Finished processing all filesets. (Total time: 0 secs). +-----------------------------------------------------------------------------+ Summaries: +-----------------------------------------------------------------------------+ Installation Summary -------------------- Name Level Part Event Result ------------------------------------------------------------------------------- clean.rte 1.0.0.0 USR DEINSTALL SUCCESS # crontab -l # ls -lrt /usr/bin/clean_tmp ls: 0653-341 The file /usr/bin/clean_tmp does not exist. #Build the update package
The
mkinstallpcommand also allows us to build the updates to a package. The updates are helpful in including bug fixes or new features with our packages.Next, you need to modify your existing files or add new files to your /sandbox directory.
In the following example, I am modifying the clean_tmp script to clean up one more directory.
# cat /sandbox/usr/bin/clean_tmp #!/bin/ksh print "Cleaning up /tmp" rm -rf /tmp/* > /dev/null 2>&1 rm -rf /app_tmp/* > /dev/null 2>&1 #Instead of going through the
mkinstallpprompt all over again, we can make our changes in the existing template file and use the same to create an update.Updates should have an increment to the VRMF (Version.Release.Modification.FixLevel) of the fileset. So, we should update the VRMF to one level higher.
# cat /sandbox/.info/clean.template Package Name: clean Package VRMF: 1.0.1.0 Update: N Fileset Fileset Name: clean.rte Fileset VRMF: 1.0.1.0 Fileset Description: Cleans /tmp directory USRLIBLPPFiles Pre-installation Script: /sandbox/pre_install.sh Post-installation Script: /sandbox/post_install.sh Pre-deinstall Script: /sandbox/pre_deinst.sh EOUSRLIBLPPFiles Bosboot required: N License agreement acceptance required: N Include license files in this package: N Requisites: USRFiles /usr/bin/clean_tmp EOUSRFiles ROOT Part: N ROOTFiles EOROOTFiles Relocatable: N EOFileset #Create a backup of this template file and remove the .info directory.
# cp /sandbox/.info/clean.template /sandbox/clean.template # rm -rf /sandbox/.info #Rebuild the package
Delete the .info directory to clear previous build information and rebuild the package with the updated template.
# rm -rf .info # mkinstallp -T /sandbox/clean.template Using /sandbox as the base package directory. Cannot find /sandbox/.info. Attempting to create. Using /sandbox/.info to store package control files. Cleaning intermediate files from /sandbox/.info. Using /sandbox/clean.template as the template file. clean 1.0.1.0 I processing clean.rte creating ./.info/liblpp.a creating ./tmp/clean.1.0.1.0.bff #You can find the new version of the package under the tmp directory as before:
# ls -lrt /sandbox/tmp/clean.1.0.1.0.bff -rw-r--r-- 1 root system 3072 Jul 05 15:47 /sandbox/tmp/clean.1.0.1.0.bff #To verify that the package works correctly, install the new image and check if the new updated shell script is also installed.
# pwd /sandbox/tmp # ls -lrt total 8 -rw-r--r-- 1 root system 3072 Jul 05 15:47 clean.1.0.1.0.bff # lslpp -l clean.rte Fileset Level State Description ---------------------------------------------------------------------------- Path: /usr/lib/objrepos clean.rte 1.0.0.0 COMMITTED Cleans /tmp directory # # installp -ad . clean.rte +-----------------------------------------------------------------------------+ Pre-installation Verification... +-----------------------------------------------------------------------------+ Verifying selections...done Verifying requisites...done Results... SUCCESSES --------- Filesets listed in this section passed pre-installation verification and will be installed. Selected Filesets ----------------- clean.rte 1.0.1.0 # Cleans /tmp directory << End of Success Section >> +-----------------------------------------------------------------------------+ BUILDDATE Verification ... +-----------------------------------------------------------------------------+ Verifying build dates...done FILESET STATISTICS ------------------ 1 Selected to be installed, of which: 1 Passed pre-installation verification ---- 1 Total to be installed +-----------------------------------------------------------------------------+ Installing Software... +-----------------------------------------------------------------------------+ installp: APPLYING software for: clean.rte 1.0.1.0 PRE INSTALL Finished processing all filesets. (Total time: 1 secs). +-----------------------------------------------------------------------------+ Summaries: +-----------------------------------------------------------------------------+ Installation Summary -------------------- Name Level Part Event Result ------------------------------------------------------------------------------- clean.rte 1.0.1.0 USR APPLY SUCCESS # crontab -l 0 0 * * * /usr/bin/clean_tmp # cat /usr/bin/clean_tmp #!/bin/ksh print "Cleaning up /tmp" rm -rf /tmp/* > /dev/null 2>&1 rm -rf /app_tmp/* > /dev/null 2>&1 #We can also build the update packages using the
mkinstallpcommand. The update packages include only the modifications done to an existing fileset. Updates, if not committed will allow us to reject the update, providing a facility to roll back to the old version.To generate an update, you can set the
Updatefield toYin the template file or in themkinstallpinteractive session. You can choose to include any extra packaging scripts required for the update.# mkinstallp Using /sandbox as the base package directory. Cannot find /sandbox/.info. Attempting to create. Using /sandbox/.info to store package control files. Cleaning intermediate files from /sandbox/.info. ************************************************************ | Beginning interactive package input | | * - required; () - example value; [] - default value | ************************************************************ * Package Name (xyz.net) []: clean * Package VRMF (1.0.0.0) []: 1.0.1.0 Update (Y/N) [N]: Y Number of filesets in clean (1) [1]: Gathering info for new fileset (1 remaining) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * Fileset Name (clean.rte) []: clean.rte * Fileset VRMF (1.0.0.0) []: 1.0.1.0 * Fileset Description (some text) []: Cleans /tmp directory Do you want to include a copyright file for this fileset? (Y/N) [N]: N Entering information for the USER part liblpp files Do you want to include an installp pre_i/u script for this fileset? (Y/N) [N]: N Do you want to include an installp post_i/u script for this fileset? (Y/N) [N]: N Do you want to include a pre-deinstall Script for this fileset? (Y/N) [N]: N Do you want to include an installp pre_rm script for this fileset? (Y/N) [N]: N Do you want to include an installp config script for this fileset? (Y/N) [N]: N Would you like to create ROOT part? (Y/N) [N]: N Bosboot required (Y/N) [N]: N License agreement acceptance required (Y/N) [N]: N Include license files for clean.rte in this package (Y/N) [N]: N Do you want to specify Requisites using a file for this fileset? (Y/N) [N]: N Number of Requisites for clean.rte (1) [0]: Number of filesystems requiring additional space for clean.rte [0]: You should include any directories that you are creating in the file count. (ie: For /usr/proj/myFile, enter 2; 1 for /usr/proj and 1 for /usr/proj/myFile) Number of USR part files in clean.rte (1) [0]: 1 * 1 of 1. Directory or File Path (/usr/proj/myFile) []: /usr/bin/clean_tmp This file exists in another fileset on the system. Are you sure you want to include this file? (Y/N) []: Y Do you want to make this fileset relocatable? (Y/N) [N]: N Do you want to include an override inventory file for this fileset? (Y/N) [N]: N Do you want to add WPAR attributes to your fileset? (Y/N) [N]: N Using /sandbox/.info/clean.template as the template file. 0503-880 mkinstallp: This file /usr/bin/clean_tmp already exists as a system file. clean 1.0.1.0 S processing clean.rte creating ./.info/clean.rte.a copying ./.info/clean.rte.a to ./usr/lpp/clean/clean.rte/1.0.1.0/liblpp.a creating ./tmp/clean.1.0.1.0.bff #Here is the corresponding template file:
# cat /sandbox/.info/clean.template Package Name: clean Package VRMF: 1.0.1.0 Update: Y Fileset Fileset Name: clean.rte Fileset VRMF: 1.0.1.0 Fileset Description: Cleans /tmp directory USRLIBLPPFiles EOUSRLIBLPPFiles Bosboot required: N License agreement acceptance required: N Include license files in this package: N Requisites: USRFiles /usr/bin/clean_tmp EOUSRFiles ROOT Part: N ROOTFiles EOROOTFiles Relocatable: N EOFileset #
Summary
This comprehensive approach described in this tutorial ensures that you can create, update, and manage AIX installation packages efficiently. By following these steps, you can streamline your software deployment processes and maintain consistency across installations.
Reference
For detailed information about installp packaging, refer: AIX: Packaging software for installation documentation.