Tag Archive for 'build'

Building NVIDIA akmod package for RHEL/CentOS using Fedora and mock

Unfortunately there are no NVIDIA driver packages for RHEL/CentOS available on RPMFusion (that I could find), so this is how I built them. Disclaimer: This is just the way I did it and is probably dodgy. Suggestions welcome.

I have a dedicated build server and use mock so that all of the building is kept separate from my running system in a chroot environment. Packages are built against epel (Extra Packages for Enterprise Linux) and I’m using 64 bit.

We’re building an akmod package (rather than a static kmod) which will push the compilation of the driver on a per kernel basis to the client. The benefit of this is you only need to install the akmod once and the system will compile the kmod drivers after every kernel update.

Install Fedora
Install Fedora and then configure RPMFusion repositories (free, free-updates, non-free, non-free-updates).

Install mock and add yourself to the mock group (replace [username]). Log out and in or run newgrp:
$ sudo yum install mock
$ sudo gpasswd -a [username]
$ newgrp mock

Create a temporary location to perform the tasks below (makes copy and paste from here easier)
$ mkdir ~/building-nvidia
$ cd ~/building-nvidia

Source RPMS
Now we’re ready to get the source RPMs:
$ yumdownloader --source akmod-nvidia akmods buildsys-build-rpmfusion-kerneldevpkgs-current kmodtool libvdpau nvidia-kmod-common nvidia-settings nvidia-xconfig

Initialise mock
Let’s initialise the chroot environment for epel:
$ mock -r epel-6-x86_64 --init

Build and install dependencies
Ordinarily, building an RPM using mock will automatically install any build dependencies into the chroot. By default however it can (obviously) only automatically install any packages that are available in the target distribution. This presents a little problem with RHEL and CentOS because some of the dependencies (such as kmodtool and akmods) are not available in these distributions. So, how do we get around this? We can tell mock to install any RPM we like into the chroot, they don’t have to be available in the target distribution.

But it gets a little more tricky. If said dependency doesn’t exist for RHEL/CentOS, then we need to build it (using mock) and then install it into mock’s chroot manually. Make sense?

Once we have these dependencies manually installed the trick is telling mock not to clean the chroot environment for any post build processes, else it would remove those dependencies we manually installed (and therefore you couldn’t build the packages!).

Building kmodtool
The first dependency we need to build is kmodtool, because it does much of the grunt work for kmods (akmods requires this). Note we will add the “–no-clean” option when building packages, as we don’t want the packages we installed to be removed from the chroot (they’re dependencies).

Go for it:
$ mock -r epel-6-x86_64 --no-clean --no-cleanup-after --resultdir=/var/lib/mock/epel-6-x86_64/result/ --rebuild kmodtool*.src.rpm

Installing kmodtool
Install kmodtool into the chroot:
$ mock -r epel-6-x86_64 --install /var/lib/mock/epel-6-x86_64/result/kmodtool*.noarch.rpm

Building akmods
It gets slightly more tricky. The akmods package we are using is designed for Fedora and fails to build because it can’t detect the version of Fedora we are using and so tries to use systemd (Fedora’s boot system) which is not yet used in RHEL/CentOS. This means we need to install the akmod source rpm, modify the spec file and then re-create the source rpm for compilation (this will happen in your home directory).
$ rpm -ivh akmods*.src.rpm
$ sed -i 's/%fedora\ <=16/0%{?rhel}/g' ~/rpmbuild/SPECS/akmods.spec
$ rpmbuild -bs ~/rpmbuild/SPECS/akmods.spec
$ mock -r epel-6-x86_64 --no-clean --no-cleanup-after --rebuild --resultdir=/var/lib/mock/epel-6-x86_64/result/ ~/rpmbuild/SRPMS/akmods*.src.rpm

This will build akmods RPM and place it in mock's result dir which we will install next.

Installing akmods
Install akmods into the chroot:
$ mock -r epel-6-x86_64 --install /var/lib/mock/epel-6-x86_64/result/akmods*.noarch.rpm

