kernel configuration and compilation

19
Configuring the Kernel By Buddhika Siddhisena Co-Founder & CTO THINKCube Systems Pvt. Ltd <bud at thinkcube.com> Member of LKLUG & FOSS.LK <bud at babytux.org>

Upload: bud-siddhisena

Post on 29-Nov-2014

12.256 views

Category:

Technology


0 download

DESCRIPTION

Presentation on configuring the compiling the Linux kernel

TRANSCRIPT

Page 1: Kernel Configuration and Compilation

Configuring the Kernel

ByBuddhika SiddhisenaCo­Founder & CTO

THINKCube Systems Pvt. Ltd<bud at thinkcube.com>

Member of LKLUG & FOSS.LK<bud at babytux.org>

Page 2: Kernel Configuration and Compilation

2

 Coverage

• What is the kernel

• Why customize?

• Obtaining the kernel source

• Quick compile HOWTO

• Configuring the kernel

• Loading/Unloading modules

Page 3: Kernel Configuration and Compilation

3

What is the Kernel

• What is the Kernel?• Linux is the Kernel• Developed by Linus Torvalds in1991•  Modular kernel as opposed to a micro­kernel• Ported to more than 20 architectures• Over 6M lines of code

Page 4: Kernel Configuration and Compilation

4

What is the Kernel

User space

Kernel space

Program GNU C Library

Virtual File System (vfs)

read()

syscall(SYS_read)

Filesystem drivers

Block device drivers

LinuxKernel

Page 5: Kernel Configuration and Compilation

5

Why customize?

• Most of the time you actually dont!

• Optimize to the hardware

• Optimize for the situation (desktop/server,low memory,SMP,64bit, diskless)

• Add an unofficial driver or feature

• Upgrade the kernel to the latest without waiting for your distribution.

Page 6: Kernel Configuration and Compilation

6

 Obtaining the Linux Kernel source

• Patched Kernel source can be obtained for your distro

• e.g.: linux­source­2.6.16 on debian

• Vanilla kernels via kernel.org

• Specially patched kernels such Andrew Morton's ­mm patched kernel and  Alan Cox's ­ac

Page 7: Kernel Configuration and Compilation

7

 Quick kernel compile

• You need to install the kernel development packages

• e.g.: gcc, make, binutils, ncurses, qt

• Extract the kernel source in /usr/src

• Optionally create a symlink

• Quick configuration using an old configuration

• Compiling the kernel

linux:# tar jxvf /tmp/linux­2.6.16.8.tar.gz

linux:# ln ­s /usr/src/linux­2.6.16.8 /usr/src/linux

linux:# cp /boot/config­2.6.14 .config

linux:# make oldconfig

linux:# make && make install && make modules_install

Page 8: Kernel Configuration and Compilation

8

 Configuring the Kernel 101

# make menuconfig

# make config

OR

# make xconfigOR

OR If you are INSANE!# vi .config

Page 9: Kernel Configuration and Compilation

9

 Configuring the Kernel 101

But WHAT if you make a MESS and want to CLEAN UP?

Just use Mr. Proper# make mrproper

 This will clear all pre­compiled binaries as well as remove the .config file# make clean

 Just clean all pre­compiled binaries

Page 10: Kernel Configuration and Compilation

10

 Configuring the Kernel 101

Module or Built-in (Static)?

 Building drivers into the kernel makes the kernel FAT – require more memory and overall slower execution.

YET certain drivers are better of being built­in (e.g: motherboard drivers)

 Building drivers as modules results in a thinner kernel that can load external modules as an when needed.

BUT make sure your kernel has access to essential drivers required to boot, through an initrd or making them built­in.

Page 11: Kernel Configuration and Compilation

11

 Configuring the Kernel 101

• To see whats plugged into your motherboard, or USB ports.

• To check your processor and memory

• To see your hard drive partitions.

• To see your kernel log

linux:# lspci ­vlinux:# lsusb

Know your Hardware

linux:# cat /proc/cpuinfolinux:# cat /proc/meminfo

linux:# fdisk ­l

linux:# dmesg

Page 12: Kernel Configuration and Compilation

12

 Configuring the Kernel 101

• Code Maturity Level Options

You will find options to compile alpha quality or experimental drivers. Generally fine for a desktop system, but use with care for a production quality server.

• General Setup

Options to enable process accounting, optimize the kernel for size or have .config support that allows you to see how the kernel was configured (zcat /proc/config.gz).

• Loadable Module Support

Its generally a good idea to enable this. If you will need third­party kernel modules you will also need to enable Set Version Information on All Module Symbols.

Kernel config overview

Page 13: Kernel Configuration and Compilation

13

 Configuring the Kernel 101

• Processor Type and Features

Included in this submenu are features such as Processor type, Preemptible Kernel which can improve desktop responsiveness, Symmetric Multi­processing Support for machines with multiple CPUs, and High Memory Support for machines with more than 1G of RAM.

• Power Management Options

Found here are options for ACPI and CPU Frequency Scaling which can dramatically improve laptop power usage

• Bus Options ( PCI, PCMCIA, EISA, MCA, ISA)

Here are found options for all system bus devices. On modern machines the ISA and MCA support can often be disabled.

Kernel config overview

Page 14: Kernel Configuration and Compilation

14

 Configuring the Kernel 101

• Networking

Options to configure network protocols, firewalls, IR, Bluetooth etc.

• Device Drivers

Features such as SCSI support, graphic card optimizations, sound, USB, network cards and other hardware are configured here.

• File Systems

 Found here are options for filesystems which are supported by the kernel, such as EXT3, ReiserFS, NTFS or VFAT. It is best to build support for the root filesystems directly into the kernel rather than as a module. 

• Security OptionsInteresting options here include support for NSA Security Enhanced Linux and other, somewhat experimental, features to increase security. 

Kernel config overview

Page 15: Kernel Configuration and Compilation

15

 Configuring the Kernel 101

• Normally, “preemption” can happen only at the “user space”

• For a system to be responsive, kernel space preemption needs to be turned on.

<*> Preemptible kernel

• Do not turn on kernel preemption in server systems

Kernel Preemption

Optimize for processor architecture

• You can optimize the kernel for your exact processor as shown by /proc/cpuinfo

Processor family (Pentium­4/Celeron(P4­based)/Pentium­4 M/Xeon)  ­­­>

• You could also turn off Generic x86 support

< > Generic x86 support

Page 16: Kernel Configuration and Compilation

16

 Configuring the Kernel 101

• You can add file system drivers via the File systems menu.

DOS/FAT/NT Filesystems  ­­­>    <M> VFAT (Windows­95) fs support  <M> NTFS file system support

• Generally you should make the root file system built­in

• If you want to mount network file systems such as NFS or CIFS you can enable it here.

Network File Systems  ­­­>  <M> SMB file system support (to mount Windows shares etc.)

FS drivers

Enable High memory

• By default the kernel can access only about 890MB. If you have 1GB or more memory you need to enable high memory.

<*> High Memory Support (4GB)

Page 17: Kernel Configuration and Compilation

17

 Configuring the Kernel 101

Magic Sys rq

• On a desktop system Turn on Magic SysRq key in kernel hacking

<*> Kernel debugging<*> Magic SysRq key

• In the unlikely event of a system ?crash? (not responding), press Alt + PrtSc and other keys to reduce the damage:

Alt + PrtSc + S  :  flush buffersAlt + PrtSc + U  :  remount disks read onlyAlt + PrtSc + O  :  power offAlt + PrtSc + B  :  reboot

Page 18: Kernel Configuration and Compilation

18

Manually loading Linux device drivers

•  To list modules that are currently loaded you can issue

• To list available modules (compiled) for the current kernel

• To get a small description about a module ...

• To load a kernel module driver manually

• To load a kernel drive automatically as the machine boots consider adding it to /etc/modules.conf (2.4) or /etc/modprobe.conf (2.6)

#lsmod

#modprobe ­l

#modinfo radeon

#modprobe radeon

Page 19: Kernel Configuration and Compilation

19

 Happy compiling...

Thank You

&Happy compiling ...