Thursday, December 18, 2008

Kernel driver changes

I learned how to add in or swap out a Linux kernel module today. Kinda cool.

Let's start with the problem. My new laptop has both a wireless card AND an Ethernet card that are incompatible with Ubuntu Linux. So, after a little bit of testing and research, my ever patient friend, savior and all things *nix tutor discovered that the problem was that Ubuntu picks the wrong kernel driver for the Ethernet card on this machine and that it didn't have the wireless driver at all.

Just for extra learning goodness (or kharma or something), after my friend did the whole process to get my networking up and running, the Ubuntu updater updated the kernel and wiped out all his work. That just meant that I got to do the whole process myself, with him reminding me of the steps as I went.

So, the steps: First we downloaded the source code for the drivers. Unpacked the tarballs, followed the directions to compile the drivers.

With one of the drivers, the make install target did the copying of the kernel object into the right place for us. With the other driver, we needed to do that ourselves. To do that we found the ".ko" file in amongst the compiled code and copied it to the correct directory under /lib/modules/.

In the case of the Ethernet card, we needed to blacklist the wrong module as well, just to make sure that it didn't get loaded again by accident. To do that, we headed over to /etc/modprobe.d/blacklist and edited the list to include the bad driver. (Bad, bad driver! Don't come back!!)

Next
depmod -a
runs through your kernel and makes sure that all of the dependencies are there. It takes kind of a long time to run, because it goes through all of your kernel files.

Then use
modprobe [module]
where [module] is the name of your module, of course, to get the driver up and running.

Use
lsmod
to check to see if your modules are there.

We tested the whole thing by creating a boot image with our modified kernel. We did that with
mkinitramfs -o /boot/initrd.img-2.6.27-9-generic.new `uname -r`
and then we created an entry in grub at /etc/grub/menu.lst for the new image. The command mkinitramfs creates a special file with all the kernel information that the system needs to boot. The name that I used was based on the existing file for the pre-modified kernel, but with .new on the end. That was so that we'd know which was which, of course, and so that we'd know what to copy over top of later.

After booting into the modified kernel with out a problem, we went back and removed the extra grub entry, and moved the .new version of the image over top of the normal version. Now the modified kernel is my kernel and I have Ethernet AND wireless networking. Yay!


In case you are wondering, my new laptop is an LG R510. (My 9yo son says the LG stands for "Lawful Good". You think I'm raising a geek?) The drivers it needed are Realtek Ethernet and Ralink Wireless.

No comments: