Friday, July 25, 2014

Customizing Redhat/Oracle Linux CDROMs, ISOs and USBs - Part 2

The first part of this article explains how to add a kickstart file to an Oracle Linux 7 ISO and how to modify the boot menu to manage that file without editing the boot command. Another reason for customizing an ISO, is to add or replace RPMs it contains. You may want to add a RPM you've built on your own, like the latest Oracle database engine RPM or one/few you've got from third parties. This is exactly what this second part is about... And, as you'll figure out, this is easy!

Obviously those kinds of changes can deeply alter your ability to distribute the ISO and have implications above the technical stuff. You should probably avoid spreading customized distribution or at least check for yourself what you can do and what cannot. Nevertheless, customizing ISO can really speed up some of your installation and, for that reason, is worth understanding.

Building a dummy package

The goal here is to add a RPM to the regular Oracle Linux 7 ISO. To make it brief, it uses the simplest RPM you can probably create from the specification below:
cat dummy.spec 
Summary:      A dummy package
Name:         dummy
Version:      1.0
Release:      1
License:      GPLv2
Group:        System Environment/Base
BuildArch:    noarch

A dummy package

You should be able to create the associated RPM with the rpmbuild command below:
rpmbuild -bb dummy.spec 
Processing files: dummy-1.0-1.noarch
Provides: dummy = 1.0-1
Requires(rpmlib): rpmlib(FileDigests) <= [...] <= 3.0.4-1
Checking for unpackaged file(s): check-files dummy-1.0-1.x86_64
Wrote: /root/rpmbuild/RPMS/noarch/dummy-1.0-1.noarch.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.bR2LDH
+ umask 022
+ cd /root/rpmbuild/BUILD
+ /usr/bin/rm -rf /root/rpmbuild/BUILDROOT/dummy-1.0-1.x86_64
+ exit 0

Adding the RPM to the ISO

To rebuild the ISO, you should extract it in a regular directory as described in the first part of this article. We use a directory named OL7 for it. Once done, adding a RPM to an Oracle Linux 7 distribution only requires to add it to the Packages directory:
cp -p /root/rpmbuild/RPMS/noarch/dummy-1.0-1.noarch.rpm OL7/Packages/.

Rebuilding the Repository

The createrepo command is used to rebuild the repository index from the RPMs. Before you proceed, keep a copy of the comps-Server.xml file. It contains the description of the various types of installation as well as their associated groups and packages.
cd OL7  
cp repodata/*-comps-Server.xml comps.xml
Rebuilding the repository requires to list the RPM and to run the createrepo command:
find Packages -iname "*.rpm"|sort > rpms.lst
createrepo -o . -i rpms.lst .
rm rpms.lst

Customizing the comps.xml File

To link the RPM installation to an existing type of installation or to create new types of installation, the comps-Server.xml file needs to be adapted. In this example, the dummy package is simply added to the Core Group. To proceed, the red line below has simply be added to the package list:
       <packagereq type="default">dummy</packagereq>
Once the file changed, it can be added back to the repodata directory with a prefix that is its SHA256 checksum:
cp comps.xml \
   repodata/`sha256sum comps.xml|cut -d' ' -f1`-comps-Server.xml

gzip comps.xml
export SIG=`sha256sum comps.xml.gz|cut -d' ' -f1`
mv  comps.xml.gz  repodata/$SIG-comps-Server.xml.gz
Important Note:
Opposite to Oracle Linux 6, OL7 doesn't allow to select a single RPM from the installer. That's why learning to edit this file, including adding news types of installation or addons is so useful...

Referencing files in repomd.xml

To finish with the customization, the file and its compressed counterpart should be referenced in the repodata/repomd.xml file. Check the size, creation time and name of the files with the command below:
cd repodata
ls -l --time-style=+%s *comps-Server.xml*
-rw-r--r--. 1 root root 632976 1406309424 1fee86c5fdabac0aa1609cf27e7a75fbbf6bec94602a3dda9b2e69a3056f215d-comps-Server.xml
-rw-r--r--. 1 root root 137762 1406309422 7943914c495c230c524d38caf65d364d25d04005782a98afbce3bbd9ec64d042-comps-Server.xml.gz
Adapt and add the 2 sections below to the repomd.xml file:
<data type="group">
  <checksum type="sha256">1fee86c5fdabac0aa1609cf27e7a75fbbf6bec94602a3dda9b2e69a3056f215d</checksum>
  <location href="repodata/1fee86c5fdabac0aa1609cf27e7a75fbbf6bec94602a3dda9b2e69a3056f215d-comps-Server.xml"/>

<data type="group_gz">
  <checksum type="sha256">7943914c495c230c524d38caf65d364d25d04005782a98afbce3bbd9ec64d042</checksum>
  <open-checksum type="sha256">1fee86c5fdabac0aa1609cf27e7a75fbbf6bec94602a3dda9b2e69a3056f215d</open-checksum>
  <location href="repodata/7943914c495c230c524d38caf65d364d25d04005782a98afbce3bbd9ec64d042-comps-Server.xml.gz"/>

Recreating the ISO

The ISO can simply be recreated with mkisofs and implantisomd5 as already described
mkisofs -r -T -J -V "OL-7.0 Server.x86_64" \ 
   -b isolinux/isolinux.bin \
   -c isolinux/ \
   -no-emul-boot -boot-load-size 4 \
   -boot-info-table     \
   -o OracleLinux7.iso OL7/

implantisomd5 OracleLinux7.iso

Testing the ISO

Last but not least, the ISO must be tested. That's where Virtualbox comes to help.

Customizing ISO can be very useful to speed-up installation you don't want to automate with kickstart. It makes easy to upgrade Oracle Linux DVD with the latest Kernel and updates. As you've probably already figured out its also very easy to add any file or program...
To learn more about the subject of this post, we may want to read: How to use and edit comps.xml for package groups.

No comments:

Post a Comment