Building buildsys-build-rpmfusion
The kmod package has some smarts to work out which kernel to build the kmod for. We need to build and install the buildsys-build-rpmfusion package which will give us an akmod compatible version of the package (actually it's a "provides"). This also requires kmodtool, hence we had to do this after the others:
$ mock -r epel-6-x86_64 --no-clean --no-cleanup-after --resultdir=/var/lib/mock/epel-6-x86_64/result/ --rebuild buildsys-build-rpmfusion*.src.rpm

Installing buildsys-build-rpmfusion
We only want to install the base package (not the 'current' package as that would require kernel-devel for your Fedora kernel).
$ rm /var/lib/mock/epel-6-x86_64/result/buildsys-build-rpmfusion-kerneldevpkgs-current*.x86_64.rpm
$ mock -r epel-6-x86_64 --install /var/lib/mock/epel-6-x86_64/result/buildsys-build*.x86_64.rpm

That's it for manual dependencies!

From now on, the packages we build will not be installed into the chroot, they will be copied and installed on the client machine.

Building nvidia-kmod package
The spec file for the nvidia-kmod package has a "buildforkernels" definition to tell it what kernel you want to build for, either current or latest kernel. Alternatively, it can build an akmod package (dynamically build package on boot), which is what we want. By default this option is set to "current" so we need to change this definition to "akmod" (hard-coded in the spec file).

To do this, we need to install the source RPM, change the option in its spec file, and rebuild the SRPM:
$ rpm -ivh nvidia-kmod*src.rpm
$ sed -i s/^%define\ buildforkernels\ current/%define\ buildforkernels\ akmod/ ~/rpmbuild/SPECS/nvidia-kmod.spec
$ rpmbuild -bs ~/rpmbuild/SPECS/nvidia-kmod.spec
$ mock -r epel-6-x86_64 --no-clean --rebuild ~/rpmbuild/SRPMS/nvidia-kmod*.src.rpm

If you don't want an akmod, then you need to specify the kernel that you're building for (this should install kernel-devel into the chroot). If you don't, you'll run into problems because the chroot will detect your Fedora kernel, not the kernel you need to build for. Note this is a different definition we are specifying (replace with the kernel version you want):
$ mock -r epel-6-x86_64 --define "kernels 2.6.32-220.17.1.el6.x86_64" --no-clean --rebuild nvidia-kmod*.src.rpm

Building remaining packages
Now build the rest of the packages:
$ mock -r epel-6-x86_64 --no-clean --rebuild \
libvdpau*.src.rpm nvidia-settings*.src.rpm \
nvidia-xconfig*.src.rpm xorg-x11-drv-nvidia*.src.rpm

Copy built packages
All of the build packages will be under mock's result directory, so we can now copy these out and install them on a RHEL/CentOS box!
$ mkdir {packages,source}
$ cp -r /var/lib/mock/epel-6-x86_64/result/*{noarch,x86_64}.rpm packages/
$ cp -r /var/lib/mock/epel-6-x86_64/result/*src.rpm source/

Now these can be published to a repository and pushed out to machines.

Install akmod-nvidia package
All you need to do is install the nvidia akmod package:
$ sudo yum install akmod-nvidia

This should automatically pull in all dependencies required to build the package, like kernel-devel, gcc, make, etc.

Finally, make sure that akmods is set to start on boot:
$ sudo chkconfig akmods on

Now each time a kernel update is released, the machine will automatically build the nvidia driver for you.

On becoming a Fedora maintainer

Recently, Rahul Sandaram (Fedora dev and creator of the Omega Fedora Remix) offered to sponsor me to become a Fedora maintainer, which I accepted. A day or so later I pushed my first updates into Fedora for deja-dup – the package I now co-maintain while I learn the ropes.

Previously, one would become a maintainer by first submitting a new package and thereby overtime demonstrating an understanding of the Fedora packaging process and guidelines. However recently a new system was approved whereby one could become a co-maintainer of an existing package, instead. This requires being sponsored by an existing maintainer, which Rahul was for me.

It’s quite a big task, but Rahul was very helpful and patient while I learned about the process. There is a lot of information on the Fedora Wiki but I found there wasn’t really a single place which provided a nice overview, broke down each section in detail, and then explained all the steps required. So that (along with my cautious nature) meant it took a dozen or so clarifying emails back and forth between Rahul and myself.

When I got my first understanding and taste of the system though, I’ve gotta say, I was quite impressed. The scale of the system and architecture and how it all works is amazing. The build files (RPM spec files) of all the packages in Fedora are kept under their own git repository. Hooks into this git system and special build tools manage the whole process. All in all, this automation makes it quite seamless.

So after reading and doing everything Rahul sent to me, I started on my journey.

There are two development systems to update now – rawhide (development tree) and F15 (the upcoming version). I wanted to update both of these to the latest upstream version, 17.90. I also wanted to update the stable Fedora 14 package to an upstream bug-fix release, version 16.1.1.

Cloning deja-dup from the git repo put me in the rawhide branch by default. I updated the spec file – increasing the version, adding python-cloudfiles as a new dependency, and putting in a detailed changelog. I then committed that to my local git repo with a comment linking to upstream. I then pulled those changes from rawhide into the f15 branch and updated f14.

commit bb1a5daa9feea74640fd84a0174e74e4e83ad34b
Author: Christopher Smart
Date: Sat Mar 5 21:23:07 2011 +1100
    
     Updated to upstream bugfix version 16.1.1.
     "This release fixes a bug in the just-released 16.1 that caused help
     documentation to not be translated."
     https://launchpad.net/deja-dup/+announcement/7239

Next I needed to test these packages, so I built a source RPM from the spec for each version. I discovered that one can either do a mock build on their local machine, or use Koji to do a scratch build on Fedora’s online build system. I did both, which worked well.

Using Koji meant I needed to first push my changes back to Fedora first though (or so I thought), so I was hesitant to do it without first checking with Rahul. This was the sort of thing that was emailed back and forth – I didn’t fully understand the system and didn’t want to break anything! For example, in order to test my F14 update I had to push back to the git repo – but what if I made a mistake in the process? Would my build on Koji push this broken package onto everyone’s system?

Fortunately, no. Once all the updating of the spec file and building is complete, the maintainer has to formally submit it into the update process before anything will happen. In addition, each package must then pass approval by other maintainers before it is approved and pushed out. You can see why it took some back and forth between Rahul and myself – I wanted to be sure I wasn’t going to do some damage :-)

Along the way I discovered new automated ways of doing things, such as validating a spec file, automatically downloading the source tarball to update the spec file, then uploading it to the Fedora build system.

In the end though, I think that I have a pretty good grasp of the overall process and am quite excited by the prospect of becoming a Fedora maintainer. I’m hoping that deja-dup comes out with a new update soon, so that I can do another update!

I’m still a little hesitant to go and change things – I don’t want to do the wrong thing or step on anyone’s toes. I did however create my own page on the Fedora Wiki, complete with a hackergotchi, of course.

So once again, thanks to Rahul for his patience and guidance :-)