Saturday, August 16, 2008
Building Red Hat Enterprise RPMs
Red Hat makes source RPMs freely available at ftp.redhat.com/You can find the SRPMs for RHEL 5 Server in the /pub/redhat/linux/enterprise/5Server/en/os/SRPMS directory. If you're working with RHEL 5 Desktop, substitute 5Client for 5Server.
If you're studying for the Red Hat exams using a "rebuild," you don't have to buy RHEL. Alternatively, you can build Red Hat Enterprise RPMs from the source code. For example, you can learn more about the Samba server from the Samba source code. To do so, take the following steps. First, navigate to ftp.redhat.com (or a mirror site) and navigate to the directory with RHEL 5 source RPMs. (The source code for the RHEL 5 Client and Server are identical, as of this writing). Then you can
1. Down the RHEL 5 version of the package that contains the Samba server, samba-*.src.rpm.
2. Install the source RPM package. The rpm command described earlier sets up the source code in your /usr/src/redhat tree.
3. Build the RPM from source. The rpmbuild commands use the code loaded in the /usr/src/redhat directories to create RPM packages in the /usr/src/redhat/RPMs directory, in the subdirectory associated with your architecture.
If you're studying for the Red Hat exams using a "rebuild," you don't have to buy RHEL. Alternatively, you can build Red Hat Enterprise RPMs from the source code. For example, you can learn more about the Samba server from the Samba source code. To do so, take the following steps. First, navigate to ftp.redhat.com (or a mirror site) and navigate to the directory with RHEL 5 source RPMs. (The source code for the RHEL 5 Client and Server are identical, as of this writing). Then you can
1. Down the RHEL 5 version of the package that contains the Samba server, samba-*.src.rpm.
2. Install the source RPM package. The rpm command described earlier sets up the source code in your /usr/src/redhat tree.
3. Build the RPM from source. The rpmbuild commands use the code loaded in the /usr/src/redhat directories to create RPM packages in the /usr/src/redhat/RPMs directory, in the subdirectory associated with your architecture.
Labels:
rpm,
source rpm
Friday, August 15, 2008
Building Custom Source and Binary RPMs
By now, you should understand where you should modify a source RPM spec file to change compile-time options in the %build section. However, there's much more to building customized RPMs. Once you have modified the spec file, you need to tell RPM to build a new binary and source RPM.
You can build an RPM using the rpmbuild command, with the build switch, -b. By itself, rpmbuild -b calls the scripts specified in the %prep, %build, and %install section of the spec file. Normally, you'll modify the -b with a, which makes RPM go through the build process, step by step. The rpmbuild command is directed at a spec file. For example, this command
# rpmbuild -ba vsftpd.spec
directs RPM to create binary and source RPMs from this spec file. Alternatively, if you just want the binary RPM, use the following commands:
# rpmbuild -bb vsftpd.spec
Naturally, the RPMs are created in the RPMs/ and SRPMS/ subdirectories.
You can build an RPM using the rpmbuild command, with the build switch, -b. By itself, rpmbuild -b calls the scripts specified in the %prep, %build, and %install section of the spec file. Normally, you'll modify the -b with a, which makes RPM go through the build process, step by step. The rpmbuild command is directed at a spec file. For example, this command
# rpmbuild -ba vsftpd.spec
directs RPM to create binary and source RPMs from this spec file. Alternatively, if you just want the binary RPM, use the following commands:
# rpmbuild -bb vsftpd.spec
Naturally, the RPMs are created in the RPMs/ and SRPMS/ subdirectories.
Labels:
rpm,
source rpm
Thursday, August 14, 2008
Changing Compile Options for a Source RPM
Continuing from May 21, 2008...
While most precompiled RPMs will serve your needs, at times you will want to modify the source code or compile options in the corresponding SRPMs. You can do so in the spec file that you get when you installed the source RPM. Let's looking at the directories and their purpose.
/usr/src/redhat/SOURCES - Contains the original program source code.
/usr/src/redhat/SPECS - Contains spec files, which control the RPM build process
/usr/src/redhat/BUILD - Source code is unpacked and built here
/usr/src/redhat/RPMS - Contains the output binary RPM
/usr/src/redhat/SRPMS - Contains the SRPM created by the build process
To change the compile options in an SRPM, you must understand spec files. The spec file is stored in /usr/src/redhat/SPECS/packagename.spec. The spec file controls the way a package is built and what actions are performed when it is installed or removed from a system. A spec file has 10 different sections (see the list below). Several of the sections include commands that can be run as individual shell scripts. You won't see all of these sections every spec file. For more information, see the RPM HOWTO at www.rpm.org.
%preamble - Includes informaton shown with an rpm -qi command. This normally includes a summary, version, and group. It also includes a list of dependent packages.
%description - A basic package description.
%pre - Adds a macro for preinstallation scripts.
%prep - Includes any preparatory commands required before building the source code, such as unpacking.
%build - Commands to compile the spec file and build sources.
%install - Commands to install the software on a system.
Install and uninstall scripts - Spec files usually contains cripts that will be run on the end user's system to insall or remove the software. RPM can execute a script before the package is installed, after the package is installed, before the package is removed, and after the package is removed.
%verify - Although RPM takes care of most verifictaion tasks, a script can be inserted here for any desired extra checks.
%clean - A script can be specified here to perform any necessary cleanup tasks.
%post - Adds a macro that cleans up after installation.
%preun - Scripts that prepare for uninstallation.
%postrun - Adds a macro that cleans up after installation.
%files - A list of files in the package.
%changelog - A list of revisions.
You can change the compile-time options for a package in the build section of the spec file. Here's a sample %clean section from a different spec file (this is not from the vsftpd RPM):
%build
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/usr/bin $RPM_BUILD_ROOT/etc
./configure --prefix=/usr/ --exec-prefix=/
make CFLAGS="$RPM_OPT_FLAGS" LDFLAGS=-s
This section, a shell script, begins with some housekeeping, removing any files that may be left over from a previous build. A directory structure is created for the source files. Then the package is configured and compiled with the make command.
For a different package, you might modify the make command line to compile other components after LDFLAGS. The compile options from $RPM_OPT_FLAGS are defaults, set by RPM. Alternatively, you could use this variable to set other compile-time options such as a different CPU.
Note: Perhaps the essential reference guide to the RPM system is Red Hat's book Maximum RPM. An older version is available online from Red Hat at www.redhat.com/docs/books/max-rpm.
While most precompiled RPMs will serve your needs, at times you will want to modify the source code or compile options in the corresponding SRPMs. You can do so in the spec file that you get when you installed the source RPM. Let's looking at the directories and their purpose.
/usr/src/redhat/SOURCES - Contains the original program source code.
/usr/src/redhat/SPECS - Contains spec files, which control the RPM build process
/usr/src/redhat/BUILD - Source code is unpacked and built here
/usr/src/redhat/RPMS - Contains the output binary RPM
/usr/src/redhat/SRPMS - Contains the SRPM created by the build process
To change the compile options in an SRPM, you must understand spec files. The spec file is stored in /usr/src/redhat/SPECS/packagename.spec. The spec file controls the way a package is built and what actions are performed when it is installed or removed from a system. A spec file has 10 different sections (see the list below). Several of the sections include commands that can be run as individual shell scripts. You won't see all of these sections every spec file. For more information, see the RPM HOWTO at www.rpm.org.
%preamble - Includes informaton shown with an rpm -qi command. This normally includes a summary, version, and group. It also includes a list of dependent packages.
%description - A basic package description.
%pre - Adds a macro for preinstallation scripts.
%prep - Includes any preparatory commands required before building the source code, such as unpacking.
%build - Commands to compile the spec file and build sources.
%install - Commands to install the software on a system.
Install and uninstall scripts - Spec files usually contains cripts that will be run on the end user's system to insall or remove the software. RPM can execute a script before the package is installed, after the package is installed, before the package is removed, and after the package is removed.
%verify - Although RPM takes care of most verifictaion tasks, a script can be inserted here for any desired extra checks.
%clean - A script can be specified here to perform any necessary cleanup tasks.
%post - Adds a macro that cleans up after installation.
%preun - Scripts that prepare for uninstallation.
%postrun - Adds a macro that cleans up after installation.
%files - A list of files in the package.
%changelog - A list of revisions.
You can change the compile-time options for a package in the build section of the spec file. Here's a sample %clean section from a different spec file (this is not from the vsftpd RPM):
%build
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/usr/bin $RPM_BUILD_ROOT/etc
./configure --prefix=/usr/ --exec-prefix=/
make CFLAGS="$RPM_OPT_FLAGS" LDFLAGS=-s
This section, a shell script, begins with some housekeeping, removing any files that may be left over from a previous build. A directory structure is created for the source files. Then the package is configured and compiled with the make command.
For a different package, you might modify the make command line to compile other components after LDFLAGS. The compile options from $RPM_OPT_FLAGS are defaults, set by RPM. Alternatively, you could use this variable to set other compile-time options such as a different CPU.
Note: Perhaps the essential reference guide to the RPM system is Red Hat's book Maximum RPM. An older version is available online from Red Hat at www.redhat.com/docs/books/max-rpm.
Labels:
rpm,
source rpm
Wednesday, August 13, 2008
Red Hat Enterprise Linux 5 Tech Notes
Hi
I'm sorry that I've been away. I've been working on a book, and needed some time to finish it.
The PDF can be downloaded for free (as in beer). You may also purchase a printed version from Lulu.com.
I'll be picking up the blog next week.
-HackingRHEL
I'm sorry that I've been away. I've been working on a book, and needed some time to finish it.
The PDF can be downloaded for free (as in beer). You may also purchase a printed version from Lulu.com.
I'll be picking up the blog next week.
-HackingRHEL
Subscribe to:
Posts (Atom)
