Compile a second Linux kernel

Related gallery

Mint Linux 12 Lisa

Mint Linux 12 Lisa

If you read my last article on kernel compilation, "Compiling (or recompiling) your Linux kernel," you should be able to recompile your existing kernel without a hitch.

But what if you wanted to test a newer kernel or make changes to your existing kernel without destroying your currently running-just-fine kernel? Where there is a will, there's almost always a way when it comes to Linux.

I was once faced with a sticky situation where I wanted to take advantage of a CD-RW, but I knew that compiling that into the kernel would break another function of the kernel. In order to get around that mess, I decided to compile a kernel to take advantage of the CD-RW, leaving the current kernel intact. With this set up, I was able to reboot and choose which kernel (which functionality) I wanted to use, depending on the task at hand.

This Daily Feature is going to show you how to create the same set up by adding a second (or third, or however many you wish) kernel to your Linux box.

What you will need

You will need a working Linux machine (of course), a connection to the network (if you plan to download a new kernel), the full source for the kernel you wish to compile, root access to the Linux box, and a little time (depending on the speed of your machine, this could be half an hour to an hour, approximately). You will also need a working X graphical environment if you want to take advantage of the easier xconfig tool (not necessary for kernel compilation).

There are a number of places to grab the source for the Linux kernel. The most popular place is Kernel.org.

Before you start

In order to preserve your current working kernel, it's always best to take a few preventive steps. Before I unpack a kernel in /usr/src, I always copy the tar file to the /tmp directory, unpack it, and check to make sure the base directory of the package isn't linux. The reason for this step is that many distributions use a /usr/src/linux sym link to point to the current kernel's source. Overwrite that sym link and you could find yourself in big trouble. So, if the new kernel unpacks in a directory akin to linux-2.4.17, you are in good shape and can unpack that file in /usr/src.

If you unpack the kernel and see that the base directory is linux, you will want to unpack the new kernel in the /tmp directory and then move it to /usr/src, renaming it to (in this case) linux-2.4.17 with the commands:

mv linux-2.4.17.tar.gz /tmp
cd /tmp
tar xvzf linux-2.4.17.tar.gz
mv linux /usr/src/linux-2.4.17
cd /usr/src/

You will also need to know what boot loader you are using. You will have chosen this during installation. If you use Red Hat Linux and you are using any version prior to 7.2, your boot loader will most likely be LILO. If you are using Red Hat 7.2, you will probably be using GRUB. If you are using a newer Mandrake Linux, you will be using GRUB. SuSE Linux takes advantage of LILO, as well as Debian.

The last and most important thing is to make sure you have a working copy of your boot floppy around.

Let's get started

For the purpose of this article, you are going to be compiling a 2.4.17 kernel. The first thing you are going to do is unpack the kernel archive into /usr/src. You will need root access to do this (as well as the rest of the steps outlined in this article).

If you haven't already unpacked your kernel, do so (as outlined above). Once that kernel is unpacked, change to the linux-2.4.17 directory and get ready to compile.

The most time-consuming step in kernel compilation is choosing what you want to add or remove from the kernel. To do this, you will run one of the various available styles of make, which are:

  • make config
    This is a text-only selection process. This process will be a long series of questions that you answer with a Y (for "Yes, install"), an N (for "No, do not install"), or an M (for "Install as a module").
  • make menuconfig
    This style is an ncurses-based menu selection process. This type of make is much easier than make config, but it is not point-and-click but rather tab-and-select.
  • make xconfig
    This is the most common kernel configuration. It is a total GUI point-and-click experience. This style is the least time-consuming and the most user friendly.


Let me introduce you to Mr. Proper
If this is the first time this kernel is being compiled, you can immediately move to the make dep command. If, however, this is either a second attempt at compiling or a recompile, you'll need to run the make mrproper command before running make xconfig.

During this process, you will go through the various sections (and subsections) selecting (or unselecting) the various modules available in that kernel.

Once you have made all your selections, save the new kernel configuration and get ready for the compilation.

Compiling the kernel

The kernel compilation process is actually just a set of commands that are run in a very specific order. As root, you will want to run the following commands:

make dep
make clean
make bzImage
make modules
make modules_install

Some of the above steps will take a bit longer than others and, depending upon the machine, could take anywhere from two minutes to 30 (my best and worst times using a p200pro and athlong 1-GHz processor, respectively). Once the compilation is complete, you need to copy a couple of files over to the /boot directory, add entries into your boot loader configuration file (and run the boot loader command if needed), and then you are ready to boot into your new kernel.

Copying the correct files

If you change into the /usr/src/linux-2.4.17/arch/i386/boot directory, you will find a file called bzImage. This file needs to be moved over to the /boot directory and renamed vmlinuz-2.4.17.This can be achieved with:

cd /usr/src/linux-2.4.17/arch/i386/boot
cp bzImage /boot/vmlinuz-2.4.17

The next file to copy is the System.map file. This file is located in /usr/src/linux-2.4.17/ directory. Like the bzImage file, the System.map file must be renamed when moved. Follow these commands:

cd /usr/src/linux-2.4.17
mv System.map /boot/System.map-2.4.17

You are nearly finished.

These boots are made for...

The final step is making your boot loader aware of the new kernel. If you are using LILO, you will need to add a new entry to /etc/lilo.conf and then rerun /sbin/lilo (as root). The lilo.conf entry will look like:

image=/boot/vmlinuz-2.4.17
label=2.4.17
read-only
root=/dev/hda2

With this addition to the lilo.conf file in place, run (as root):

lilo

and the process is complete. You can now boot up and select 2.4.17 as your kernel.

If you are using the GRUB boot loader, you only have to add the new entry into the /boot/grub/menu.1st file. This entry looks like:

title 2.4.17.tar.gz
root (hd0,0)
kernel /vmlinuz-2.4.17

With this entry in place, you are ready to reboot.

Wrap it up

This method of kernel compilation will ensure that not only will you be able to test newer kernels or newer features (or even add some older features) but you will also have a working kernel on your machine. Granted, it's ill-advised to tinker around with the kernel of a production machine (unless you know exactly what you are doing) but the process outlined above will make kernel compilation a whole heck of a lot safer.

Editorial disclaimer: The authors and editors have taken care in preparation of the content contained herein but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for any damages. Always have a verified backup before making any changes.

TechRepublic is the online community and information resource for all IT professionals, from support staff to executives. We offer in-depth technical articles written for IT professionals by IT professionals. In addition to articles on everything from Windows to e-mail to fire walls, we offer IT industry analysis, downloads, management tips, discussion forums, and e-newsletters.

©2001 TechRepublic, Inc.

Talkback

Add your opinion

In order to post a comment, you need to be registered. (Sign In or register below)

Post your comment

Terms of Service - As a ZDNet registrant, and by using this service, you indicate that you agree to our Terms and Conditions and have read and understand our Privacy Policy.

ZDNet Australia Live

More TV Now may mean less TV later http://t.co/w805DQXk via @zdnetaustralia

Qld releases NBN strategic plan http://t.co/Wl9i4s6w

Are ebooks taking away our freedom? http://t.co/DpaeRReX

Cyber attack is the new #NuclearBomb. Shut down the country's infrastructure and that's the war WON... Look at the... http://t.co/9nJXOmX0

Full Spectrum: getting tough on telcos: The standard of telecommunications customer service has been a sore poin... http://t.co/XiL2fytU

What fibretech seems to be saying is that it shouldnt be enough that 93/97% get better than satellite. 100% should. If I've misread you...

40 minutes ago by Gav on NBN Co inks $620m satellite deal

RT @damiencummings: Does Facebook accurately count users? http://t.co/KLSlJsgO

Ansell comes back from IT **** up: Ansell has said it is rectifying problems with its new business processing sy... http://t.co/wPyaBdO6

RT @zdnetaustralia: Is the telco code enough, or does the regulator need to step in? http://t.co/iLgTOdX7

Ansell comes back from IT **** up - Ansell has said it is rectifying problems with its new business processing syste... http://t.co/7QH6c8Oq

What is missing from the code is a ban on the telcos creating their own funny-money by offering (say) "$500 worth of calls for $50" (and...

54 minutes ago by MaudeLynne on Telco customer code goes to the regulator

@joshgnosis who is responsible for this? that is one hell of a #newspun !!! http://t.co/9dd7tvx3

Open source needed to save democracy - Software - News - ZDNet Australia http://t.co/nH2C1VPb

Ansell comes back from IT **** up: Ansell has said it is rectifying problems with its new business processing sy... http://t.co/hVtbecMH

Spamvertised 'Tax information needed urgently' emails lead to malware http://t.co/ma7weWG1

Does Facebook accurately count users? http://t.co/KLSlJsgO

by http://t.co/vmlQ0Ecb: Ansell comes back from IT **** up: Ansell has said it is rectifying problems with its ne... http://t.co/UJdAxaMX

Tech? Done in days. Business model? A little longer :-) Finally! LoadRunner, more #agile than ever in #AWS and #vcloud http://t.co/O8ZaBty3

#trollDay “@lukehopewell: Our headline of the year: http://t.co/ldugUO77

RT @mwyres: #trollDay “@lukehopewell: Our headline of the year: http://t.co/ldugUO77

You may not realise but massive numbers of metro suburban citizens cannot currently get broadband and many more cannot get anywhere near ...

1 hour ago by harryinthesoup on NBN Co inks $620m satellite deal

RT @stilgherrian: SOPA/PIPA fail, studios try anti-piracy 'charm offensive'. http://t.co/xuqzY3Rm

"If you are trying to trace with the ftp trick it's just worthless." Hackers: $50,000 to keep source code private - http://t.co/x4BBGyav

Malware's the next nuclear bomb: Kaspersky: Governments have begun to create malware in the form of cyberweapons... http://t.co/VpOaDbIR

Malware's the next nuclear bomb: Kaspersky - ZDNet Australia http://t.co/dubHKvUX #B

NBN Co inks $620m satellite deal http://t.co/qgNiZcFH

Does Facebook accurately count users? http://t.co/hQcOtd2s via @zdnetaustralia

by http://t.co/vmlQ0Ecb: Malware's the next nuclear bomb: Kaspersky: Governments have begun to create malware in ... http://t.co/KfveHrKX

Malware's the next nuclear bomb: Kaspersky http://t.co/wJTLAbCP (via @Shogannai)

I guess we will hear more about this in the future..

1 hour ago by borrisz0r on Cochlear implant recall costs over $100m

Malware is the next nuclear bomb: Kaspersky http://t.co/j3oBGlxc

Malware's the next nuclear bomb: Kaspersky http://t.co/ILhLnszV

RT @zdnetaustralia: Malware is the next nuclear bomb: Kaspersky http://t.co/j3oBGlxc

Govt mulls closing Optus TV loophole - In the wake of Optus' victory over the sporting codes in its TV Now case, spo... http://t.co/6PxhKfB2

Can't believe how quickly things are happening on operation kill TV Now http://t.co/BK3Ecj1D

RT @zdnetaustralia: NBN Co inks $620m satellite deal: http://t.co/LsbQBeXL

Yahoo loses board chairman in reshuffle: By Josh Lowensohn, http://t.co/lS9JInfl on February 8th... http://t.co/R2FuBaYx #dualstack #ipv6

Rights holders lobbying for a quick change to the copyright act in the wake of the Optus TV Now case. http://t.co/dZAkzp0f #optusnrl

This is my point of view and like I said I cannot please everyone and I'm not going to try. Nor am I arguing about the economics, what I...

2 hours ago by fibretech on NBN Co inks $620m satellite deal

Govt mulls closing Optus TV Now loophole: http://t.co/mWyxcaNm

@chrispilgrim: Do you know how much it costs currently to get top tier NBN speeds in Surry Hills (basically 3 or 4 kms from the CBD)? It...

2 hours ago by gammprog on Libs would wind back NBN to fund roads

My yahoo account has been down all day, and I use it to run my business. If you call Yahoo, they will set up your MS Outlook account to h...

2 hours ago by tenderfoot on Yahoo Mail suffers overnight outage

fibretech, that's totally wrong. The metro users of the NBN will be subsidizing the NBN services in the regional zones because they co...

2 hours ago by tsudo77 on NBN Co inks $620m satellite deal

I know many people won't like this (not that you can please everyone anyway) but in one word "Equality"

2 hours ago by fibretech on NBN Co inks $620m satellite deal

What's the alternative fibre tech?

2 hours ago by mwil19 on NBN Co inks $620m satellite deal

@Spiraldeath Don't you think every tax payer deserves the same level of QOS? After all these people are leaders in primary industry whic...

2 hours ago by fibretech on NBN Co inks $620m satellite deal

@Fibretech so how would you propose to give broadband to a residence that is out in the middle of the Australian Desert and there is not ...

2 hours ago by Spiraldeath on NBN Co inks $620m satellite deal

Satellite technology is always a backward step when it comes to providing broadband. No matter how much bandwidth satellite provides the ...

3 hours ago by fibretech on NBN Co inks $620m satellite deal

I'm doing an assignment at my school about whether Facebook should have age restrictions; I think that even if you put an age limit on fa...

3 hours ago by Student onetwothree on Facebook to get age bans, parent control?

More TV Now => More mainstream fanbase in the future => More revenue streams from complementing products and accessories e.g. shirts, sho...

3 hours ago by pcr on More TV Now may mean less TV later

Shame on the Pilot, a company which employed him and gave him livelihood now he wants to sue the company. What if it was his personal lug...

3 hours ago by karan.vinayak on Pilot sues Virgin for being iPad Luddite

is Australian Cloud a puplic traded co. and if so what are the stock symble
thanks perry222

4 hours ago by perry222 on Australian clouds compared

I could care less about mobile footy coverage but if it wipes out Ray Warrens inane bleatings after forty years of aural misery I am all ...

5 hours ago by btone on More TV Now may mean less TV later

5mb/s calculates out to 625kb per second which means that a 1mb eMail will go out in under 1 second. Why isn't this fast enough ?

5 hours ago by deandari on Optus unveils NBN small business plans

PS. Living in Europe.

6 hours ago by Sparcosso on Chrome for Android finally arrives

This story has been voted 20 times in the last 24 hours!

20 hours ago, Symantec confirms hacker extortion

This story has been voted 10 times in the last 24 hours!

21 hours ago, Symantec confirms hacker extortion

Facebook Activity

Keep up with ZDNet Australia

ZDNet Events Calendar

ZDNet Events Calendar