Tag Archive for 'kmod'

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.

Recovering from 3rd party drivers, with Jockey

What happens if you enable a 3rd party driver (like ATI) with Jockey, but after a reboot your graphics is broken and you can’t log in to revert?

Answer: Use the command line version of Jockey!

Here’s how you can revert any installed 3rd party driver using Jockey from the command line:

  • At log in (perhaps with a broken X screen), switch to another terminal using the key combination:
  • Ctrl + Alt + F2

  • Log in as root
  • Get a list of enabled drivers from Jockey:
  • jockey --list

  • Disable the driver (such as the ATI driver):
  • jockey --disable=kmod:fglrx

  • Once it has finished, reboot!

When using Jockey, you should ensure that you have the latest updates applied, in particular the latest running kernel. This is because you might otherwise get a driver for a newer kernel, which might break your system upon reboot, or fail to activate.

You can also try using akmods with Jockey, which will build a new driver for you on reboot, if one does not exist for your running kernel (no matter what that is!).

-c

Using akmods with Jockey in Fedora

By default, 3rd party drivers (such as NVIDIA and ATI) are pre-compiled against a specific kernel version and delivered in a kmod package. However when there’s a kernel update, it might block because there is no updated driver package yet available. This can also break a system if you update the kernel and reboot.

Wouldn’t it be great if the system could automatically build a new driver if required? Yes, and this is where akmods come into play.

With akmods, when your system boots it will check to see if a registered driver needs to be built. If you have an updated kernel, then akmods will build a fresh driver for that kernel and install it – no need to wait for a kmod to be updated upstream. This avoids the broken system scenario above.

While akmods are nothing new, you can now use them with Jockey under Fedora 16 (rather than just kmod packages). Simply download the RPMS from a Kororaa mirror and install (or you could build your own from SRPM).

You will need:

  • jockey
  • jockey-selinux
  • jockey-modaliases
  • jockey-gtk or jockey-kde

Post install, edit the /etc/jockey.conf and set “akmods=true”. Then, you can run Jockey and install the driver you want.

Jockey driver manager

You will also need build tools like gcc, make and kernel-headers (and of course, akmods), however these should be pulled in as dependencies of the akmod package.

This is still an experimental feature and any feedback is welcome!