Low-Latency 2.4.x with ALSA mini-HOWTO

by Paul Winkler 9/11/2000
updated by Eric Rzewnicki 03/17/2002
updated by Patrick Shirkey 07/24/2002

Last addition by Paul Winkler 07/22/2002


  1. Introduction
  2. Downloading and Patching the Kernel
  3. Configuring and Building the New Kernel
  4. Update Modutils and Load Modules
  5. Install ALSA
  6. Necessary Upgrades


This document is specifically aimed at those interested in using 2.4.x with Andrew Morton's low-latency patch for audio purposes.

It's not really hard when you know what to do, but there's a lot of stuff to upgrade before you can compile and install the kernel if you are moving from linux 2.2.x. So if you are, don't forget to read the section on updating your system files.

We suggest scanning through this whole document to get an overview before you start mucking with the kernel. Everything described here requires kernel configuration, and it's easier to do it all in one go rather than rebuilding the kernel again for each feature you want. You should also read through the necessary upgrades to make sure you have all your software in order before you start configuring.

Downloading and Patching the Kernel

  1. Download Andrew Morton's latest low-latency patch.
  2. Download the 2.4.x sources of the right version for Andrew's patch. When I say x, I mean for example get linux-2.4.17 if you have a Morton patch for 2.4.17. Kernel sources can be found at ftp.kernel.org and various mirrors.
  3. It's good to keep your sources organized. /usr/src/linux is probably a link to your current kernel sources, something like this:
    $ ls -l
    total 4
    lrwxrwxrwx    1 root     src            12 Jul 22 13:46 linux -> linux-2.2.16
    drwxr-xr-x   14 root     root         4096 Jul 21 22:59 linux-2.2.16

    If that's the case, remove the link:

    rm /usr/src/linux
    Otherwise, if /usr/src/linux is a directory and not a symlink, rename it so the name includes the kernel version, e.g.:
    mv /usr/src/linux /usr/src/linux-2.2.16
  4. Now unzip the 2.4.x source tarball and untar it in /usr/src/ . This will result in a /usr/src/linux directory. Rename this /usr/src/linux-2.4.x where x is the proper number.
    mv linux linux-2.4.x
  5. Re-create /usr/src/linux as a link to your new sources:
    ln -s /usr/src/linux-2.4.x /usr/src/linux
  6. Now apply Andrew's patches:
    cd /usr/src/
    patch -p0 < /dir/where/you/put/2.4.x-low-latency.patch

    This should patch without any problems. However some people have found that this works better:

    cd /usr/src/linux
    patch -p1 < /dir/where/you/put/2.4.x-low-latency.patch
    gzip -cd patchXX.gz | patch -p0

Configuring and Building the New Kernel

  1. Configuration may be easier if you copy your old kernel configuration to your new source directory:
      cp /usr/src/linux-2.2.x/.config /usr/src/linux
  2. To save a copy of your old kernel config as .config.old and create a .config updated for the current kernel:
     make oldconfig
  3. In /usr/src/linux, do make config, make xconfig or make menuconfig (your choice). You'll want to read /usr/src/linux/Documentation/Changes first!

    Options relevant to low-latency audio:

  4. Most likely, you have an IDE CDROM or CD-R or CD-RW drive. If you want to exercise your rapidly-diminishing fair use rights under U.S. law and make a copy of something in your CD collection for your own personal use, you'll need to do a few things before you can "rip" music from an audio CD. As it happens, exactly the same setup is necessary to support "burning" your own data or audio CDs.

    You first need to enable SCSI emulation so that the system treats the IDE drive as if it were a SCSI drive.

    During kernel configuration: First, go into "ATA/IDE/MFM/RLL support". In the subsection for "IDE, ATA and ATAPI Block devices", make sure to choose N for "Include IDE/ATAPI CDROM support". Then choose Y or M for "SCSI emulation support". Go back to the main menu, enter SCSI support, and be sure to say Y to "SCSI support", Y to "SCSI CD-ROM support", and Y to "SCSI generic support".

  5. (Optional step) Edit line 4 or your kernel Makefile to set an Extraversion. I find this useful for tracking various compiles of the same kernel version in case I make a mistake or want to test different configuration options. I usually use the hostname and a sequence number in addition to indicating any patches applied:
      vi Makefile
      EXTRAVERSION = -ll-box1-0

  6. Now build your kernel:
      make dep
      make clean
      make bzImage
    Next check to see that the compile succeeded. There is nothing more frustrating than removing the files below before you find out that there was a problem you didn't notice while compiling. Usually compile problems are because of missing module dependencies. Often the output will look normal but you will know for sure there was something missing from the config if you don't have a System.map. If you do then proceed below, if you don't then you need to hunt down the missing dep. Sometimes the location of the dependency changes between kernel versions. If you are using a 'pre' kernel you may even have to to patch a file by hand.
      ls System.map (check to see that the compile succeeded)
      rm -f /boot/System.map
      cp System.map /boot/System.map
      rm -f /boot/bzImage
      cp arch/i386/boot/bzImage /boot/bzImage-2.4.x
  7. Update LILO. Edit your /etc/lilo.conf file and put in a new image entry:
    If you also want to use your cdwriter, or rip audio from a CD, there's one more thing to add in lilo.conf before you'll be able to use the drive:
    append="hdX=scsi hdX=ide-scsi"
    ... replacing X with the drive letter of your IDE cd drive, e.g. my CD drive is /dev/hdc.

    (I'm not clear on which of those options is actually needed, I think it may have changed at some point. I have both options, which seems to be safe - the invalid one is ignored.)

    If you already have an "append" line in lilo.conf, just add the text in quotes.

  8. Now run LILO so it finds the new image:
    As always, running LILO is VERY important. You won't be able to boot the new kernel until you do so. This is especially important if you ever remove your old kernel!
  9. The 2.4 kernel uses a new device file for shared memory. It's a good idea to use this, so add this to /etc/fstab. Put this line in /etc/fstab:
    none                /dev/shm              shm     defaults      0 0
    And make the directory: mkdir /dev/shm
    It won't affect booting an old linux 2.2 kernel - you'll just get a complaint that the kernel does not support the shm filesystem.
  10. Finally!! Shut down and boot your new kernel.
  11. Extra step for CDWriting support - After rebooting the new kernel, the only remaining step is (as root):
    rm /dev/cdrom
    ln -s /dev/srN /dev/cdrom  
    lns -s /dev/scdN /dev/cdrom
    (either one should work) Once again, replace N in these commands with the appropriate number. In my case, I have no real SCSI devices, so I choose /dev/sr0.

    Now that you've got everything ready, try mounting a data CD to make sure that still works. Also try playing an audio cd. Next, try ripping and/or burning. Useful tools include cdrecord and cdparanoia. More information can be found in the CD-Writing HOWTO, which may be in your installed documentation, or check here: http://www.tldp.org/HOWTO/CD-Writing-HOWTO.html

Update Modutils and Load your Modules

There's a few things you need to do before you can load modules with 2.4.
  1. First, if you are running an old modutils version (probably not these days), upgrade modutils.

    insmod -V
    See below for the correct version number. Hopefully you won't have to, but if you do then you need to download the modutils package. Compile and install it now, or use your distribution's latest available package. Make sure your old modutils is gone!
  2. If your module configuration is in /etc/conf.modules, be advised that this name is deprecated - you should rename it to /etc/modules.conf . Don't worry, this won't harm anything with your old 2.2 kernel. Note that some linux distributions, e.g. Debian, do not advise editing /etc/modules.conf directly; instead, you edit or add files in /etc/modutils and run a script called update_modules which generates /etc/modules.conf for you. This allows you to organize things a little better.
  3. Now you should build your kernel modules.
    cd /usr/src/linux
    make modules; make modules_install
  4. Try to load a module using modprobe or insmod ... hopefully it should work! You might need to run depmod -a as root. If there's a problem, double-check your configuration for that module in /etc/modules.conf.

Alternative Build and Install for Debian Users

The above directions will work just as well as the following, but this method using make-kpkg can save some work for Debian users. Starting after the kernel configuration:
  1. Install kernel-package
    apt-get install kernel-package
  2. Build a kernel and pack it into a .deb file
    make-kpkg clean
    make-kpkg kernel-image
    or, if you want to time the kernel build so you'll know how long it takes if you need to do it again:
    time sh -c "make-kpkg clean; make-kpkg kernel_image"
  3. Install the kernel .deb package
    cd ..
    dpkg -i linux-2.4.x-ll-box1-0.deb
    The kernel package will take care of configuring and running LILO. It also handles the modules. For more information on the organization of kernel package management in Debian see the dpkg and make-kpkg man pages.
  4. Shut down and boot your new kernel.

Install ALSA

Now you're finally ready to get your soundcard working again. I won't go into detail on this because ALSA installation and configuration is well covered elsewhere. Go to The ALSA howto. I didn't have to do anything differently with the 2.4 kernel; ALSA just worked fine!

Necessary Upgrades

There are a number of packages you may need to upgrade. These are listed in /usr/src/linux/Documentation/Changes. The listing below is taken from Documentation/Changes for a 2.4.17 kernel.
Current Minimal Requirements

Upgrade to at *least* these software revisions before thinking you've
encountered a bug!  If you're unsure what version you're currently
running, the suggested command should tell you.

Again, keep in mind that this list assumes you are already
functionally running a Linux 2.2 kernel.  Also, not all tools are
necessary on all systems; obviously, if you don't have any PCMCIA (PC
Card) hardware, for example, you probably needn't concern yourself
with pcmcia-cs.

o  Gnu C                  2.95.3                  # gcc --version
o  Gnu make               3.77                    # make --version
o  binutils                   # ld -v
o  util-linux             2.10o                   # fdformat --version
o  modutils               2.4.2                   # insmod -V
o  e2fsprogs              1.25                    # tune2fs
o  jfsutils               1.0.12                  # fsck.jfs -V
o  reiserfsprogs          3.x.1b                  # reiserfsck 2>&1|grep reiserf
o  pcmcia-cs              3.1.21                  # cardmgr -V
o  PPP                    2.4.0                   # pppd --version
o  isdn4k-utils           3.1pre1                 # isdnctrl 2>&1|grep version

Additional test commands that take advantage of your distribution packaging system: