Compile a second Linux kernel

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

BYOD: What the people think http://t.co/syY7RSyR via @zite

Twitter to track users through widgets: Twitter has given details about tracking users across the internet, and ... http://t.co/Er6izMDp

@superjon_11 just be weary that's what causes them to explode http://t.co/6XSePS0j

SAP eyes cloud super network with Ariba buy
http://t.co/F7NtV2Ju

SA Health's journey to e-health http://t.co/tHAhRy9c

Govt CIO praises budget's $1bn IT investment: Despite a tighter 2012-13 Federal Budget, the government's chief i... http://t.co/sRO5U7C0

Bit more meat to this Global SI #salesforce announcement than earlier ones, still don't think they get it though! http://t.co/Eb386WFF

NSW Govt appoints Silicon Valley office head to represent Aussie tech. Is this useful or a good direction? http://t.co/icIl6GOq

#ABC #Bitcoin Miner tackled in minutes #ITSecurity #law http://t.co/ptOPKpOI

#NSW Govt announces shopfront in Silicon Valley http://t.co/oUEMM9zY #gov2au”. MT: @allisonhornery @johnW3LLS #gov2au

SA Health's journey to #ehealth – structural reform, workforce restructure & infrastructure
http://t.co/TTno9Td9 /via @zdnetaustralia

Goods Shopping Location Discount Of Japan's Largest Abroad Train Brands. Coach Escape Shelter 89% Off.We Entertain Jammed Items Such As A...

9 hours ago by befeffofs on Reservoir blogs: Fan fakes Tarantino diary

1963年ナイキの創業者フィル・ナイトが訪日、オニツカ(現アシックス)の経営陣を訪問。 最新の機能性や斬新なデザインによって、常に新しいもの求める若者たちの心を掴んできたナイキスニーカー。今回はエアジョーダンやエアマックスなど、ナイキスニーカーの歴史に欠かせない名品から今...

9 hours ago by Speerbprayexy on Reservoir blogs: Fan fakes Tarantino diary

9 hours ago by Ideoforie on Reservoir blogs: Fan fakes Tarantino diary

Ferragamo Shoes Is Distinguished Brand.Ferragamo Is So Baby Valuation Broaden, It Is Secure To Shopping Outlet Online Stores.Ferragamo Ba...

9 hours ago by axollaCrake on Reservoir blogs: Fan fakes Tarantino diary

We Are Specialty Fit out Miu Miu Handbags, Miu Miu Purse, Miu Miu Sunglasses And So On. Miu Miu Sale Online Big Reduction With No Trade O...

9 hours ago by MoxboowsVix on Reservoir blogs: Fan fakes Tarantino diary

Pay off Trainer Wallet&Coach Pocket In Our Coach Store With Sad Sacrifice And Finish Quality, Save 80% Off. Cheap Carriage Overnight bag ...

9 hours ago by Fefinfani on Reservoir blogs: Fan fakes Tarantino diary

クリスチャン ルブタンは靴職人としてのスピリットが強いことで有名で、インタヴューでは下記のように語っています。Christian Louboutin「私は女性に、私の作る靴をファッションとは別の領域のにある、美の対象としてみてほしい。靴というものはアクセサリーではなく、その...

9 hours ago by ganitaickexia on Reservoir blogs: Fan fakes Tarantino diary

Celine luggage,Celine carrier bag,pocketbook Celine,CELINE Celine is synonymous with trait and fastidiousness prevalent since founding in...

9 hours ago by unulseDralola on Reservoir blogs: Fan fakes Tarantino diary

From moi @zdnetaustralia: where are all the ICT jobs: http://t.co/p3e1Y26r via

SAP buys its way into the cloud party: Will it work?: Will SAP and Oracle's rollup strategy for cloud players wo... http://t.co/nPjHXHtH

10 hours ago by Elundaninulge on Reservoir blogs: Fan fakes Tarantino diary

RT @dataPlumbers: Combining @Ariba's network & @SAP's applications - "SAP eyes cloud super network with Ariba buy" http://t.co/jeMWEKpB

Gee zdnet gets this wrong, not often either. Heard of html5 @zdnetaustralia? http://t.co/TksSIP31 read comment 1

BYOD: What the people think http://t.co/iqfwr2R5 via @zite

Medicare Locals get $50m for e-health http://t.co/0Prqy7Q3 via @zdnetaustralia #fb #in

Normally would expect better from zdnet. I call BS. It appears that if you look at their decision it is about using HTML5 to develop thei...

10 hours ago by butterflyeffecs on Android fragmentation steers Vic Health

oBoDwZrOrsjUq //www.2012chanelbagsforsale.com]chanel handbags gWbyPIERM niLqoOE //www.2012chanelbagsforsale.com]chanel outlet hBaJhfpEu...

10 hours ago by khngmspwbzm on Deakin Uni opts for Cisco Unified Computing

RT @zdnetaustralia: South Australia's e-health journey is a tough one, but it first required a good foundation. http://t.co/ha4HV3y3 ^ML

RT @zdnetaustralia: Google has joined in on the chorus of organisations warning users about DNSChanger infections http://t.co/ysaIHiuG ^ML

SA Health's journey to e-health http://t.co/tsbfDYHd

“@jufemaiz : Ausgrid is trialling tech that allows the grid to report back on what might be wrong. http://t.co/ezB8ksXa ^ML” is this you?

RT @maverickwoman: Yammer gets into gamification with Badgeville: http://t.co/faPDDVYr #gamification RT @mobilelearning #yam

Chrome beats Internet Explorer in global Web browser race http://t.co/E2YsEvbO

SA Health's journey to e-health: Implementing e-health services for an entire state is a daunting task, but, as ... http://t.co/93FJNlE6

SA Health's journey to e-health http://t.co/3iMSd3nN

SA Health's journey to e-health: Implementing e-health services for an entire state is a daunting task, but, as ... http://t.co/Zl9T7kQL

SA Health's journey to e-health - ZDNet Australia http://t.co/lI1N44kB #ehealth

RT @zdnetaustralia: Google has joined in on the chorus of organisations warning users about DNSChanger infections http://t.co/ysaIHiuG ^ML

South Australia's e-health journey is a tough one, but it first required a good foundation. http://t.co/ha4HV3y3 ^ML

Hotel Wi-Fi investigation - http://t.co/luJqmD1T

Listened to a guy from SA Health chat about how to consolidate IT from 70 hospitals today. Snazzy stuff. http://t.co/IZxhpu5X

Govt CIO praises budget's $1bn IT investment http://t.co/HXx2LFDf via @zdnetaustralia

by http://t.co/vmlLt4bh: SA Health's journey to e-health: Implementing e-health services for an entire state is a... http://t.co/NVrBd9c5

Facebook investor to sue Nasdaq over alleged bungled orders: http://t.co/XGRsNzA4 ^LH

Combining @Ariba's network & @SAP's applications - "SAP eyes cloud super network with Ariba buy" http://t.co/jeMWEKpB

Akku Asus A32-K72 Original,Kompatibler Ersatz akku für Li-ion Asus A32-K72 Original Laptop Akkus Asus A32-K72 Original,A32-K72 Original...

12 hours ago by akkuakku on HP Compaq 6730b

It is great to see the NSW government taking this step, however there's plenty of home-grown talent loeaving or being rediverted due to l...

12 hours ago by Aceyducey on NSW Govt appoints Silicon Valley champion

But this is the thing. There are still plenty of good-quality graduates whose skills can raise seasoned professional eyebrows... if they ...

14 hours ago by techkid on Skills shortage: companies being too picky?

I wouldn't have called Vista cheesy. Its GUI was pretty slick (and indeed handed on to Windows 7). It was, however, poorly implemented, h...

14 hours ago by techkid on Microsoft admits Vista was 'cheesy'

Thanks Nelson, it should be right now.

-Michael.

14 hours ago by Mukimu on Ausgrid network to talk back to operators

I guess the mouse was a necessary evil at the time. I mean, yes, keyboard shortcuts in the right hands are faster than any mouse action (...

15 hours ago by techkid on Microsoft admits Vista was 'cheesy'

fyi google may always lie

15 hours ago by rt luvs youh on Google shows we're killing our language

they probaly always lie about in4mation bout people

15 hours ago by rt luvs youh on Google shows we're killing our language

$6.7million, now we know the price to the tax payer of a government IT project clean up. You've got to ask the question don't you: why o...

16 hours ago by Takenforgranted on Vic scraps HealthSMART system

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

1 day ago, CeBIT 2012 opens: photos

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

1 day ago, Lenovo ThinkPad 3G tablet (32GB)

Facebook Activity

Keep up with ZDNet Australia

ZDNet Events Calendar

ZDNet Events Calendar