Building Package or Kernel Modules Using a Script
You can use a script to build a single Photon OS package without the need to setup a complete Photon build workspace. You just need a .spec
specification file and the source files. You can place the source files and the specification files in the same folder, or provide a URL for the source file location, and then run the build_spec.sh
script.
The script performs the following steps:
- Creates sandbox using docker
- Installs build tools and
.spec
build requirements from the Photon OS repository - Runs
rpmbuild
Result: You have a native Photon OS RPM package.
The build-spec.sh
script is located in the photon/tools/scripts/
folder.
Prerequisites
Before you run the build-spec.sh
script, perform the following steps:
- Ensure you have any Linux OS with a docker daemon running.
- Place the source and RPM
.spec
files in the same folder or provide a URL for the source files.
Procedure
Run the script. Provide the RPM .spec
file name, including absolute or relative path, as an argument:
./photon/tools/scripts/build_spec.sh <path-to-rpm_spec_file.spec> [$STAGEDIR]
You can specify the staging directory ($STAGEDIR
) where you want to store the generated RPM files and build logs. If you do not specify a staging directory, the generated output files are stored in the directory that contains the spec file.
The following topics show examples to build packages based on various use cases.
1 - Hello World Kernel Module
This example shows how to build a package that provides a hello world kernel module. To build the package, you need to run the script with hello-world.spec
as an argument, where hello-world.spec
is the RPM specification file.
You can find the source file at the following location:
https://github.com/vmware/photon/tree/<BRANCH>/tools/examples/build_spec/kernel_module_example/hello-world.tar.gz
To generate the output in the spec-file folder, run the following command:
./photon/tools/scripts/build_spec.sh ./photon/tools/examples/build_spec/kernel_module_example/hello-world.spec
The following are the contents of the hello-world.spec
file:
%define linux_esx_ver 6.1.10
Summary: Hello World Linux module
Name: hello-world
Version: 1.0
Release: 1%{?dist}
License: GPLv2
Group: System Environment/Kernel
Vendor: VMware, Inc.
Distribution: Photon
Source0: hello-world.tar.gz
BuildRequires: linux-esx-devel = %{linux_esx_ver}
BuildRequires: kmod
Requires: linux-esx = %{linux_esx_ver}
%description
Example of building linux module for Photon OS
%prep
%autosetup -n hello-world
%build
make -C `echo /usr/src/linux-headers-%{linux_esx_ver}*` M=`pwd` VERBOSE=1 modules %{?_smp_mflags}
%install
make -C `echo /usr/src/linux-headers-%{linux_esx_ver}*` M=`pwd` INSTALL_MOD_PATH=%{buildroot} modules_install %{?_smp_mflags}
# fix permissins to generate non empty debuginfo
find %{buildroot}/lib/modules -name '*.ko' -print0 | xargs -0 chmod u+x
%ldconfig_scriptlets
%post
/sbin/depmod -a
%files
%defattr(-,root,root)
/lib/modules/*
Build Logs
The following logs indicate the steps that the script performs internally:
0. Build Script Version: 1.1
1. Create sandbox
Use local build template image OK
2. Prepare build environment
Create source folder OK
Copy sources from ./photon/tools/examples/build_spec/kernel_module_example OK
install createrepo OK
createrepo OK
Create local repo in sandbox OK
makecache OK
3. Build Binary and Source Package
Run rpmbuild OK
Delete SOURCES OK
4. Destroy sandbox
Stop container OK
Remove container OK
Build completed. RPMS are in './photon/tools/examples/build_spec/kernel_module_example/stage' folder
Verification
You can verify the generated output with the following commands:
- Command to install the RPM:
rpm -ivh ./photon/tools/examples/build_spec/kernel_module_example/stage/RPMS/x86_64/hello-world-1.0-1.ph5.x86_64.rpm
- Command to install the kernel module:
modprobe hello-world
- Command to verify the installed kernel module:
dmesg | grep "Hello World"
2 - Hello World Binary
This example shows how to build a package that provides a hello world binary. To build the package, you need to run the script with hello-world-user1.spec
as an argument, where hello-world-user1.spec
is the RPM specification file.
You can find the source file at the following location:
https://github.com/vmware/photon/tree/<BRANCH>/tools/examples/build_spec/user_package_example/hello-world-user1.tar.gz
To generate the output in a staging directory, run the following command:
./photon/tools/scripts/build_spec.sh ./photon/tools/examples/build_spec/user_package_example/hello-world-user1.spec $STAGEDIR
The following are the contents of the hello-world-user1.spec
file:
% Summary: Hello World User Package
Name: hello-world-user1
Version: 1.0
Release: 1%{?dist}
License: GPLv2
Group: System Environment/Kernel
Vendor: VMware, Inc.
Distribution: Photon
Source0: hello-world-user1.tar.gz
%description
Example of building User Package for Photon OS
%prep
%autosetup -n hello-world-user1
%build
make %{?_smp_mflags}
%install
make %{?_smp_mflags} install DESTDIR=%{buildroot}
%ldconfig_scriptlets
%files
%defattr(-,root,root)
/usr/bin/*
Build Logs
The following logs indicate the steps that the script performs internally:
0. Build Script Version: 1.1
1. Create sandbox
Use local build template image OK
2. Prepare build environment
Create source folder OK
Copy sources from ./photon/tools/examples/build_spec/user_package_example OK
install createrepo OK
createrepo OK
Create local repo in sandbox OK
makecache OK
Install build requirements OK
3. Build Binary and Source Package
Run rpmbuild OK
Delete SOURCES OK
4. Destroy sandbox
Stop container OK
Remove container OK
Build completed. RPMS are in '$STAGEDIR' folder
Verification
You can verify the generated output with the following commands:
- Command to install the RPM:
rpm -ivh $STAGEDIR/RPMS/x86_64/hello-world-user-1.0-1.ph5.x86_64.rpm
- Command to verify the installed user package (execute the installed binary of the user package):
root@photon-aab77099dca0root [ ~ ]# /usr/bin/hello-world-user
Hello World
3 - Manage a Dependent package
This example shows how to build a dependent package. To build the package, you need to run the script with hello-world-user.spec
as an argument, where hello-world-user.spec
depends on the RPM build from hello-world-user1.spec
(hello-world-user -> hello-world-user1
)
You can find the source file at the following location:
https://github.com/vmware/photon/tree/<BRANCH>/tools/examples/build_spec/user_package_example/hello-world-user.tar.gz
To generate the output in a staging directory, run the following command:
./photon/tools/scripts/build_spec.sh ./photon/tools/examples/build_spec/user_package_example/hello-world-user.spec $STAGEDIR
The following are the contents of the hello-world-user.spec
file:
Summary: Hello World User Package
Name: hello-world-user
Version: 1.0
Release: 1%{?dist}
License: GPLv2
Group: System Environment/Kernel
Vendor: VMware, Inc.
Distribution: Photon
Source0: hello-world-user.tar.gz
BuildRequires: hello-world-user1
BuildRequires: git
Requires: hello-world-user1
%description
Example of building User Package for Photon OS
%prep
%autosetup -n hello-world-user
%build
make %{?_smp_mflags}
%install
pwd
make %{?_smp_mflags} install DESTDIR=%{buildroot}
%ldconfig_scriptlets
%files
%defattr(-,root,root)
/usr/bin/*
Build Logs
The following logs indicate the steps that the script performs internally:
0. Build Script Version: 1.1
1. Create sandbox
Use local build template image OK
2. Prepare build environment
Create source folder OK
Copy sources from ./photon/tools/examples/build_spec/user_package_example OK
install createrepo OK
createrepo OK
Create local repo in sandbox OK
makecache OK
Install build requirements OK
3. Build Binary and Source Package
Run rpmbuild OK
Delete SOURCES OK
4. Destroy sandbox
Stop container OK
Remove container OK
Build completed. RPMS are in '$STAGEDIR' folder.
4 - Include a patch file
This example shows how to build a package with a patch file. To build the package, you need to run the script with python-M2Crypto.spec
as an argument, where python-M2Crypto.spec
is the RPM specification file.
You can find the patch file at the following location:
https://github.com/vmware/photon/tree/<BRANCH>/tools/examples/build_spec/user_package_example/0001-openssl-3.0.0-support.patch
To generate the output in the spec-file folder, run the following command:
./photon/tools/scripts/build_spec.sh ./photon/tools/examples/build_spec/user_package_example/python-M2Crypto.spec
The following are the contents of the python-M2Crypto.spec
file:
Name: python3-M2Crypto
Version: 0.36.0
Release: 1%{?dist}
Summary: Crypto and SSL toolkit for Python
Group: Development/Languages/Python
License: MIT
URL: https://pypi.python.org/pypi/M2Crypto/0.26.0
Source0: https://pypi.python.org/packages/11/29/0b075f51c38df4649a24ecff9ead1ffc57b164710821048e3d997f1363b9/M2Crypto-%{version}.tar.gz
Vendor: VMware, Inc.
Distribution: Photon
BuildRequires: openssl
BuildRequires: openssl-devel
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: python3-typing
BuildRequires: swig
BuildRequires: python3-xml
Requires: python3-typing
Requires: python3
Requires: openssl
Patch0: 0001-openssl-3.0.0-support.patch
%description
M2Crypto is a crypto and SSL toolkit for Python featuring the following:
RSA, DSA, DH, HMACs, message digests, symmetric ciphers (including
AES). SSL functionality to implement clients and servers. HTTPS
extensions to Python's httplib, urllib, and xmlrpclib. Unforgeable
HMAC'ing AuthCookies for web session management. FTP/TLS client and
server. S/MIME. ZServerSSL: A HTTPS server for Zope. ZSmime: An S/MIME
messenger for Zope.
%prep
# Using autosetup is not feasible
%setup -q -n M2Crypto-%{version}
%patch0 -p1
%build
CFLAGS="%{optflags}" python3 setup.py build --openssl=/usr/include --bundledlls
%install
rm -rf %{buildroot}
python3 setup.py install --prefix=%{_prefix} --root=%{buildroot}
%files
%defattr(-,root,root)
%{python3_sitelib}/*
Build Logs
The following logs indicate the steps that the script performs internally:
0. Build Script Version: 1.1
1. Create sandbox
Use local build template image OK
2. Prepare build environment
Create source folder OK
Copy sources from ./photon/tools/examples/build_spec/user_package_example OK
Download M2Crypto-0.36.0.tar.gz OK
install createrepo OK
createrepo OK
Create local repo in sandbox OK
makecache OK
Install build requirements OK
3. Build Binary and Source Package
Run rpmbuild OK
Delete SOURCES OK
4. Destroy sandbox
Stop container OK
Remove container OK
Build completed. RPMS are in './photon/tools/examples/build_spec/user_package_example/stage' folder
5 - Refer an External Source
This example shows how to build a package that downloads the source files from an external website like GitHub. To build the package, you need to run the script with libdrm.spec
as an argument, where libdrm.spec
is the RPM specification file.
./photon/tools/scripts/build_spec.sh ./photon/tools/examples/build_spec/user_package_example/libdrm.spec
The following are the contents of the libdrm.spec
file:
Summary: user space library for accessing the DRM.
Name: libdrm
Version: 2.4.110
Release: 1%{?dist}
License: MIT
URL: http://dri.freedesktop.org/
Group: System Environment/Libraries
Vendor: VMware, Inc.
Distribution: Photon
Source0: https://dri.freedesktop.org/libdrm/%{name}-%{version}.tar.xz
BuildRequires: meson
BuildRequires: libpciaccess-devel
Requires: libpciaccess
Provides: pkgconfig(libdrm)
%description
libdrm provides a user space library for accessing the DRM, direct rendering manager, on operating systems that support the ioctl interface. libdrm is a low-level library, typically used by graphics drivers such as the Mesa DRI drivers, the X drivers, libva and similar projects.
%package devel
Summary: Header and development files
Requires: %{name} = %{version}-%{release}
%description devel
libdrm provides a user space library for accessing the DRM, direct rendering manager, on operating systems that support the ioctl interface. libdrm is a low-level library, typically used by graphics drivers such as the Mesa DRI drivers, the X drivers, libva and similar projects.
%prep
%autosetup -p1
%build
CONFIGURE_OPTS=(
-Dintel=false
-Dradeon=false
-Damdgpu=true
-Dnouveau=false
-Dvmwgfx=false
-Dlibkms=false
)
%meson "${CONFIGURE_OPTS[@]}"
meson --prefix=%{_prefix} build
%install
DESTDIR=%{buildroot}/ ninja -C build install
%ldconfig_scriptlets
%files
%defattr(-,root,root)
%{_libdir}/lib*
%{_datadir}/libdrm/*
%files devel
%defattr(-,root,root)
%{_includedir}/*
%{_libdir}/pkgconfig*
Build Logs
The following logs indicate the steps that the script performs internally:
0. Build Script Version: 1.1
1. Create sandbox
Use local build template image OK
2. Prepare build environment
Create source folder OK
Copy sources from ./photon/tools/examples/build_spec/user_package_example OK
Download libdrm-2.4.110.tar.xz OK
install createrepo OK
createrepo OK
Create local repo in sandbox OK
makecache OK
Install build requirements OK
3. Build Binary and Source Package
Run rpmbuild OK
Delete SOURCES OK
4. Destroy sandbox
Stop container OK
Remove container OK
Build completed. RPMS are in './photon/tools/examples/build_spec/user_package_example/stage' folder