Showing posts with label Compile. Show all posts
Showing posts with label Compile. Show all posts

Tuesday, 25 January 2011

How to compile a kernel from kernel.org in Fedora 14

This quick guide will show you how to compile and install a kernel from kernel.org in Fedora 14.

Start


Open a terminal and work through the below list of commands. Modify where appropriate.


Install the following packages

su -c 'yum install rpmdevtools yum-utils gcc make ncurses-devel'

Setup your build environment

rpmdev-setuptree

Download and extract your Kernel source

cd ~/rpmbuild/SOURCES

wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.37.tar.gz

tar -xf linux-2.6.37.tar.gz

Configure and Compile it

cd linux-2.6.37

make menuconfig

export CONCURRENCY_LEVEL=3

time make rpm

General rule for concurrency level = number of processor cores + 1


Install it

cd ~/rpmbuild/RPMS/x86_64

su -c 'rpm -ivh --force kernel-2.6.37-1.x86_64.rpm'

cd /boot

su -c 'mkinitrd initramfs-2.6.37.img 2.6.37'

su -c 'vi grub/grub.conf'

Fedora 32-bit users replace x86_64 with i386

Edit your grub.conf file and add an entry for your new kernel. Just copy your first kernel entry and modify it.

Note: Please do not copy this grub.conf, it is for illustrative purposes only.

# 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,0)
#          kernel /boot/vmlinuz-version ro root=/dev/sda1
#          initrd /boot/initrd-[generic-]version.img
#boot=/dev/sda1
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu

title Fedora (2.6.37)
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.37 ro root=UUID=162b11c2-d9a1-4487-86d5-6ade5c5ee055 rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=uk rhgb quiet
        initrd /boot/initramfs-2.6.37.img

title Fedora (2.6.35.10-74.fc14.x86_64)
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.35.10-74.fc14.x86_64 ro root=UUID=162b11c2-d9a1-4487-86d5-6ade5c5ee055 rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=uk rhgb quiet
        initrd /boot/initramfs-2.6.35.10-74.fc14.x86_64.img

title Fedora (2.6.35.6-45.fc14.x86_64)
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.35.6-45.fc14.x86_64 ro root=UUID=162b11c2-d9a1-4487-86d5-6ade5c5ee055 rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=uk rhgb quiet
        initrd /boot/initramfs-2.6.35.6-45.fc14.x86_64.img

title Other
        rootnoverify (hd0,4)
        chainloader +1

Boot from your new kernel


Restart your system and enjoy your new kernel.

Monday, 3 May 2010

How to compile a kernel on Ubuntu 10.04

The Ubuntu wiki does provide the necessary documentation to allow users to build their own Linux kernel but in a rather disorganised way.

They should restructure it and provide clear detailed steps for each release and not the current mish-mash of old and new.

How about giving each release their own dedicated wiki page?

Original Ubuntu wiki: https://help.ubuntu.com/community/Kernel/Compile

First steps

Install the required tools and packages.

Open a terminal and type the following,

sudo apt-get install fakeroot kernel-wedge build-essential makedumpfile kernel-package libncurses5 libncurses5-dev

Then run the following command,

sudo apt-get build-dep --no-install-recommends linux-image-$(uname -r)

And finally type,

mkdir ~/src
cd ~/src
apt-get source linux-image-$(uname -r)
cd linux-2.6.32

At the time of writing 2.6.32 was the current kernel source, it should remain at this version throughout the life of Ubuntu 10.04

It is a good idea to start with the same .config as the currently running kernel, so type the following,

cp -vi /boot/config-`uname -r` .config

Now we are ready to customize the build and kernel options.

make menuconfig

Once you have finished, save and exit. It is now time to compile. However to speed up the build if you have a dual core processor type,

export CONCURRENCY_LEVEL=3

The general rule is 1 + the number of processor cores.

make-kpkg clean
fakeroot make-kpkg --initrd --append-to-version=-some-string-here kernel-image kernel-headers

Remember to substitute the writing in green for something else, for example -alpha

After a few minutes or hours your kernel compile will be complete. The next step is to install it.

The kernel package will be created in the parent directory of ~/src/linux-2.6.32 (i.e. ~/src)

cd ~/src
sudo dpkg -i linux-image-2.6.32.11+drm33.2-alpha_2.6.32.11+drm33.2-alpha-10.00.Custom_amd64.deb
sudo dpkg -i linux-headers-2.6.32.11+drm33.2-alpha_2.6.32.11+drm33.2-alpha-10.00.Custom_amd64.deb

Please note the text in green must be changed to reflect your version.

We are almost ready, prior to 10.04 the initramfs kernel image was automatically created. The Ubuntu wiki suggests using the scripts to create the image but I have been unsuccessful in using this method, hence the manual approach.

sudo update-initramfs -c -k all

BUG:  Please use the alternate method described below as this command fails to create an image for your new kernel. Special thanks to Helios38. - 16/06/2010


Alternatively if you know the kernel version, substitute the word all with the kernel version.

Example, sudo update-initramfs -c -k 2.6.32.11+drm33.2-alpha

Finally we need to add the initramfs image to the grub.cfg file located at /boot/grub/grub.cfg.

For the easy and automatic method as oppose to manually editing the grub.cfg file, just type the following,

sudo update-grub

Now just reboot and your new kernel should automatically load.

How to remove your  kernel

sudo dpkg -r linux-headers-2.6.32.11+drm33.2-alpha
sudo dpkg -r linux-image-2.6.32.11+drm33.2-alpha
sudo rm /boot/initrd.img-2.6.32.11+drm33.2-alpha

Enjoy compiling your own kernels.

Monday, 12 April 2010

OpenSUSE 11.2 - How to compile a Kernel for Newbies

There are many reasons to compile your own kernel, for example adding hardware support, improving system performance or just for educational purposes.

Methods vary across distributions and within distributions there are also different ways to compile the kernel.

I am going to show you how I compile a kernel on OpenSUSE 11.2.

Important: It is assumed proprietary ATi or Nvidia drivers are not installed. If you have such drivers installed and boot into your new kernel, X will crash!

Here we go...

First we need the kernel source and various development tools such as GCC.

Yast > Software Management > View patterns > tick 'Linux Kernel Development' > Accept

This will download and install what you need. At the time of writing the current OpenSUSE Kernel source was version 2.6.31.12-0.2.1, reference to such has been made throughout.

Open a terminal and type the following

su -
cd /usr/src/linux

We are now into our Linux source directory with root privileges and must create a config file for our kernel.

It is a good idea to use the same config that is being used by the OpenSUSE kernel which you are using right now, then fine tune it to your needs later on.

To use the same config file type the following,

make cloneconfig

With our config file we can now start editing the kernel by typing the following,

make menuconfig

This is the fun part, you can go through all the kernel options and change whatever you wish. I won't tell you what to change, that is completely down to you.

Changing some options may cause a broken kernel and / or Kernel Panic!

Tip: Highlight any option and press h. This will show information about the selected option.

When you have finished playing around, exit and save your changes.

Remember to give your kernel a different name, edit the following kernel option

General Setup ---> Local version - append to kernel release

Type anything you wish, for example

-modified

Building the Kernel

This part can take a while depending on your processor. Compiling also puts a high load on your processor as well as stressing the system, causing temperatures and power consumption to increase.

If you are unable to successfully compile a 100% default and unchanged kernel due to a compilation error, there is a high possibility your system has a weakness.

It could be due to many things, for example a hot running processor, motherboard chipset, PWM circuitry, memory, combination of all these, faulty memory, poor power supply.

To build your kernel as an RPM package type the following,

make rpm

You can watch the compile if you wish, maybe have a cup of tea...and biscuits!

When the compile has finished, the new kernel needs to be installed.

cd /usr/src/packages/RPMS/x86_64

If you are using the 32-bit OpenSUSE the new kernel will be located in the i386 folder.

cd /usr/src/linux/packages/i386

If you type in dir, you will see an rpm file, for example kernel-2.6.31.120.2modified-1.x86_64.rpm

To install it type the following,

zypper install NAME_OF_FILE.rpm

example, zypper install kernel-2.6.31.120.2modified-1.x86_64.rpm

Once it has been installed, type

cd /boot
mkinitrd

Now if you type dir whilst still in the /boot directory you should have the following 2 files,

vmlinuz-2.6.31.12-0.2-modified
initrd-2.6.31.12-0.2-modified

The NAME_OF_KERNEL in this example is 2.6.31.12-0.2-modified

The final part, is to edit the grub loader (using your favourite editor) to add our new kernel.

gedit /boot/grub/menu.lst

Example menu.lst

# Modified by YaST2. Last modification on Thu Apr  8 16:21:47 BST 2010
# THIS FILE WILL BE PARTIALLY OVERWRITTEN by perl-Bootloader
# Configure custom boot parameters for updated kernels in /etc/sysconfig/bootloader

default 0
timeout 8
##YaST - generic_mbr
gfxmenu (hd0,0)/boot/message
##YaST - activate

###Don't change this comment - YaST2 identifier: Original name: linux###
title Desktop -- openSUSE 11.2 - 2.6.31.12-0.2
root (hd0,0)
kernel /boot/vmlinuz-2.6.31.12-0.2-desktop root=/dev/disk/by-id/ata-SAMSUNG_HD502HJ_S20BJ1KSB14195-part1 resume=/dev/disk/by-id/ata-SAMSUNG_HD502HJ_S20BJ1KSB14195-part2 splash=silent quiet showopts vga=0x31a
initrd /boot/initrd-2.6.31.12-0.2-desktop


###Don't change this comment - YaST2 identifier: Original name: failsafe###
title Failsafe -- openSUSE 11.2 - 2.6.31.12-0.2
root (hd0,0)
kernel /boot/vmlinuz-2.6.31.12-0.2-desktop root=/dev/disk/by-id/ata-SAMSUNG_HD502HJ_S20BJ1KSB14195-part1 showopts apm=off noresume edd=off powersaved=off nohz=off highres=off processor.max_cstate=1 x11failsafe vga=0x31a
initrd /boot/initrd-2.6.31.12-0.2-desktop

Use the default OpenSUSE kernel entry as a template. In the above example menu.lst the green text will be our template.

Modify it to suit your needs.

###Don't change this comment - YaST2 identifier: Original name: linux###
title Desktop -- openSUSE 11.2 -
2.6.31.12-0.2
root (hd0,0)
kernel /boot/vmlinuz-NAME_OF_KERNEL root=/dev/disk/by-id/ata-SAMSUNG_HD502HJ_S20BJ1KSB14195-part1 resume=/dev/disk/by-id/ata-SAMSUNG_HD502HJ_S20BJ1KSB14195-part2 splash=silent quiet showopts vga=0x31a
initrd /boot/initrd-NAME_OF_KERNEL

The red parts must be changed with the exact name of your kernel.

For example, 2.6.31.12-0.2-modified

The orange bits can be left alone but to avoid confusion I suggest you change them. It can be anything you wish.

Then add the new entry to the menu.lst file.

# Modified by YaST2. Last modification on Thu Apr  8 16:21:47 BST 2010
# THIS FILE WILL BE PARTIALLY OVERWRITTEN by perl-Bootloader
# Configure custom boot parameters for updated kernels in /etc/sysconfig/bootloader


default 0
timeout 8
##YaST - generic_mbr
gfxmenu (hd0,0)/boot/message
##YaST - activate

###Don't change this comment - YaST2 identifier: Original name: linux###
title Desktop -- openSUSE 11.2 - 2.6.31.12-0.2
root (hd0,0)
kernel /boot/vmlinuz-2.6.31.12-0.2-desktop root=/dev/disk/by-id/ata-SAMSUNG_HD502HJ_S20BJ1KSB14195-part1 resume=/dev/disk/by-id/ata-SAMSUNG_HD502HJ_S20BJ1KSB14195-part2 splash=silent quiet showopts vga=0x31a
initrd /boot/initrd-2.6.31.12-0.2-desktop


###Don't change this comment - YaST2 identifier: Original name: My custom kernel###
title Desktop -- openSUSE 11.2 - 2.6.31.12-0.2-modified
root (hd0,0)
kernel /boot/vmlinuz-2.6.31.12-0.2-modified root=/dev/disk/by-id/ata-SAMSUNG_HD502HJ_S20BJ1KSB14195-part1 resume=/dev/disk/by-id/ata-SAMSUNG_HD502HJ_S20BJ1KSB14195-part2 splash=silent quiet showopts vga=0x31a initrd /boot/initrd-2.6.31.12-0.2-modified

###Don't change this comment - YaST2 identifier: Original name: failsafe###
title Failsafe -- openSUSE 11.2 - 2.6.31.12-0.2
root (hd0,0)
kernel /boot/vmlinuz-2.6.31.12-0.2-desktop root=/dev/disk/by-id/ata-SAMSUNG_HD502HJ_S20BJ1KSB14195-part1 showopts apm=off noresume edd=off powersaved=off nohz=off highres=off processor.max_cstate=1 x11failsafe vga=0x31a
initrd /boot/initrd-2.6.31.12-0.2-desktop

Exit the editor, reboot your machine.

When you see the grub menu, select your new kernel. If you want it to load by default, change the default option in the menu.lst file to 1.

I have highlighted the default option in purple.

0 corresponds to the 1st entry, 1 will correspond to the 2nd entry and so on.

Before recompiling another Kernel

If you wish to compile again, issue the following command whilst in the /usr/src/linux directory

make mrproper

This will clear any rubbish left from the previous compile and is necessary to prevent a make error.

How to remove your custom Kernels

You can use zypper to remove your kernel by typing,

zypper remove NAME_OF_PACKAGE

example, zypper remove kernel-2.6.31.120.2modified-1.x86_64

The .rpm at the end is not required and will result in a package not found error.

Next delete the initrd file created when we issued the mkinitrd command,

rm /boot/2.6.31.12-0.2-modified

And finally delete the now obsolete entry in the /boot/grub/menu.lst file.

Enjoy compiling your own Kernels!