A Guide to Recompiling the Kernel


Recommended Posts

Downloading and installing the kernel

The new kernel is quite easy to find and download. Follow these steps.

1. First, become root (use the: su command in a shell)

2. Go to The Linux Kernel Archives.

3. Download the Linux 2.6.xx kernel and save it to your /usr/src directory.

4. As root, run the following commands in the console. (Note: This assumes you've installed your Linux distribution with all the developer options. If you haven't, take a look at your distribution's website for more information on 2.6 kernel packages you can download.)

tar -zxvf linux-2.6.xx.tar.gz
cd linux-2.6.xx
make menuconfig

After your machine takes a bit of time to compose the menus, you should see the Linux kernel menu system. The menu gives you the ability to choose which options are included in your kernel. After choosing these options, you'll be able to compile your kernel.

Compiling the kernel

First, type in the following.

make bzImage

If you use LILO as your boot manager, then type the following.

make install

If you configured your kernel to use modules, which many people want to do, you'll need to type in the following command.

make modules
make modules_install

Hurry up and wait

If it's your first time building a kernel, keep the boot disk from the first time you installed your OS. It'll come in handy if you did something wrong when configuring your kernel!

Building the kernel can take a lot of time, depending on your machine's specs. Think in terms of at least a half-hour and you won't be far off. It's a big plate of spaghetti for your computer to munch on, so be patient.

The good news is that Linux is great at multitasking, so you can go surf the Web while the kernel compiles. And have fun!

Link to comment
https://www.neowin.net/forum/topic/149758-a-guide-to-recompiling-the-kernel/
Share on other sites

Not a bad guide. Perhaps if you could include a run down on the recommended options in the Linux Kernel Menu system? For newbies this can be a very daunting process. Remember. Always aim your guide towards first time users. Keep it as simplified as possible. Step by step instructions are a must!

A couple of things:

1) you want to untar the file with

tar -xvjpf linux.whatever

or

tar -xvzpf linux.whatever

It keeps the permissions correct. I don't know if the p is necessary for compiling and using, but it is a good practive for kernels

2) With the latest 2.6 kernels you only need to type

make

after the menuconfig. It will make the bzlmage and the modules. then type

make modules_install

3) You don't need to symling to /usr/src/linux. This is for the kernel headers. Actually it is advisable to have this linked to an older 2.4 kernel or a 2.4 header set for backwards compatibility. It will not mess up compiling anything if you set it to a 2.4 kernel. However the 2.6 kernel's headers are slightly different than normally expected by the compiler and its libraries.

4) you can run

make install

for both lilo and grub if they are set right.

5) For the menuconfig I suggest that you get a listing of all your hardware on a piece of paper and make sure that it is very detailed. Additionally you need to check with the distro to make sure that you don't need to add in extra stuff to make that distro work right. I know you need to with gentoo.

6) lastly if you don't choose make install to install the kernel, don't overwrite the last one. and if you choose make install it will over write the last kernel installed if it has the same name. For example if you have installed a 2.6.3 kernel and want to change some things and don't do anything to the kernel source (ie add patches) and re make the 2.6.3 kernel and choose make install the original 2.6.3 kernel will be replaced with the newer one. However you can change this in the make file in the base kernel source directory. it is in the extraversion options. I suggest you patch the kernel source to see what I am talking about because most patches will change the append on the end of the image files and system map files.

7) I am sorry if I confused anyone. Compiling your own kernel isn't difficult. However you have to make sure you configure it correctly in the menuconfig. Wierd things can happen, and at worse a kernel panic. But these are all fixable. Try to have another kernel for just in case your new one fails. Then you can boot with it at lilo or grub and you can fix whatever error you made.

I get Unexpected EOF in archive error

Most likely you downloaded a bad kernel source. download a new one and try again.

What about generate-modprobe.conf?

I've always had to do that in order to get everything working. Remember that you have to specify the output of the modprobe.conf file to the /etc dir tho.

Also I found make gconfig better than menuconfig, but I guess that is a matter of personal taste.

I'm not an expert but, like I think that like I said, make install will usually update grub for you so that the new kernel is listed on the statup menu.

For example here is my /etc/grub.conf file:

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: ?You do not have a /boot partition. ?This means that
# ? ? ? ? ?all kernel and initrd paths are relative to /, eg.
# ? ? ? ? ?root (hd0,4)
# ? ? ? ? ?kernel /boot/vmlinuz-version ro root=/dev/hda5
# ? ? ? ? ?initrd /boot/initrd-version.img
#boot=/dev/hda
default=0
timeout=10
splashimage=(hd0,4)/boot/grub/splash.xpm.gz
title Fedora Core (2.4.22-1.2174.nptl)
	root (hd0,4)
	kernel /boot/vmlinuz-2.4.22-1.2174.nptl ro root=LABEL=/ hdd=ide-scsi rhgb
	initrd /boot/initrd-2.4.22-1.2174.nptl.img
title Fedora Core (2.4.22-1.2115.nptl)
	root (hd0,4)
	kernel /boot/vmlinuz-2.4.22-1.2115.nptl ro root=LABEL=/ hdd=ide-scsi rhgb
	initrd /boot/initrd-2.4.22-1.2115.nptl.img
title Windows XP
	rootnoverify (hd0,0)
	chainloader +1

You see I have two different linux kernel entries (2.4.22-1.2174.nptl?& 2.4.22-1.2115.nptl)?

You could try manually adding the new kernel to the grub.conf file but to me it sounds like the install has not worked properly as it has always done this itself for me.

  • 3 weeks later...

For LILO try running the $lilo command from the terminal see if this adds the kernel to your config

Alternate

-----------

1.Assumes that you have "root" or "sudo"

Take a look in the "/boot" partition or file path depending on how you partitioned your drive.

use the following from your terminal of choice

$ls -F /boot

See what you have got there and double check that with your grub.conf file.

<snip>

kernel /boot/vmlinuz-2.4.22-1.2174.nptl ro root=LABEL=/ hdd=ide-scsi rhgb

initrd /boot/initrd-2.4.22-1.2174.nptl.img

title Fedora Core (2.4.22-1.2115.nptl)

root (hd0,4)

</snip>

Your output from the "ls" command should be able to be matched to one of your kernel entries,

ie..

If you have kernel named vmlinuz-2.4.22-1.nptl in your config file you should also have a file named

vmlinuz-2.4.22-1.nptl in your "/boot" directory. If for some chance your kernel image is not listed in

your "/boot" directory search for it then move it to your /"boot" directory manualy.

#Update your locate database

$updated

#Search for the kernel image

$locate vmlinuz-2.6.* | less

See what you can find, use the up & down cursor keys to navigate to the end of the results or until you

find what you are looking for, if you find the kernal image then move it to the "/boot" directory.

$mv -r /file.name/path/to file /boot

Repeat the above steps for the initrd image.

Now double check that your conf file and your kernel images line up. Restart the box to see if you get an option for the kernel at boot.

Hope this helps,

The_Geek

i did this question in other thread, but i guess i can repeat it here too because are pretty the same post...

wich is the diference in set to Built-in or Module on the kernel configuration when you enter the make menuconfig command?

that's all. thanks

built-in compiles the part into the kernel. modules compiles the part as an externel module that can be loaded or unloaded at any given time given the correct circumstances. Some parts need to be compiled in otherwise you risk a kernel panic, most doesn't and you need to experiment with those to determine the optimum settings for your computer.

I got a kernel panic :oops: :D

Couldnt mount the hard drive or something, which i imagine is pretty serious :p Im sure it just needs a little bit more care and adaptation from me, and i'll try later, but if anyone has any tips that would be appreciated.

Oh, by the way, im using SuSE and have been told that i shouldnt of just compiled 2.6.0 randomly and needed a SuSE-adapted kernel. How correct is this? Sounds a load of rubbish to me

Kongit - is there any speed advantage to using modules over compiled-in or do I have that back to front?

Specifically I'd like to improve the boot speed of the kernel as currently it takes 5 or 10 secs before my services etc start.

It depends. I for one have noticed no speed increase on boot with the exception of usb. I use hotplug (almost all distros do) so only the usb stuff that is plugged in at boot will be loaded. If you get your kernel properly configured and the modules that are supposed to load at boot properly configured then you will probably have the best in time for boot. However boot times for a normal linux user shouldn't matter as you stay booted for long periods of time.

It shouldn't make a difference between compiling in or as modules if everything is configured correctly for boot speed.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • DiskGenius 6.2.0.1829 - All Versions: Free, Lite & Portable by Razvan Serea DiskGenius is a full-featured partition manager, which is designed to optimize disk usage for Windows users. It will efficiently help you recover lost data, resize/split partition, backup files, edit hex data, check bad sectors, manage virtual disks, erase data, etc.. Create a system image backup for current Windows with simple clicks to keep the operating system under protection. DiskGenius key features: Partition Management - It can create format, resize, extend, backup, split, hide and clone partition, both MBR and GPT are supported. Disk and partition conversion - Convert dynamic disk to basic, convert virtual disk format and convert MBR to GPT, convert primary partition to logical. File recovery - It can recover files deleted or emptied form recycle bin, recover files from damaged partition or disk and recover files by file type and supports file preview and file filter. Partition recovery - It is the best partition recovery program in that it can recover files from damaged, corrupted and RAW partitions, search for lost partition and recover files from it, besides, it can fix partition table. RAID recovery - It can reconstruct Virtual RAID and recover files from it, and all RAID types are supported. Sector Editor - A Hex editor is embedded to help users edit raw hex data and recover data manually. Backup and Restore - It can backup and restore partition including system partition, hard disk and partition table. Bad Tracks - It can check and repair bad sectors for all storage devices; check hard disk S.M.A.R.T. information. Delete files permanently - It can delete files permanently so that they can't be recovered by any data recovery software. Virtual Disk - It supports virtual disks, including VMware, Virtual PC and Virtual Box. Create WinPE bootable disk and you can manage disk partition when system crashes or there is no operating system on your computer. Support FAT12/FAT16/FAt32/exFAT/NTFS/EXT2/EXT3/EXT4 file system format. DiskGenius 6.2.0.1829 changelog: Add the "Disk Speed Test" feature. Add the "Windows Boot Repair and Conversion" feature. Add the BMB21-2019 erase standard to the "Erase Sectors" feature. Add support for restoring an individual partition from a PMFX disk image file. Enhanced The "Verify Or Repair Bad Sectors/Blocks" feature displays disk read speed in the detection window during scanning. The "Quick Partition" dialog box allows users to quickly select the number of partitions by pressing the numeric keys 1, 2, 7, 8, or 9. The "Set Volume Name" dialog box supports selecting preset volume labels provided by the software. The "Copy Sectors" feature supports resuming copy tasks after modifying the number of skipped bad sectors. Add the "TRIM Optimization" option to the format dialog box. The "Clone Partition" and "Clone Disk" features perform TRIM optimization on target partitions or disks before cloning. Add support for Not Equal To search conditions (prefixed with "!") when searching hexadecimal data in the sector editor. Optimize the display of capacity values in the program interface to show two decimal places. Add a minimize button to dialogs that may require long processing time. Enhance support for the ReFS file system. Enhance support for newer HIF and MP4 formats when recovering files by type. Enhance support for the EXT4 file system. Enhance compatibility of the "File Recovery" feature with special data structures. Fixed Fixed the issue that the selected file system type automatically reverted to NTFS after changing it to exFAT or EXT4 in the "Quick Partition" dialog box. Fixed inaccurate Unicode string search results in the "Sector Editor" feature. Fixed the issue that exceptions might occur when adding multiple disks in the "Erase Sectors" feature. Fixed the issue that insufficient target disk space was incorrectly reported in some cases when cloning, backing up, or restoring disks. Fixed the issue that folder modification timestamps were not preserved when copying files from ReFS partitions. Fixed the issue that Excel-format reports generated by features such as file copying or bad sector checking could not be opened when the report contained more than one million rows. Fixed the issue that folders were not displayed in the exclude-folder dialog box when backing up partitions to image files. Fixed the issue that the "Erase Sectors" feature could not be executed in some cases. Download: DiskGenius 6.2.0.1829 | 63.9 MB (Freeware, paid upgrade available) Download: DiskGenius Portable 64-bit | 40.0 MB Download: DiskGenius Portable 32-bit | 36.0 MB Download: DiskGenius Lite 64-bit | 13.4 MB Download: DiskGenius Lite 32-bit | 11.6 MB View: DiskGenius Home Page | DiskGenius Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Really? Use a better search engine https://www.google.com/search?...ourceid=chrome&ie=UTF-8
    • Seems like Neowin has transitioned into being simps for the white house. I can't find a review for the last UFC games that came out.
  • Recent Achievements

    • Week One Done
      agatameier earned a badge
      Week One Done
    • One Month Later
      agatameier earned a badge
      One Month Later
    • Week One Done
      ssd21345 earned a badge
      Week One Done
    • Contributor
      MarkHughes4096 went up a rank
      Contributor
    • Dedicated
      jordanspringer earned a badge
      Dedicated
  • Popular Contributors

    1. 1
      +primortal
      513
    2. 2
      +Edouard
      182
    3. 3
      PsYcHoKiLLa
      143
    4. 4
      ATLien_0
      95
    5. 5
      Steven P.
      76
  • Tell a friend

    Love Neowin? Tell a friend!