0% found this document useful (0 votes)
31 views

RPM Build Steps

This document provides instructions for creating an RPM package to configure a local YUM/DNF repository in RHEL 8 using an ISO image mounted at the /mnt directory. It describes using rpmdevtools to set up the rpmbuild directory structure, creating a source tarball with the YUM repository configuration file, writing a spec file to define the package, building the RPM, and installing it to configure the local repository.

Uploaded by

amit_post2000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

RPM Build Steps

This document provides instructions for creating an RPM package to configure a local YUM/DNF repository in RHEL 8 using an ISO image mounted at the /mnt directory. It describes using rpmdevtools to set up the rpmbuild directory structure, creating a source tarball with the YUM repository configuration file, writing a spec file to define the package, building the RPM, and installing it to configure the local repository.

Uploaded by

amit_post2000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Create/Build RPM Package in Linux From Source Code

$ tree rpmbuild/
rpmbuild/
├── BUILD
├── RPMS
├── SOURCES
├── SPECS
└── SRPMS

Here’s a short description of each of the directories:

BUILD - this is the folder where all of the files go which are created during a build
of the package you want to create

RPMS / SRPMS - If your build is successful this is the folder there the final rpm
file will be created. The SRPMS folder only contains source rpm.

SOURCES - This is the folder where you want to put the source tar file or/and
additional files such as init.d/systemd files.

SPECS - The SPECS folder is where your spec-file is located. A spec file is basically
a set of instructions on how to build the rpm package. I will explain the layout of
the spec-file in detail.

-------------
THE SPECFILE:
If there was one thing that you should know about creating a rpm it’s how to
write the spec file. As I wrote earlier a spec file consists of instructions on how
to package the software into an rpm and how it should be installed on the OS.
Not only that but also information about the package/software such as version
and licence.

Name, Version, Release - Should be pretty straight forward. Name the package,
it’s version and it’s release (dist is a macro that will translate to the red-hat
flavour dist you build on).

Summary, %description- Easy stuff as well. Summary should be one sentence


describing the software while %description should be longer and more
descriptive.

Group, Licence, URL, Source0 - Same here, this is also pretty basic stuff. Group
is used to categorize the package. If unsure take a look at /usr/share/doc/rpm-
4.8.0/GROUPS to see the full list of available groups. Next we have licence which
should be included, if for example you are packaging Elasticsearch you should
write that corresponding licence in your spec-file. Source0 is important, here
you write the name of the source tar file in the SOURCES directory. You can write
multiply Source in the specfile like this; Source0, Source1, Source2 and so on.
You would do this if you want to point to a startscript, logrotate or libs that you
don’t want to inclide in the source tar file.

BuildRequires, Requires - BuildRequires is the category you need to list the


packages that the software you are packaging requires at build time, whereas
Requires is what your rpm requires at runtime. For example, if we’re packaging
tomcat we need to list java as a requirement for the runtime, but we dont need
any special BuildRequires as tomcat does not need to be compiled.
%files - %files is an important field because here we specify every folder or file(-
s) we will install on the computer. The %defaultattr macro sets the permission
of the file(-s), in this case root. Use %doc to highligh which files are READMEs.

You might noticed we didn’t cover the %prep and %setup definitions. We will
cover them shortly but first let’s talk about macros.

$RPM_BUILD_ROOT (or the equivalent %{buildroot} SPEC file macro) always


holds the directory under which RPM will look for any files to package.

-------------

Creating RPM To Configure Local YUM/DNF Repository in RHEL 8 Using ISO


Image Mounted at /mnt Direcotry:

Follow below steps/commands to create the RPM package.


# yum repolist all
# yum install -y rpmdevtools rpm-build
# mv /etc/yum.repos.d/local.repo /tmp
# ls /etc/yum.repos.d/local.repo
# yum repolist all
# su - vikasnehra
$ rpmdev-setuptree
$ ls -l
$ tree rpmbuild
$ cd rpmbuild/SOURCES
$ ls
$ mkdir -p localrepo-1/etc/yum.repos.d/
$ ls
$ vim localrepo-1/etc/yum.repos.d/RHEL8local.repo
[InstallMedia-BaseOS]
name=Red Hat Enterprise Linux 8 - BaseOS
metadata_expire=-1
gpgcheck=1
enabled=1
baseurl=file:///mnt/BaseOS/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[InstallMedia-AppStream]
name=Red Hat Enterprise Linux 8 - AppStream
metadata_expire=-1
gpgcheck=1
enabled=1
baseurl=file:///mnt/AppStream/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

----------

$ tar -cvzf localrepo-1.tar.gz localrepo-1/


$ cd ../SPECS/
$ ls
$ rpmdev-newspec localrepo.spec
$ ls
$ vim localrepo.spec
Name: localrepo
Version: 1
Release: 0
Summary: Local Repo For RHEL 8

Group: System Environment/Base


License: GPL
URL: https://www.youtube.com/NehraClasses
Source0: localrepo-1.tar.gz
BuildArch: noarch
BuildRoot: %{_tmppath}/%{name}-buildroot

%description
Create a local yum repo file in /etc/yum.repos.d/ directory.

%prep
%setup -q

%install
mkdir -p "$RPM_BUILD_ROOT"
cp -R * "$RPM_BUILD_ROOT"
%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root,-)
/etc/yum.repos.d/RHEL8local.repo

%changelog
* Fri Feb 25 2022 Vikas Nehra
-

-------------

$ cd
$ rpmbuild -v -bb rpmbuild/SPEC/localrepo.spec
$ rpm -qpl rpmbuild/RPMS/noarch/localrepo-1-0.noarch.rpm
$ exit
# rpm -ivh /home/vikasnehra/rpmbuild/RPMS/noarch/localrepo-1-
0.noarch.rpm
# rpm -qa | grep localrepo
# ls /etc/yum.repos.d/
# yum repolist all
# cat /etc/yum.repos.d/RHEL8local.repo
# mount /dev/sr0 /mnt
# yum install -y httpd vsftpd ftp samba

-------------
tree rpmbuild/
rpmbuild/
├── BUILD
│ └── localrepo-1
│ └── etc
│ └── yum.repos.d
│ └── RHEL8local.repo
├── BUILDROOT
├── RPMS
│ └── noarch
│ └── localrepo-1-0.noarch.rpm
├── SOURCES
│ ├── localrepo-1
│ │ └── etc
│ │ └── yum.repos.d
│ │ └── RHEL8local.repo
│ └── localrepo-1.tar.gz
├── SPECS
│ └── localrepo.spec
└── SRPMS

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy