Deployment Solution

 View Only

How to Compile Linux Drivers in DS 6.8 SP2 

Aug 09, 2007 11:42 AM

This How To explains how to compile drivers for Linux automation and add them to your Linux image. Compiling drivers for Linux automation can be a daunting task, but once your environment is set up and you've done it a few times, it becomes quite easy.

To complete this How To, you will need access to a computer running Linux (most any distro will work; these steps were written using Ubuntu 7.04). You will also need to access a Deployment Solution server, and be able to boot a computer into automation. It is presumed you have a basic understanding of Linux and Deployment Solution. Deployment Solution 6.8 SP2, along with Linux kernel version 2.6.18.8, were used in the creation of this document.

Preparing Your Linux Computer

First, you will need to setup your Linux computer to compile drivers for Linux automation. This involves installing the correct compiler, downloading the kernel source code, adding the configuration information from your Linux automation image, and compiling the source code. You should only have to do this part once, after you have everything set up you can skip to the compiling drivers section.

  1. Verify the Linux kernel version your are using for automation. You can do this using Boot Disk Creator. From the DS Console click Tools > Boot Disk Creator. From Boot Disk Creator click Tools > Installed Pre-boot Operating Systems. In the box labeled Linux, the version number will be the kernel version you are using. Make sure you get the kernel version for the architecture you are using (that is, x86, x64, or IA64). In Deployment Solution 6.8 SP2 the version number should be 2.6.18.8 for all architectures.
  2. Now go to http://www.kernel.org/pub/linux/kernel/v2.6/. Scroll down to the ZIP file that corresponds to the kernel version you are using, it should be linux-2.6.18.8.tar.gz. Make sure you get the correct file—do not get one of the patch or changelog files.
  3. Copy the file to your Linux computer (if it isn't there already) and extract it to a permanent location. In this article we'll use /usr/src, the location doesn't really matter so you can change it to suit your preferences. Copy the file to /usr/src (or the place of your choosing) then type "tar xfz linux-2.6.18.8.tar.gz". You may need root access to use that directory, so if you don't have root access then you can put the files somewhere else (in your home directory, for example).
  4. Now you need to verify the version of gcc you have. You can do this by typing gcc --version from the command prompt. You need to make sure you have version 4.1.x. Many Linux distros come with 4.0, so if you have one of these you'll need to get 4.1 as well. You will need root access in order to install another version of gcc. Many package managers can get gcc for you and install all the dependencies. Ubuntu and other Debian distros use apt-get, SUSE uses yast, and RedHat and Fedora use yum. A simple Internet search will guide you in the right direction as to what package you need to install. For Ubuntu the command is "apt-get install gcc-4.1" You will also want to get g++ while you're at it. (Ubuntu command: "apt-get install g++-4.1"):
  5. Now that gcc 4.1 is installed you need to make sure it is the default compiler. The easiest way to do this is to use symlinks. The gcc binary itself should be in /usr/bin. In Ubuntu when gcc is installed the binary is named gcc-X.Y, where X.Y is the version number. In our example we only have gcc-4.1 in our /usr/bin directory. We want to create a symlink so when we run gcc we get the 4.1 version. From the /usr/bin directory use the following command to do this: "ln -sf gcc-4.1 gcc". If you already have a binary named gcc, this command won't work. You may have to rename the existing binary (you can name it after the version number, so if it is version 4.0, name it gcc-4.0) then create the symlink. Once all of this is done, verify you have the correct compiler by typing gcc --version. If it still isn't version 4.1 go through this step again.
  6. Now you need to boot a computer into Linux automation and copy the config file from it. You will need this so any drivers you compile are compiled with the same kernel options that the automation kernel has been compiled with. Create a simple Run Script task in DS with the following command:
    cp /proc/config.gz /mnt/ds"
    
    
    The file config.gz will now be in at the root of your deployment share on your Deployment Solution server. Copy it to your Linux computer.
  7. With the config.gz file on your Linux computer, copy it into the directory where your kernel source files are located. So if you copied your kernel source to /usr/src, then you would copy the config.gz file to /usr/src/linux-2.6.18.8. Now change to that directory and unzip the file with the following command: "gzip -d config.gz". You should now have a file named confg. Rename it to .config (notice the period in front of config) with the command "mv config .config". If you do an ls, you'll notice that the config file has disappeared. In Linux, files with a period (.) prefix are hidden files, so they won't show up when you do an ls. If you really want to make sure it is there use "ls -a", and it will show up.
  8. Now you need to build the kernel; change to the directory you created the kernel in (in this example you would change to /usr/src/linux-2.6.18.8). Type one of the following commands (depending on your architecture):
    • "make bzImage modules" (x86 and x64)
    • "make compressed modules" (IA64)
    This will take awhile, depending on the speed of your computer.

Compiling the Driver

Now everything should be set up and ready to go, from here on out you can skip the preparation steps and just compile drivers anytime you like. For this example, we will compile a driver called bnx2, located in the /usr/src/drivers/bnx2 folder. To actually compile drivers do the following:

  1. Copy the driver source files to a location of your choice. We'll use /usr/src/drivers, but you can choose whatever location is preferable to you.
  2. Change to the directory containing the driver source files; this is usually a directory with .c, and .h files in it.
  3. To make the drivers, type "make -C /path/to/kernel/source SUBDIRS=$PWD modules". Where /path/to/kernel/source is the path to the kernel source you downloaded in the preparation steps. So in this example, you would type: "make -C /usr/src/linux-2.6.18.8 SUBDIRS=$PWD modules"
  4. Now copy the .ko files that were generated from the compilation process. These are the driver files you need to use.
Note: The compilation process may fail with errors. If you are sure you did everything correctly then it is possible the driver source code is not compatible with the kernel version you are using. In this case you will have to find a different version of the driver source code. It is not uncommon for a variable declaration or function call that the driver expects the kernel to provide to be missing in later kernel releases. Linux kernels are released very frequently and anything is fair game for changing each time. For a particular driver that was needed once, 20 different versions were gone through before the one was found that worked. Even when a driver compiles that doesn't mean it will load properly, it may still complain about missing variables/function calls when it is loaded. That is the joy of working in Linux—you just have to keep trying. The advantage is someone else has probably had your same problem, and you can find how to fix it using the Internet.
Note: If the compilation succeeds, but has warnings this may not be a problem, try loading the driver to see how it goes.

Adding Drivers to the Linux Automation Image

To use the drivers, you need to copy them to the correct location on your Deployment Solution server and then regenerate your image. To do so do the following:

  1. Copy the .ko files to the folder: ".\Boozwiz\platforms\Linux\x86\Drivers\CUSTOM\lib\modules\_ver_\kernel\opt\bdc"

    Note: The folders may have to be created. The paths above are relative to the deployment share. Change the x86 folder to correspond to the architecture you are using (x86, x64, IA64).
  2. Regenerate your Linux image, this can be done in PXE Configuration Manager. Edit the boot image and click next until the image regenerates. Then click Save on the main PXE Configuration Manager menu to save the changes.

If you don't want to add the driver to your image or want to load it using a script you can load it with the following commands:

  1. Copy the driver to the Linux automation local file system (after it boots).
  2. Change to the directory where you copied the driver to.
  3. Type depmod -ae.
  4. Type modprobe drivername, and omit the .ko extension, so for the bnx2 driver type "modprobe bnx2". If you get an error, you can try the -f parameter, which tries to force the driver to load. You may get a warning about a tainted kernel but this isn't a huge deal.
Important: The drivers you just compiled will only work with the kernel version they were compiled with. If you upgrade your Linux automation kernel, you will have to re-setup your Linux computer and recompile the drivers.

Statistics
0 Favorited
0 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Comments

Aug 13, 2007 01:24 PM

The KB article in your link is for DS 6.8 SP1 and older. This article is for DS 6.8 SP2, some things have changed between SP1 and SP2 that made a new article necessary. The updated version of the article is at: https://kb.altiris.com/article.asp?article=36079&p=1

Aug 13, 2007 08:32 AM

There is a great KB article that describes this as well: https://kb.altiris.com/article.asp?article=28260&p=1

Related Entries and Links

No Related Resource entered.