LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 12-03-2010, 10:17 AM   #1
Gaidal
LQ Newbie
 
Registered: May 2002
Location: Sweden
Distribution: Arch x64
Posts: 29
Blog Entries: 2

Rep: Reputation: 0
How do I safely make custom kernels?


I'm trying to learn the kernel customization and compilation process, using whatever articles I can find and the book Linux Sea as a reference. I haven't gotten it to work yet, and for some reason I have now made my system unusable beyond the CLI. That's OK though (I can just reinstall, although it takes almost a day), what I don't like is being so clueless.

I would like to know how I managed to screw my system up when installing the modules, so that booting the original kernel doesn't work anymore, and how I can go back to my old configuration. I'm using Slackware current and have been using its huge-smp-2.6.35.7.
My current installation doesn't matter much, I want to understand the general process.

Question:
What is the clean, safe way of trying a new kernel configuration, that won't leave any traces if I decide it was a failure and go back to the previous kernel?

Short explanation: The apparently necessary make modules_install seems to change stuff system-wide - or for all kernels of the same version - making saving a LILO entry to my old vmlinuz insufficient as a safety measure. Learning this will be tedious if I can't go back when I screw up - the compilation taking up to 2+ hours is killing me already. :P

Long version: The first time I only ran 'make menuconfig', 'make', copied the new bzImage to /boot and updated LILO. In the boot messages, among other things it warned several times that it was expecting the 686 architecture and not the new one I had chosen (Atom), and although I could boot, X didn't work. Later when I read that I should run make modules_install after 'make' and tried that, these warnings disappeared. However I had screwed something else up this time and needed to go back. Trying to boot the original kernel (huge-smp, because generic can't mount my ext4 root fs for some reason), it now had lots of complaints about modules (which I assume had been updated for my custom kernel), so I tried restoring the original state by doing make clean in the kernel src dir, deleting .config, copying the bundled original .config for huge-smp, recompiling with 'make' just in case, and then running make modules_install again. After rebooting with my original huge-smp, nothing seems to have changed, the modules still aren't working and I get various errors, and only a CLI, X won't start (complains about modules that cannot be inserted).

What did I do? All the guides I've read only mention keeping a LILO or GRUB entry for the old kernel, which I did, and it's clearly not working in this case.
Is the system.map file relevant? Should I dare to use make install rather than copying the bzImage manually - would it overwrite a kernel of the same release?
 
Old 12-03-2010, 11:23 AM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
Something that may make your life a little easier is that you can start with the .config file from the distribution media. On the Slackware64-13.1 DVD it's in the kernels/huge.s directory and you can simply copy that file into /usr/src/linux and proceed from there; that .config is what the distribution kernel was built from.

You may want to make mrproper, then copy the .config file (mrproper wipes that out), then make. If you've really done a lot of source code changes, you may want to reinstall the kernel source. And, yeah, it's going to take a while to build but then you can make install, run lilo and you ought to be good to go (look through the README file in /usr/src/linux).

After you get that stuff done, you can edit the configuration (don't run make mrpropter again), use an editor or the gui utility and make from there (see the README). You don't need (nor do you want) to start from scratch -- start with the distribution configuration and then edit that to customize things, lots easier, that -- you know, get back to something that works then twiddle it, add the current stuff and the like.

Hope this helps some.

Last edited by tronayne; 12-03-2010 at 11:24 AM.
 
1 members found this post helpful.
Old 12-03-2010, 11:44 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Or you may be able to generate a .config file from the running kernel with zcat /proc/config.gz > .config_from_running_kernel. Definitely a better starting point than the "clean" kernel build environment's .config which has some strangely chosen (IMHO) defaults.
 
1 members found this post helpful.
Old 12-03-2010, 11:59 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
I am not knowledgeable enough to answer your specific questions but will contribute what I can, based on experience with 13.0 and 13.1 32- and 64-bit using GRUB.

If you have enough disk space you can save time on re-installing by backing up the OS file systems and then simply restoring; always nice to have a safety net.

I read a lot of HOWTOs etc. but found it hard to get started on kernel building until I found Alien Bob's page.

I use make install and have been able to revert to earlier kernels.

EDIT: having read H_TeXMeX_H's post below, I am reminded that I have always used a "local version" string.

Last edited by catkin; 12-03-2010 at 12:11 PM.
 
1 members found this post helpful.
Old 12-03-2010, 12:03 PM   #5
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Here's how I compile the kernel, after I grab the latest kernel from kernel.org and extract it to a stable location, I open a terminal there and run:

Code:
make mrproper
zcat /proc/config.gz > .config
make menuconfig
make -j4
su
make modules_install
installkernel
lilo
'installkernel' is a script I made:

Code:
#!/bin/sh
# installs kernel only, this should be run only from the kernel source directory

# make sure we are root
if test $HOME != '/root'
then
    echo 'ERROR: This script must be run as root' >&2
    # fail
    exit 1
fi

# remove the old
rm -f /boot/config.old
rm -f /boot/System.map.old
rm -f /boot/vmlinuz.old

# rename the present
mv /boot/config /boot/config.old
mv /boot/System.map /boot/System.map.old
mv /boot/vmlinuz /boot/vmlinuz.old

# copy in the new
cp arch/x86/boot/bzImage /boot/vmlinuz
cp System.map /boot
cp .config /boot/config

# change permissions of vmlinuz
chmod a-rwx,u+r /boot/vmlinuz

# shown checksums
echo
md5sum arch/x86/boot/bzImage /boot/vmlinuz
echo
md5sum System.map /boot/System.map
echo
md5sum .config /boot/config
echo

# success
exit 0
If you are installing the same kernel version, it is likely that the '/lib/modules/$(uname -r)' will be overwritten and you will NOT be able to boot the older kernel. So append a local version by going to General setup->Local version and imputing something there. This is how they get the '-smp' on some of them.

Make sure to have an entry in lilo for the older kernel.

System.map is important, use my script and it will copy it properly.
 
1 members found this post helpful.
Old 12-03-2010, 04:31 PM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,140

Rep: Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123
Quote:
Originally Posted by H_TeXMeX_H View Post
If you are installing the same kernel version, it is likely that the '/lib/modules/$(uname -r)' will be overwritten and you will NOT be able to boot the older kernel. So append a local version by going to General setup->Local version and imputing something there.
This is very important, and probably what the OP is missing.
Life will (should) be much easier then.

Do'h - just read catkins edit...

Last edited by syg00; 12-03-2010 at 04:33 PM.
 
1 members found this post helpful.
Old 12-03-2010, 08:02 PM   #7
Gaidal
LQ Newbie
 
Registered: May 2002
Location: Sweden
Distribution: Arch x64
Posts: 29

Original Poster
Blog Entries: 2

Rep: Reputation: 0
Thank you, those are all great helpful answers! With all this and Alien Bob's article I feel confident to give another shot.

Just one minor follow-up question: Let's assume that I am way too greedy for my own good and keep going back every time it works, trying to save another 8 bytes of memory... Seeing how overwriting the modules messed me up this time, can I recycle the custom string I'm experimenting on, or should I make it custom-133, custom-134 et c? If I want to really clean those up, would it be sufficient to rm -r /lib/modules/custom-2.6.xx.x, or will there be leftovers somewhere else?
I mean, it would be annoying if I unknowingly created the ultimate configuration one day and it didn't work because of conflicting old stuff from 283 previous attempts.

Now how do I mark this thread as solved...
 
Old 12-03-2010, 10:44 PM   #8
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by Gaidal View Post
... can I recycle the custom string I'm experimenting on, or should I make it custom-133, custom-134 et c? If I want to really clean those up, would it be sufficient to rm -r /lib/modules/custom-2.6.xx.x, or will there be leftovers somewhere else?
...
Now how do I mark this thread as solved...
It is useful to increment the custom string so you can boot an older version for investigation or backout. AFAIK it is sufficient to rm -r /lib/modules/2.6.xx.x-<local version(s)> and the corresponding files in /boot.

Threads can be marked SOLVED via the Thread Tools menu.
 
  


Reply

Tags
kernel



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Headers for custom kernels? miros84 Linux - Hardware 2 01-26-2010 06:28 AM
backward compatibility in kernels + custom kernels + more queries mmp_3341 Linux - Kernel 1 04-12-2007 07:28 AM
custom kernels... Why so hard? mm0204 Linux - Newbie 2 06-08-2005 04:09 AM
How to remove old kernels safely satimis Fedora 11 08-21-2004 08:06 AM
How do I safely remove old kernels? Amerist Linux - General 4 11-02-2002 10:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 04:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration