Skip navigation.
Home
Now Shipping Version 7.0

Kernel Install How-to and ndiswrapper install how-to


Posts: 7

(this is another kernel how-to for Mepis (Jan 2006). I don't claim to be a Linux expert, this is merely my experience in compiling the kernel. Recompiling your kernel CAN trash your system requiring re-install. It is always a relative risk. Any additional comments are welcome.)

Howdy,
Mepis is a great distro....I've been using it for about a year on my laptop because it just detects and runs all my laptop hardware. The Mepis team deserves credit and thanks for their hard work in creating it...and it's really cool to sit down and boot up the laptop on a plane or something and have someone look over at the computer and go "Wow! What is that?"

Linux is about choice and you have choice with Mepis as well. There's many occasions where you might want to replace or install additional kernels in Mepis---increased performance or security being a couple of reasons. One of Mepis' greatest strengths is that it will load on almost any x86 system. But it does so by enabling modules for almost every type of hardware out there. I simply just wanted to recompile the Mepis kernel without all 3 million modules (I don't really need the Appletalk drivers, dawg, or the cassette tape driver either). So I sent my Mepis kernel to "Jenny Craig".

IMPORTANT NOTE! to save yourself much frustration and headbanging, backup your kernel files in /boot before you read another word. That way if something goes wrong (and it will) you don't have to reinstall your distro. This should go without saying but having had to learn it the hard way, I really mean it. Back up your kernel, the config file, your initrd file, even the menu.lst file in Grub.

The Mepis distro releases it's own kernel through the Mepis debian apt pool (http://apt.mepis.org/3.***). At the time of this post, I am booting linux-2.6.12-1-586tsc (installed by the live CD 3.4.2 -r1 iso) and linux-source-2.6.12 (2.6.12-10.dcc3.0). It is in the Debian pool (search for linux-source in Apt, Synaptic or KPackage).

I thought that this would be a piece of cake...I use Gentoo on my desktop and I've compiled that kernal a few *hundred* times....so I'm bad. Waaay bad! So I thought....too many modules, no problem, modify the kernel, recompile and reboot. Stricktly a 1 beer job, I thought. The first time thru can be rough...it rates a 4 out 6 on the beer scale. But after that, recompiling your kernel is not that big deal.

Heh...remember when you were a windows user and all you had to do was click on the menu options as your drivers installed? Ah, those were the days.....playing "Punch the monkey..." while it installed 20 mg of spyware on the harddrive. But being unplugged from the M$atrix has its rewards...read on.

First, some definitions and overview for us newer folks (this is background...so you can skip it if you already know it....but for recent Windows users, welcome to Zion Smiling

"The chain of events at boot are: CPU-> VGA-> Power-On-Self-Test-> SCSI-> Boot Manager-> Grub bootoader-> kernel-> init-> bash. The firmware and software programs output various messages as the computer and Linux come to life." (quoted from http://www.faqs.org/docs/Linux-HOWTO/Kernel-HOWTO.html)

kernel- " The central module of an operating system. It is the part of the operating system that loads first, and it remains in main memory. Because it stays in memory, it is important for the kernel to be as small as possible while still providing all the essential services required by other parts of the operating system and applications. Typically, the kernel is responsible for memory management, process and task management, and disk management."

Specifically your kernel (kernel image really) lives in your boot directory (/boot) and tells your computer how to configure itself during startup (which modules to load, which network card you have, and so on). It generally has a name like "vmlinuz-2.6.12.10" or "kernel.2.6.14.3" but can have any name you want "spongebob-2.2.277-r4_crab_shack". It is helpful to rename your custom kernel something consistant that you will recognize later.

When you turn on your computer, the bootloader (Grub or Lilo...) lives in the main boot record and loads the kernel...it says go here and load this. Microsoft XP comes with a bootloader and kernel which load various configurations of XP....ie "safe-mode" when you press F8. You cannot modify the M$ kernel as directly as you can the Linux kernel but it loads in a similar fashion. It just runs underneath the GUI. If you run a dual boot system, the linux bootloader has replaced the M$ bootloader. You can not use the M$ bootloader to load linux, tho. If you reinstall Windows it will overwrite the linux bootloader, forcing you to reinstall Grub or Lilo so you access both OS's.

If you installed from an iso, the Mepis distro runs a pre-compiled kernel image (the binary code the machine runs) which resides in /boot. The kernel source lives in /usr/src/linux. When you make changes to the kernel, you must modify the source code, recompile it and then copy the image to the /boot directory and configure your bootloader. It is this process which this document is about.

(a nice Kernel tutorial can also be found here: http://www.mepislovers.org/ in the forums and also here http://www.mepislovers-wiki.org/index.php?title=Main_Page (search "kernel"). Another nice reference is http://www.faqs.org/docs/Linux-HOWTO/Kernel-HOWTO.html Credit for this document is owed to all these authors, thanks!).

The first thing I did was look for the kernel source code in /usr/src/**** But...surprise! The kernel source code isn't there on a virgin iso install. I couldn't find it on the iso either and I looked everywhere including under the Mepis couch. But as your network hardware is probably running, you can download the kernel source from APT via apt-get or thru Kpackage or Synaptic. You can also install any linux kernel you want (as long as it runs on your architecture) from http://kernel.org. There are additional custom kernels at www.mepislovers.org as well. If you install from APT it will download the tarball to /usr/src/. If it's a regular download, it will install wherever you told your browser to download to /home/~ or ~/desktop maybe. You need to extract the contents to /usr/src/ using Ark or by

tar xvfj kernel-source-?.tar.bz2
or
tar xvzf kernel-source-?.tar.gz

in the terminal as root user.

"Once you have the kernel source downloaded and extracted into your /usr/src directory then in a terminal type su to become root. Type

cd /usr/src

and then

ln -s kernel-source-whatever linux

(if your kernel source folder is called that) or

ln -s linux-source-whatever linux

if it is called this (the l in ln is the letter l and ln stands for link and the -s stands for symbolic. The linux word at the end is the name of the new link)."
(quoted from http://www.mepislovers-wiki.org/index.php?title=Compiling_and_installing_a_new_kernel)

This is done to link your main source directory (/usr/src/linux) to whichever kernel source you are using at the time. This is where the compiler will look when you get ready to "make" the kernel. If you maintain multiple kernel sources, /usr/src/linux must point to the correct source directory or you won't be able to compile that kernel source. If you only plan to use 1 kernel you can rename your kernel source directory in /usr/src to /usr/src/linux but using a symlink is safer.

A brief section on applying kernel patches can be found here: http://www.mepislovers-wiki.org/index.php?title=Applying_patch%28es%29_to_a_kernel and now would be the time to apply any kernel patches you might need.

patch -p1 < /path/to/kernel/patch

This will update your kernel source with the patch.

Next you must must configure your kernel so type (as root)

make oldconfig

What this does is copies the config file from your current (or old) kernel so your new kernel will compile with the same options as the old one.

But if you want a new config or different config for this kernel (my laptop doesn't like acpi) then you must manually configure your kernel. Type

make menuconfig
or
make xconfig

(you need to make sure they are installed from apt, yo)

What this does is let you manually configure your kernel options. You can change processer types and configure the driver modules for your hardware, etc. When you are done it will save a new config file for your kernel to compile with. xconfig or menuconfig...which one you use is personal preference.

Now it is time to compile your kernel. "Then you will build your kernel by typing:

make-kpkg buildpackage kernel_image

however, if you recompile the same version of your kernel use these command:

make-kpkg buildpackage -append_to_version -foo kernel_image

(exactly as written, "foo" can be anything)." (quoted from http://www.mepislovers-wiki.org/index.php?title=Compiling_and_installing_a_new_kernel)

If you are building a new kernel from scratch, I'd just use the "make-kpkg buildpackage" option.
What it does is compiles the new kernel and headers and modules and makes *.deb files which can be installed easily with dpkg or KPackage or Synaptic. Neat, huh? This is the "Debian" way.

(pause for chinese finger cymbal noises and drums......)

However, my kung-fu is "Gentoo". The "Gentoo" way works as well, little grasshopper:

make && make modules_install

but you will need to manually copy the kernel to /boot

cp arch/i386/boot/bzImage /boot/

(don't forget to copy the .config and the system map from /usr/src/linux-source-2.6.whatever to the /boot directory too)

(pause for flying roundhouse kick and more drums....and raise one eyebrow)

When I tried to recompile a previously built kernel, I had errors with the "-append-to-version" option. What I did instead is delete the old kernel (backed up of course) and also deleted the old kernel's *.deb files in /usr/src. I also needed to delete (backed up of course) the kernel module directory in /lib/modules/. I then used

make-kpkg buildpackage kernel_image

to build the kernel. Your kernel compile will take a little while depending on your machine. So check out google video or something. When it's done compiling there will be some *.deb files in /usr/src. Type

dpkg -i *.deb

in the terminal window (as root) to install them. What this will do is install your kernel image in /boot (vmlinuz-2.6.whatever) and your kernel headers and some other stuff including a tarball of your source. Nice.

Next, you have to tell the computer it has an option to load more than 1 kernel. In /boot/grub/ modify menu.lst

You are merely going to duplicate one kernel section and then alter it to fit your new kernel. So copy and paste

title linux-2.6.10-01 kernel 2.6.10-01
kernel /boot/vmlinuz-2.6.10-01 root=/dev/hda3 nomce psmouse.proto=imps quiet splash=verbose vga=791
initrd /boot/initrd.splash"

and change to

title My new kernel kernel 2.6.whatever
kernel (hd0,1)/boot/vmlinuz-2.6.whatever root=/dev/hda3 nomce psmouse.proto=imps quiet splash=verbose vga=791
initrd /boot/initrd.splash

Your title can be whatever you want. Make sure you have the correct kernel name in the second line or it won't run. Now to be honest, I don't really know what initrd does other than it loads the eye-candy splash screen as your kernel boots. So I just use initrd.splash for the 3rd line.

"The special file /dev/initrd is a read-only block device. Device /dev/initrd is a RAM disk that is...loaded by the bootloader before the kernel is started. The kernel then can use the the block device /dev/initrd's contents for a two phased system boot-up.

In the first boot-up phase, the kernel starts up and mounts an initial root file-system from the contents of /dev/initrd (e.g. RAM disk initialized by the boot loader). In the second phase, additional drivers or other modules are loaded from the initial root device's contents. After loading the additional modules, a new root file system (i.e. the normal root file system) is mounted from a different device." (quoted from http://linux.about.com/od/commands/l/blcmdl4_initrd.htm)

So it's like a mini-kernel that allows you to load modules and whatnot so you can access the device containing the root file system before you load the kernel from that device like a RAID system or a USB pen drive. I guess it allows you to use a more generic kernel over a wider subset of system architectures. Ah hah.

mkinitrd ./initrd-2.6.whatever-custom.img 2.6.whatever.custom

Your kernel will load without initrd, tho. You just have to build the drivers to access the root file system into the kernel. It means that your kernel will have to be bigger and more specific to that machine.

If you want your new kernel to be the default, have it be the first kernel section.

Save menu.lst and reboot. If everything went Ok your new kernel will be present in the boot menu and will boot. Um.."kernel panic" means that you built a Ford "Pinto" and it just caught fire. Reboot with your regular or backup kernel and figure out what went wrong.

If it works, X should come up along with your window manager and all your regular settings should be intact. Congratulations! You just compiled your first kernel (and it only took a weekend). Now, the power to control your system belongs to you. Which is the whole point. It's like the scene in "Tron" at the end where the MCP is destroyed and all of computerland lights up and turns "happy". You just did that. Cool, huh?

Depending on the kernel you have installed, you may have additional configuration issues to contend with, so just play "whack-a-mole" with ALSA and your graphics and network drivers until it all works again. Some drivers must be recompiled and reinstalled under the new kernel to work properly.

The only one I will mention is NDISWRAPPER because it's process dovetails with this one. Ndiswrapper is a network card driver that uses windows network card drivers to run the card under linux. It can be considered "kludgey" but it works just fine if your card does not have a native linux driver or if installing that native driver is going to be worse than..say, hemorrhoid surgery. Mepis uses ndiswrapper. My network card is a PCMCIA Linksys WPC54G which uses a Texas Instruments ACX110 chip. Yeah, it doesn't say that on the card but you can detect it by typing

lspci

{insert rant} Some network card chip manufacturers refuse to release their source code for many reasons....although, one might think that there would be a market in being *the* linux network card company...I reference Nvidia. TI's native linux driver for that chip had to be reverse-engineered. It works...but the install is painful. So I was happy to see that Mepis had an out-of-the-box solution that worked (windows firmware under ndiswrapper).

However, you have to recompile the ndiswrapper driver module for your new kernel after you install the new kernel or it won't load. It goes a little like this: install ndiswrapper-source from APT in /usr/src or you can get here: http://www.mepislovers-wiki.org/mepislovers/downloads/kernels/ under the correct kernel module section. Untar the tarball and put ndiswrapper in the /usr/src/modules/. If it is present when you compile the kernel, it will compile as a deb too.
Now reboot with the new kernel and install lthe deb.

If the pre-compiled deb doesn't work or isn't present, it can be compiled manually into a deb with:

make-kpkg modules_image

What this does is make debs of the module binaries for you to install with dpkg -i

Reboot with the new kernel and

dpkg -i ndiswrapper.***.***.deb

You may also have to reinstall ndiswrapper-utils (from APT) because it uses this to figure out which network card firmware you need. But make sure it has the same version number as ndiswrapper-sources.

Test the module with

modprobe ndiswrapper

and
lsmod

should return ndiswrapper as a loaded module. If this doesn't work, happy reading in the forums Smiling

If it does, go to Mepis-OS center and restart wlan0 (or whatever your network card is under) and you should get an IP address from the network. "Yayyyy!!!! I've got mail. Yayyyyyyyy!!!!"

Reboot and if you are running Mepis it should automatically load the ndiswrapper module during boot. And that's it, good luck!