Ryan’s Blog

March 26, 2009

How to fix Ubuntu Jaunty. Warning Hacks Ahead!

(Note: This post is outdated and should NOT be used. I’ll update it eventually.)

(Note: After further investigation, the newer version of ALSA installed by the Ubuntu maintainer’s test version of Pulseaudio is hated by Wine, but using Wine’s OSS option will work, this is not really Pulseaudio bustage for once so much as Wine stupidity, as Wine does not expect the new ALSA libraries. If it really bugs you that much you can stick with scratchy popping audio, or install this version of ALSA and either compile Wine yourself or use OSS)

OK, so what does it take to fix Ubuntu’s ridiculous behavior?

I’ve had a lot of these bugs for a long time, but the Ubuntu development team seems fairly indifferent and unapproachable, so I found them easier to fix myself than to beg them endlessly to fix it.

Here’s a list of what we will fix based on bugs in my Ubuntu system:
Problem 1: No Minstrel rate control algorithm.

Problem 2: Pulseaudio bustage.

Problem 3: The PCM system mangles whatever Ubuntu’s Pulseaudio didn’t.

Problem 4: My wifi does not work after resume.

Problem 5: Their realtime kernel is still bloated with crap I don’t want/need (No desktop user does), it crashes constantly, they bypassed Linux 2.6.29 entirely, and it’s not very optimized.
How to fix:

First, you should remove any drivers Ubuntu has offered you through Retricted Driver Manager, and remove anything that their DKMS system tries to patch their kernels with (such as the nvidia-common package), it can’t hurt to also get rid of jockey-common and jockey-gtk so they don’t pop up in the future.

Open a terminal:

It’s a good idea to have everything up to date with Ubuntu’s repo before we proceed, so:

sudo apt-get purge jockey-common jockey-gtk nvidia-common (so it can’t molest our new pristine kernel)

sudo apt-get update && sudo aptitude safe-upgrade (reboot if you need to)

We can now proceed to get development tools, the same kind you use on Debian:

sudo apt-get install kernel-package libncurses5-dev fakeroot wget bzip2 build-essential

After that you can navigate to your source folder and become root (sudo su is the easiest way to get into root without setting up the account):

cd /usr/src && sudo su

Enter your sudo password.

Now grab the proper kernel tarball from kernel.org without the various Ubuntu crap ;) At the time of this writing it was 2.6.29 as the latest, but you need to check their ftp to make sure and update the line appropriately:

wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.29.tar.bz2 && tar -xvvjf linux-2.6.29.tar.bz2 && ln -s linux-2.6.29 linux && cd linux

We have just unpacked the tarball, made a symlink forwarding calls to /usr/src/linux to the linux-2.6.29 kernel source directory and changed to that directory.

We now run this:

make clean && make mrproper && cp /boot/config-`uname -r` ./.config

This cleans up the build directory and copies over your config from your working Ubuntu kernel as a template, there’s thousands of settings for the kernel but I doubt you want to start from scratch.

Now if you’re using vanilla 2.6.29 (and not any updates that as of this writing don’t exist), we need to grab a file from a kernel developer’s (Takashi Iwai) git repo and copy it to our sources, think of it as a patch, the Ubuntu kernel guys are using the same file in some test kernels with the intention to make Pulseaudio suck less. I tracked this file down and it seems it didn’t make 2.6.29, it may make 2.6.29.1 though.

Go here and copy everything and past it into your text editor of choice and save it on your desktop as pcm_lib.c and then open a new terminal as you (not root):

sudo cp ~/Desktop/pcm_lib.c /usr/src/linux/sound/core

Overwrite the file if it asks. You can navigate there and make sure it worked if you like, the new file is 53k in size. Close the new terminal  (I needed that because the ~ always refers to YOUR home folder)

In your root terminal, you may now run:

make menuconfig

It’ll take you to a configuration menu for your new kernel, you obviously should not poke around with anything you are not sure of, I want a real time kernel optimized for my CPU, where I get the Minstrel rate control for my wifi, but feel free to look around, * means it’s built into the kernel, m means loadable module. Ubuntu likes to build a lot of crap in that shouldn’t be, so here’s what I change (hit spacebar to change a setting):

General Setup:

RCU Implementation I change from Classic to Preemtible, it may not appear til we select preemptible kernel later, so you can come back if that’s the case.

Enable the Block Layer/I/O schedulers:

I remove Anticipatory and Deadline and leave CFQ.

Go back to main menu.

Processor Type and Features:

I do this:

Uncheck Enable MPS Table (for old systems without ACPI)

Processor Family, I change from Generic X86-64 to Core 2/Newer Xeon

Uncheck IBM Calgary MMU support

Uncheck AMD IOMMU Support (Unless you use AMD)

Set Maximum Number of CPUs to whatever you have.

Preemption Model to “Preemptible Kernel (Low Latency Desktop)”

Uncheck EFI Runtime Support (If you have a BIOS, there’s no point in having that)

Uncheck Kernel Crash Dumps

Timer Frequency 1000HZ (Dynamic Ticks makes this largely pointless, but why not?)

Go back to main menu.

Networking Support/Wireless/Rate Control Algorithm Selection:

Make sure it’s set to Minstrel, it should be.

Back to main menu.

File Systems:

Ubuntu builds in Ext2/3/4, if you use those there’s really nothing to do here, but I don’t use them and Jaunty supports everything on XFS now, so I change them to m (module) so they’re not always loaded, and I build in XFS, do whatever floats your particular boat.

Back to Main Menu:

Kernel Hacking:

Uncheck Enable Unused/Obsolete exported symbols.

Uncheck Kernel Debugging.

Uncheck Compile The Kernel With Frame Pointers and Latency Measuring Infrastructure.

Go back to main menu.

Exit and select yes to save changes:

We then run:

fakeroot make-kpkg –initrd –append-to-version=-ryan1 kernel_image kernel_headers

Where ryan1 is the identifying string for my kernel, replace it with your particular name, if you need to recompile it later, you can use ryan2 for example, and install it side by side, grub will also see the later version number and boot that by default.

After compilation is finished, you can use:

cd ..

to move up one directory and then you will find two deb files if you use ls to list contents of the directory, install the headers and then the kernel image with “dpkg -i” followed by the name of the headers deb and then again with the image deb.

Note that if you need Nvidia, AMD’s FGLRX, or other such drivers, you now must use their installer, and to build 32-bit compatibility opengl files through the Nvidia installer, you need ia32-libs installed!

Note you can get rid of Ubuntu’s kernel if you like, just remove linux-generic, linux-image-generic and all their linux image and headers and restricted modules packages, you want to be careful to not remove yours. Be sure to leave linux-firmware installed so our new kernel can use those firmwares for things like Ralink wifi and other stuff.

———————-

Now we move on to PulseAudio which even Ubuntu’s developers admit they implemented wrong in order to expose bugs in the ALSA system:

If you notice something like this in your kernel logs, and don’t want to trust Ubuntu to do the right thing….eventually, you will need the experimental version of Pulseaudio 0.9.15 found in an Ubuntu maintainers PPA.

https://launchpad.net/~themuso/+archive/ppa

Open your Software Sources (System/Administration/Software Sources), go to Third Party Software and add Luke Yelavich’s PPA:
deb http://ppa.launchpad.net/themuso/ppa/ubuntu jaunty main

Now add his signing key by right clicking the desktop, Create Document, Empty File, name it whatever you want and add his key (from http://keyserver.ubuntu.com:11371/pks/lookup?op=get&search=0×0B47F0A6B88A1AA8):
—–BEGIN PGP PUBLIC KEY BLOCK—–
Version: SKS 1.0.10

mI0ESXPfogEEAMjHhPprxuODP9MvplG/RxR9t64WdSrVrrO8TnPSRIzcdwoFi5VcQgG2bUBG
IoVz8zSVkXJlMcj+GfbwTvdDKRxV19Fwz9gafQNsQIBLHzVAZbczjf9rOmlWCACQJMRW9eu2
AUD8T4HSlT1e9TD0cN6ONsYz38EYqlpGxPzJi5IDABEBAAG0H0xhdW5jaHBhZCBQUEEgZm9y
IEx1a2UgWWVsYXZpY2iItgQTAQIAIAUCSXPfogIbAwYLCQgHAwIEFQIIAwQWAgMBAh4BAheA
AAoJEAtH8Ka4ihqopmAEAJtuqVE+QpGJiIyrSRdFsSuCZlkUbmr6f/xBFv6ak38frVvJODnX
VKm94BGEBBrtdA0Z/K4BlsOFYvJ2emB0jYdjXRUqEX0X1fdLCn8jAX4HzZ0AonNDd6NtHCx5
vvNZZTy9myrFye+B2qNIQhQ/WrBMtCAb+aCE4/7241z36rua
=OzQk
—–END PGP PUBLIC KEY BLOCK—–

Save the file, go to the Authentication tab in Software Sources, and and Click Import Key File, and navigate to the file you just made on your desktop and double click, then exit and select Yes when it asks to update your sources.

Go to a terminal and:

sudo apt-get update && sudo apt-get dist-upgrade

Install everything it offers.

Bonus: If you want to change Pulseaudio to now behave like Fedora’s GlitchFreeAudio, you can edit /etc/pulse/default.pa

Look for the line:

load-module module-hal-detect tsched=0

and change to

load-module module-hal-detect

Restart and you should have a decent kernel and functional timer-based Pulseaudio with no snaps crackles or pops, this is an operating system, not a breakfast cereal.

Now if you use a wifi connection and your wifi does not come back after reboot, there’s a suitably generic hack around this that I’ll post below:

Create a file called 66wireless in /etc/pm/sleep.d:

cd /etc/pm/sleep.d/ && gedit 66wireless.sh

And for the Ralink RT61PCI driver which I use, paste this in:

#!/bin/sh

case $1 in
hibernate|suspend)
;;
thaw|resume)
ifconfig wlan0 down
modprobe -r rt61pci
modprobe rt61pci
ifconfig wlan0 up
;;
help)
echo “$( basename $0 ): Reinitializes wireless (rt61pci) after a suspend”
;;
*)
echo “$( basename $0 ): called wrong”
exit 1
;;
esac

And save it, now:

sudo chmod +x 66wireless.sh

and reboot. (rt61pci is the name of my wireless driver module, replace it with the name of yours) The next time you suspend, your wireless will most likely survive.

Enjoy!


16 Comments »

  1. Kernel building for Ubuntu
    http://blog.bitcomet.com/post/74675/

    Comment by G&T — March 26, 2009 @ 4:58 am

    • That seems kind of old.

      Yes, I used to use Alberto Milone’s EnvyNG when it was maintained, and it would grab the real Nvidia installer and use that, it was awesome.

      The reason I said to get rid of the DKMS modules that Ubuntu uses to patch newly installed kernels is because they did a really piss poor job with that and their module installer either just fails to build, will eat the kernel you just made, or will corrupt your Dpkg database. It’s much better to use the installer from Nvidia if you’re using your own kernels, otherwise Ubuntu’s installer will fuck over your system more often than not.

      Comment by Ryan — March 26, 2009 @ 5:31 am

  2. Here is the error I receive trying to build the kernel:

    fakeroot make-kpkg –initrd –append-to-version=-ryan1 kernel_image kernel_headers
    Error: Unknown target –initrd Unknown target –append-to-version=-ryan1
    use –targets to display help on valid targets.

    Comment by NeoFax — March 29, 2009 @ 6:33 pm

    • WordPress changed two dashes (-) to a single double-sized. grrrr, just use two of those in front of initrd and append. sorry :(

      I also notice that 2.6.29-git5 has merged a lot of PCM fixes, but it’s a prepatch and those are automatically built and not tested, so I don’t recommend them unless you know what you’re getting into :)

      Comment by Ryan — March 29, 2009 @ 7:35 pm

  3. Why the hell are you using the realtime kernel? Are you running robotic equipment?

    “realtime” does not mean “super cool”. Use Generic, that’s what it’s there for.

    Comment by yttrx — March 30, 2009 @ 3:10 pm

    • “You need a low latency kernel for optimal performance (this applies to both client and server installations). Make sure your kernel
      is configured with CONFIG_HZ_1000=y. You should also enable other low latency settings, such as the various preemption settings.”

      -From the Enemy Territory documentation

      That’s what got me started with CONFIG_PREEMPT=Y

      It does make the system much more responsive.

      and “Why the hell” not?

      Generic is fairly unoptimized and has all the legacy/deprecated crap turned on, and all the stuff like Calgary which does nothing for you except leave crap in your logs every boot.,

      The Ubuntu kernel team is using a “catch all” kernel that has much crap that you don’t want or need instead of bothering to optimize for specific processors or use cases.

      Comment by Ryan — March 30, 2009 @ 11:59 pm

  4. Achtung!
    Das vanilla-kernel is nicht fur gefingerpoken und mittengrabben. Ist easy schnappen der springenwerk, blowenfusen und poppencorken mit spitzensparken. Ist nicht fur gewerken by das dummkopfen. Das rubbernecken sightseeren musten keepen das cotten-pickenen hands in das pockets – relaxen und usen das blinkenlights-generic.

    Happy now?

    Comment by Ryan — March 31, 2009 @ 12:07 am

  5. I compiled a kernel last night, it works and it boots and runs fine. But > I wanted to remove some cruft like raid and such, to make the kernel smaller.

    I did it all over again, and when I got to this step it fails to make a new package to install. I ma new Ubuntu. but not sure what this is telling me:

    root@Q6600:/usr/src/linux# fakeroot make-kpkg --initrd --append-to-version=-bob1 kernel_image kernel_headers
    exec debian/rules DEBIAN_REVISION=2.6.29.1-bob1-10.00.Custom APPEND_TO_VERSION=-bob1 INITRD=YES kernel_image kernel_headers
    /usr/bin/make -f ./debian/rules debian/stamp/binary/pre-linux-image-2.6.29.1-bob1
    make[1]: Entering directory `/usr/src/linux-2.6.29.1'
    make[1]: `debian/stamp/binary/pre-linux-image-2.6.29.1-bob1' is up to date.
    make[1]: Leaving directory `/usr/src/linux-2.6.29.1'
    /usr/bin/make -f ./debian/rules debian/stamp/binary/pre-linux-headers-2.6.29.1-bob1
    make[1]: Entering directory `/usr/src/linux-2.6.29.1'
    make[1]: `debian/stamp/binary/pre-linux-headers-2.6.29.1-bob1' is up to date.
    make[1]: Leaving directory `/usr/src/linux-2.6.29.1'
    root@Q6600:/usr/src/linux#

    When I try it with bob2 it results in this:

    root@Q6600:/usr/src/linux# fakeroot make-kpkg --initrd --append-to-version=-bob2 kernel_image kernel_headers
    exec debian/rules DEBIAN_REVISION=2.6.29.1-bob1-10.00.Custom APPEND_TO_VERSION=-bob2 INITRD=YES kernel_image kernel_headers
    /usr/bin/make -f ./debian/rules debian/stamp/binary/pre-linux-image-2.6.29.1-bob2
    make[1]: Entering directory `/usr/src/linux-2.6.29.1'
    ====== making target debian/stamp/install/linux-image-2.6.29.1-bob2 [new prereqs: ]======
    This is kernel package version 11.015.
    echo "The UTS Release version in include/linux/version.h"; echo " \"\" "; echo "does not match current version:"; echo " \"2.6.29.1-bob2\" "; echo "Please correct this."; exit 2
    The UTS Release version in include/linux/version.h
    ""
    does not match current version:
    "2.6.29.1-bob2"
    Please correct this.
    make[1]: *** [debian/stamp/install/linux-image-2.6.29.1-bob2] Error 2
    make[1]: Leaving directory `/usr/src/linux-2.6.29.1'
    make: *** [kernel_image] Error 2
    root@Q6600:/usr/src/linux#

    can you tell me where I went wrong? I’m also trying to figure how to compile it with MAKEOPTS j5 like on Gentoo.

    Comment by BobbyJ — April 8, 2009 @ 6:33 pm

  6. So, I did all this, I was happy, the kernel seems to run like a charm but my sound is gone… :s
    Nothing is mute, mplayer act like if there was no problem but there is absolutely no sound going through my speakers :s
    Any idea?
    thanks

    Comment by nicoseb — April 19, 2009 @ 7:38 pm

  7. holy crap, we have that “achtung! … ” spiel on a sign in our barn, on the breaker box! you are my hero!

    that said, I might try to build the vanilla kernel by this guide when I upgrade. does it work for dual core?

    Comment by Dave — April 20, 2009 @ 4:00 am

  8. Examining /etc/kernel/postinst.d.
    run-parts: executing /etc/kernel/postinst.d/dkms
    run-parts: executing /etc/kernel/postinst.d/nvidia-common
    run-parts: /etc/kernel/postinst.d/nvidia-common exited with return code 20
    Failed to process /etc/kernel/postinst.d at /var/lib/dpkg/info/linux-image-2.6.29.6-rt23psc1.postinst line 1186.
    dpkg: error processing linux-image-2.6.29.6-rt23psc1 (–install):
    subprocess post-installation script returned error exit status 2
    Errors were encountered while processing:
    linux-image-2.6.29.6-rt23psc1

    Comment by psc — July 10, 2009 @ 6:19 pm

    • Yes, that’s why I said to remove nvidia-common before proceeding.

      This bit is old now and the 2.6.30 kernel is out, I really need to update this.

      Comment by Ryan — July 10, 2009 @ 7:25 pm

  9. yo ryan,
    i followed your howto compile the kernel for kernel 2.6.30.4 it work, but it seem i cant use usplash nor see any text during the bootup process but only blank screen (but it seemf faster thought)
    can you tell me..why is this happening, is it have something to do with disable kernel debug?

    Comment by kambeng — August 3, 2009 @ 1:53 pm

  10. When you do update this, I’d love to see it done with ArchLinux. :D

    Comment by Ryan W — August 19, 2009 @ 8:14 am

    • I need to update it actually.

      I’ve never used Arch.

      Comment by Ryan — August 20, 2009 @ 1:01 am

      • Aww really? You should try it. It is quite amazing. It seems like everyone who uses it falls in love with it.

        Comment by Ryan W — August 20, 2009 @ 1:31 am


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.