Tuesday, May 31, 2011

Anaconda System installer stage1 initrd patching .

Reference : http://hi.baidu.com/delovery/blog/item/8a454d9085fd1181a877a42b.html

Manually Update the Anaconda stage 1 image


The stage 1 image in anaconda confuses a lot of people. We've done a good job making stage 1 and stage 2 appear as a single entity, but they are really separate. The whole job of stage 1 is to load the necessary drivers to find anaconda (which we call the stage 2 image). Stage 2 could be located on a network source (NFS, HTTP, FTP), a local hard drive, or a CD-ROM drive. Stage 1 also takes care of configuring your network interface for installation if you indicate the stage 2 location is a network source.

When a bug is found in stage 1, patching it and testing it requires building a new ramdisk image to boot in to the installation environment. We cannot provide a mechanism like updates.img for several reasons. First, the stage 1 portion of anaconda is responsible for loading updates.img after it loads. Second, the stage 1 portion is basically one static program called /sbin/loader, so the only way to test it is to build a new one.

This document explains one of several ways to build a new stage 1 image for testing purposes. The example platform is Red Hat Enterprise Linux 5, but the techniques apply to Fedora Core 6 and higher.


I will assume you are building a new ramdisk image for the same architecture as your workstation. If you are not, you will need to explore other means of building the anaconda SRPM. You must build on the target architecture.

First, set up RPM to build locally:
     mkdir -p ~/rpmbuild/RPMS
     mkdir -p ~/rpmbuild/SRPMS
     mkdir -p ~/rpmbuild/SOURCES
     mkdir -p ~/rpmbuild/BUILD
     mkdir -p ~/rpmbuild/SPECS
     echo '%_topdir %(echo $HOME)/rpmbuild' > ~/.rpmmacros

Next, obtain the anaconda source RPM from the RHEL-5 media and install it. You should not be doing this as root:
     rpm -Uvh anaconda-

Now you are ready to patch anaconda to your liking.


Extract the source:

     cd ~/rpmbuild/SPECS
     rpmbuild -bp anaconda.spec
RPM may complain about missing dependencies. Install them if you lack them. Anaconda needs a lot of stuff in order to compile.

Patch the source:
     cd ~/rpmbuild/BUILD/anaconda-

The stage 1 sources are located in the loader2 subdirectory. The stage 1 components also link against libisys which is in the isys subdirectory. Either way, you will want to make patches against this source tree and put the patches in the ~/rpmbuild/SOURCES directory. For this example, we are patching loader2/loader.c:
cd loader2
     cp -a loader.c loader.c.orig
     vim loader.c
     # la la la...making my changes.... :wq
     cd ~/rpmbuild/BUILD
     gendiff anaconda- .orig > ~/rpmbuild/SOURCES/anaconda.patch

Now go and edit ~/rpmbuild/SPECS/anaconda.spec and add anaconda.patch as a patch and make sure it's applied in the %prep section after the %setup macro is run.


Simple, use rpmbuild:
     cd ~/rpmbuild/SPECS
     rpmbuild -ba anaconda.spec

The resulting packages will be written to ~/rpmbuild/RPMS


First, we need to get the two stage 1 components that matter: loader and init.
     cd ~/rpmbuild/RPMS/
     rpmdev-extract anaconda-runtime-
     cd anaconda-runtime-
     cp -a usr/lib/anaconda-runtime/loader/init ~/init
     cp -a usr/lib/anaconda-runtime/loader/loader ~/loader

Second, get the ramdisk image that you want to update. For this example, I am updating the pxeboot/initrd.img from the RHEL-5 tree. I have copied the initrd.img file to my home directory:
     cd ~
     mkdir tmp-initrd
     cd tmp-initrd
     gzip -dc ~/initrd.img | cpio -id
     cat ~/init > sbin/init
     cat ~/loader > sbin/loader
     (find . | cpio -c -o | gzip -9) > ~/initrd.img
     cd ~
Now the initrd.img file in my home directory contains the new loader and init binaries. Copying this to the boot server and you are ready to go with a new initrd.img for RHEL-5.


isolinux (not available for Itanium systems, you'll need to use a loop back mount of the ia64 boot.iso) is used for booting the Red Hat Enterprise Linux installation CD. To create your own CD-ROM to boot the installation program, use the following instructions:

Copy the isolinux/ directory from the Red Hat Enterprise Linux CD #1 into a temporary directory (referred to here as path-to-workspace) using the following command:

cp -r path-to-cd/isolinux/ path-to-workspace

Change directories to the path-to-workspace directory you have created:

cd path-to-work-space

Copy the new initrd.img to path-to-workspace

cp ~/initd.img path-to-workspace/isolinux/

Make sure the file(s) you have copied have appropriate permissions:

chmod u+w isolinux/*
Finally, issue the following command to create the ISO image file:

mkisofs -o file.iso -b isolinux.bin -c boot.cat -no-emul-boot \\
-boot-load-size 4 -boot-info-table -R -J -v -T isolinux/

No comments: