We help IT Professionals succeed at work.

How to create binary RPM file for my own drivers installation on CentOS 5.5?

Hello,

I'm trying to create RPM that will contains binary drivers for my own hardware.
I would like not to use root account for that.

1. I created the directories:
mkdir -p ~/rpm/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
2. I put .tar.gz file that containing my binary driver (drv.ko) to SOURCES folder.
3. I need to put driver to the /lib/modules/<krnel_version>/kernel/drivers folder.

What I need to write into the %files section of SPEC file? I don't know what the <krnel_version> will be used on target machine.

Need I compress my drv.ko file by tar.gz or just put drv.ko to the SOURCES directory?
Comment
Watch Question

Commented:
The files section contains the exact location of an item. But since you don't know what the kernel version on your target machines is, should you not rather building out-of-tree kernel modules on target systems using DKMS instead?

I'll throw in  sample .spec file (for fixed kernel version) just in case:

8<-------------------------------------------
# Don't exit rpmbuild if files are in $RPM_BUILD_ROOT but not listed in spec:
%define _unpackaged_files_terminate_build 0
# Don't exit rpmbuild on missing documentation files:
%define _missing_doc_files_terminate_build 0
# Don't strip:
%define __os_install_post    \
    /usr/lib/rpm/brp-compress \
%{nil}
# No debuginfo:
%define debug_packages      %{nil}
%define debug_package %{nil}
# Disable automatic dependencies tracking (almost never necessary):
AutoReqProv: no
#
%define name drivername
# Version
%define ver 1.2.3
# Release
%define rel 1
#
Name: %{name}
Summary: %{name}, a kernel driver
Version: %{ver}
Release: %{rel}
License: GPL
Group: System Environment/Kernel
Source0: %{name}.tar.gz
Prereq: kernel = 2.6.18-194.3.1.el5
Provides: %{name}
BuildRoot: %{_tmppath}/%{name}-%{version}
%description
Package containing the %{name} kernel driver.

%setup -n %{name}

%install
 rm -rf $RPM_BUILD_ROOT
 install -d $RPM_BUILD_ROOT/lib/modules/2.6.18-194.3.1.el5/extra/
 install ${RPM_SOURCE_DIR}/driver.ko $RPM_BUILD_ROOT/lib/modules/2.6.18-194.3.1.el5/extra/driver.ko
                                    
%clean
 rm -rf "${RPM_BUILD_ROOT}"

%post
if [ "$1" = "1" ]; then
      /sbin/depmod -ae
fi

%files
%defattr(-,root,root)
%attr(644,root,root) /lib/modules/2.6.18-194.3.1.el5/extra/driver.ko

%changelog
* Dayname Month Day Year %{packager} - release %{release}
- Freeform changelog, fixed format date line. Newest entries on top.
------------------------------------------->8

Author

Commented:
unSpawn: Thank you for the comment!

That the directories tree structure of the %{name}.tar.gz file? The driver.ko should have any path into .tar.gz?

In the %install section of the SPEC I see that rm -rf $RPM_BUILD_ROOT command coming before install command. Is it OK? What the first command that will be executed into %install section: "rm -rf $RPM_BUILD_ROOT" or "install ${RPM_SOURCE_DIR}/driver.ko $RPM_BUILD_ROOT/lib/modules/2.6.18-194.3.1.el5/extra/driver.ko" ???
Commented:
>That the directories tree structure of the %{name}.tar.gz file?
No, the "$RPM_BUILD_ROOT/lib/modules/2.6.18-194.3.1.el5/extra/" line is just an example how you would buil the *installation tree* before packaging things up as shown in the %files section (needs to match).

>The driver.ko should have any path into .tar.gz?
Yes, as long as you use the right "install" command.

>In the %install section of the SPEC I see that rm -rf $RPM_BUILD_ROOT command coming before install command. Is it OK?
Yes because you want to clean out the installation path between runs.


* For a quick introduction to building RPM packages see http://www.ibm.com/developerworks/linux/library/l-rpm1/ and http://www.rpm.org/max-rpm/ and http://fedoraproject.org/wiki/PackageMaintainers/CreatingPackageHowTo for more details.