Custom Installation CentOS/RHEL DVD

30 11 2009

I recently had to create a custom CentOS 5.4 DVD that included a set list of installed packages, some files copied from the DVD and a comprehensive kickstart script.  After trawling the web for a couple of days I did manage to successfully get my image operational – there are quite a few quirks and the required information is on the web but it’s not exactly in one place… So here’s my effort:

– Copy the CentOS DVD to a local image folder (you can use the actual physical CentOS DVD or just the ISO file).  At this stage we have to ensure that all files from the disk are copied including .discinfo and .treeinfo.  If we don’t we’ll get the ‘CentOS cd was not found error…:

#mkdir -p /mnt/centos (we’ll only use this mount the iso/dvd)

#mount -o loop /home/mark/CentOS-5.4-i386-bin-DVD.iso /mnt/centos (if using the iso file)

#mount /dev/cdrom /mnt/centos (if using the physical DVD)

#cp -av /mnt/centos /home/mark/  (the options -av ensure all files and links are copied)

#mv /home/mark/centos /home/mark/customdvd

– Remove the repodata information from our customdvd image folder, we’re going to regenerate this data later.  (NB: It’s important not to remove repodata/comp.xml as this is a full package list we can edit):

#cd /home/mark/customdvd/

#rm ./repodata/*.gz ./repomd.xml

– Modify or add packages to our customdvd image folder.  In this example I’ll add the lshw rpm package to keep it straightforward.  I downloaded this package from rpmforge.com.  The DVD has a CentOS folder which contains all the rpm packages, we’ll keep ours in there too. (NB: you’ll need to add any dependencies into this folder too, if they’re not already there):

#cp /home/mark/lshw-2.14-1.el5.rf.i386.rpm /home/mark/customdvd/CentOS/

– At this stage we need to add our lshw package to the comps.xml file.  The comps.xml file is a xml database file that lists all the packages in the familiar installation groups along with whether or not they’re installed as part of that group by default or not.  The repodata we create later reads the comps.xml file and outputs the required file information for our installation.  With only one package it’s probably easiest to just add the package name to the ‘core’ package group, but just in case you’ve a bunch more packages to install I’m going to create a new group called ‘custom’ and add lshw to the new group.  For comps.xml it’s important you add the rpm package name, this is not necessarily the same name as the file/package, so query the file first to find the name with the command:

#rpm -q –qf ‘%{NAME}\n’ -p /home/mark/lshw-2.14-1.el5.rf.i386.rpm

In our case the package name actually is ‘lshw’ so we edit the file comps.xml and enter something like the following (hopefully this is self-explanatory):

<group>
<id>custom</id>
<name>custom</name>
<name xml:lang=”uk”>custom</name>
<description>Custom Tools</description>
<description xml:lang=”uk”>Custom Tools</description>
<default>true</default>
<uservisible>true</uservisible>
<packagelist>
<packagereq type=”mandatory”>lshw</packagereq>
</packagelist>
</group>

– Now we need to recreate the repodata for our installation.  The repodata is the link between comps.xml and the rpm packages in the DVD’s CentOS folder.  Using the createrepo utility we can iterate through all the rpm’s and create the appropriate files to help with our installation (we deleted they earlier).  The files that createrepo generates need to be relative to the DVD’s path so we have to declare the path before doing the regeneration:

#cd /home/mark/customdvd/

#declare -x discinfo=`head -1 .discinfo`

#createrepo -u “media://$discinfo” -g repodata/comps.xml .

Hopefully at this stage you’ll see the rpms being iterated over and you’ll end up with additional files in customdvd/repodata.  If you don’t have the createrepo utility installed use ‘yum install createrepo’ to get it.

At this stage our custom installation DVD could be made into an iso and burnt, however if you want to add more files to the DVD (not rpm packages) copy them into the customdvd image folder. Before we do that however we may want to add a kickstart file to the DVD.

– (Optional) Copy the file kickstart file to the DVD:

#cp /home/mark/ks.cfg /home/mark/customdvd/

At this point we could create the DVD iso and just boot and type ‘linux ks=cdrom:/ks.cfg’ to run through our kickstart installation, however to have it automatically run our kickstart installation, edit the file isolinux/isolinux.cfg file so that our kickstart runs automatically, for example:

label linux
kernel vmlinuz
append initrd=initrd.img ks=cdrom:/ks.cfg

To use files from the DVD during kickstart installation, for example predefined config files, you’ll need to copy the files using a %post –nochroot script.  Don’t panic though, after copying the files you can simply using a standard %post for example:

%post –nochroot
mkdir /mnt/sysimage/tempdir
mkdir -p /mnt/cdrom
mount -t iso9660 /tmp/cdrom /mnt/cdrom
cp /mnt/cdrom/CentOS/filex /mnt/sysimage/tempdir/

After this you can use filex from within your %post, for example:

%post
cp /tempdir/filex /opt

Ok – so now we have our customdvd image the way we need it, we can create our iso using mkisofs (you probably won’t need all the options so just strip out the ones you don’t need):

mkisofs  -o /home/mark/customcentos.iso -r -J -N -d -hide-rr-moved \
-sysid `hostname`  -V ‘Custom CENTOS’  \
-no-emul-boot -boot-info-table -boot-load-size 4 \
-b isolinux/isolinux.bin -c isolinux/boot.cat \
/home/mark/dvdimage/

After this we should have a shiny new custom CentOS/RHEL DVD.  Ordinarily I check the output ISO file using a virtual machine.  Best of luck.

Advertisements

Actions

Information

9 responses

9 04 2010
Prasad

Hi Mark,
Great Article. Appreciate it !!!!

Cheers,
Prasad Pednekar.

4 08 2010
Roan

Just as a note, there are a couple of errors in this document.

First, to pull the package name, the proper command is:

rpm -q -–qf ‘%{NAME}\n’ -p /home/mark/lshw-2.14-1.el5.rf.i386.rpm (double dashes before the qf)

Second, and this may just be a Cent4.8 issue, but there was no comps.xml in the repodata directory. I copied the once from CentOS/base to the repodata directory and used that.

Finally, the mkisofs command at the end should have “/home/mark/customdvd”, not “/home/mark/dvdimage”. It needs to be the directory path of the working directory.

Other than those little issues, very helpful article.

30 08 2010
meowiso

Great Article. Appreciate it !!!!
helped me alot when i was setting up my server
Hentai JAV DVDISO

13 07 2012
Allan Button

I had problems with the command to cp -a

Turns out I did not have the same users as the ISO did so I was getting a permission denied even though I was root.

The solution was to

cp -rv -dR –preserve=links /mnt/centos/ /root/iso_remake/i386/

Allan Button

23 08 2012
Ritwick

“At this stage we have to ensure that all files from the disk are copied including .discinfo and .treeinfo. If we don’t we’ll get the ‘CentOS cd was not found error…”

I think above were the most important lines…..that rescued me when I was stucked wit my config 🙂

Great Article Mark!
keep writting

22 09 2012
Jayesh

Thanks. Really appreciate this article.

30 09 2012
7 07 2013
frontier internet

I am actually delighted to read this blog posts which contains
plenty of useful information, thanks for providing these kinds of information.

2 04 2015
arun

#createrepo -u “media://$discinfo” -g repodata/comps.xml .

when I type this .. it is showing errors on centos 6.6

createrepo -u “media:///$discinfo” -g repodata/comps.xml
Error: Must specify a directory to index.
Usage: genpkgmetadata.py [options]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: