TONYCAI.NET homepage | sitemap | contact me
 



 

Read My Articles On Just About Everything Computers.


How To: Linux: Custom Compile Kernel (Advance Users Only)
Description: Step By Step On How To Build Your Own Custom Compiled Kernel.

Required Software Downloads:

1.latest and the greatest kernel sources (current version 2.6.11.6 as of March 26, 05) from: http://kernel.org/

I would suggest to use mirrors for kernel sources download

2.latest sumbount sources (current version 0.9) form here
http://sourceforge.net/project/showfiles.php?group_id=81174

Note about SuSE kernel-of-the-day:

It is possible to either download pre-built kernel (but what would be the point?), or get the sources from here:

http://mirror.etf.bg.ac.yu/distributions/s...ay/x86_64/HEAD/

However I was unable to install SuSE kernel. I believe that the problem was that I have SATA drive and patched SuSE kernel was unable to deal with this configuration.

Additionally, the latest patched SuSE kernel requires mkinitrd-1.2.8
mkinitrd-1.2.8 is incompatible with kernel 2.6.8 which means that installing this version will remove your default kernel. If you have another copy, then that is o.k. But if not, then next time you will not be able to boot your system. Because vanilla kernel does not require mkinitrd-1.2.8 so I suggest to stick with vanilla until you know how to use SuSE kernel-of-the-day.


3.if you are happy owner of nVidia card, then you need nVidia drivers no older than version 1.0-7167. Earlier versions will not compile with kernels vanilla kernels later than 2.6.8 (SuSE test (kernel-of-the-day) kernel should not be a problem)
http://www.nvidia.com/content/drivers/drivers.asp

Software installed:
Gnu C (gcc)
make
binutils
util-linux
module-init-tools
e2fsprogs
jfsutils
reiserfsprogs
xfsprogs
pcmcia-cs
quota-tools
PPP
isdn4k-utils
nfs-utils
procps
oprofile

Now lets check hardware available:

1.open terminal window and enter:
#lspci
The output will look like this:
redwood:/home/broch # lspci
0000:00:00.0 Host bridge: nVidia Corporation: Unknown device 00e1 (rev a1)
0000:00:01.0 ISA bridge: nVidia Corporation: Unknown device 00e0 (rev a2)
0000:00:01.1 SMBus: nVidia Corporation nForce 250Gb PCI System Management (rev a1)
...................................................
redwood:/home/broch #

next, if not certain about CPU enter:
redwood:/home/broch # cat /proc/cpuinfo
the output will look like this:
redwood:/home/broch # cat /proc/cpuinfo
processor : 0
vendor_id : AuthenticAMD
cpu family : 15
model : 31
model name : AMD Athlon™ 64 Processor 3000+
stepping : 0
cpu MHz : 2025.032
cache size : 512 KB
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 pni syscall nx mmxext fxsr_opt lm 3dnowext 3dnow lahf_lm
bogomips : 4014.08
TLB size : 1024 4K pages
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management: ts fid vid ttp

redwood:/home/broch #

Now you are ready to make your own shiny kernel.

1.su to root
2.copy downloaded kernel source to /usr/src
3.unpack sources:
1.for bz2 issue
tar xfvj /path/to/linux-2.6.x.tar.bz2
2. for tar.gz issue
tar xfvz /path/to/linux-2.6.x.tar.gz
Which compression format you choose is entirely up to you, however bz2 is smaller
4.if you have patches unpack them:
gunzip patch-2.6.x.gz
5.change directory to linux: eg if that was source linux-2.6.11.3.tar.bz2 then enter directory: /usr/src/linux-2.6.11.3
6.patch kernel (if needed):
patch -p1 </path-to-patch./patch-2.6.x
7.Now very important: edit Makefile and add/change the line:
EXTRAVERSION = -unique_name (pay attention to “-” sybmol in front of the name)
8.if this is not your first kernel then:
1. copy .config to e.g. your home dir
2. in the kernel directory enter:
redwood:/home/broch #make clean && make mrproper
9.now it is time to configure kernel
1.exit to user login and login again to su but this time enter command sux which allow root to connect to xserver
~/sux
10.redwood:/home/broch #make xconfig
11.select your processor type, select preemptible kernel, de-select ipv6, networked FS (all that you don't use), system FS, bluetooth, isdn, ppp, USB devices, network card and so on. Remember that disk type and FS should be compiled directly into kernel not as a module
12.save file
13.edit .config file (dot at the beginning)
scroll down to the line:
CONFIG_BLK_DEV_RAM_SIZE and change value to 128000
save file (this is SuSE setting)
14.at prompt issue the following commands:
export CHOST="x86_64-pc-linux-gnu" IF AMD_64 -> If not see below!
export CFLAGS="-march=k8 -O2 -funroll-all-loops -funit-at-a-time -fpeel-loops -ftracer -funswitch-loops -pipe -fomit-frame-pointer -fweb"
export CXXFLAGS="${CFLAGS}"
export MAKEOPTS="-j2"
notes if you have 32-bit processor then you can use -O3 optimization. Don't use more that -O2 id you have 64-bit processor because either kernel will not compile or what is worse will generate faulty kernel.

CHOST: x86_64-pc-linux-gnu” – amd64
CHOST: “i386-pc-linux-gnu”
CHOST: “i686-pc-linux-gnu” Athlon XP or Intel PIV
CHOST:”i586-pc-linux-gnu”
-march=k8 AMD64
-march=athlon-xp
-march=i686
-march=i586
-march=i386
MAKEOPTS= will set number of concurrent threads. I have 1GB of RAM so I can run MAKEOPTS=”-j6”
however with 256MB RAM and 1GHz CPU try “-j2”
The settings above in bold font are for AMD64 CPU

15.lets start compiling kernel:

1.redwood:/home/broch # make bzImage
2.redwood:/home/broch #make modules
3.redwood:/home/broch #make modules_install
16.when everything is ready you have to move it to /boot
1.cp arch/x86_64/boot/bzImage /boot/vmlinuz-unique_name
2.cp System.map /boot/System.map-unique_name
3.and for future reference:
a)cp .config /boot/config-unique_name
4.note that i used
a)arch/architecture not /arch/architecture (no slash at the beginning
I copied .(dot)config to config
17.mkinitrd command. It is not needed for vanilla kernel but it is required for latest SuSE kernel. In caseof vanilla it will allow you to use nice bootsplash. Note that for SuSE kernel 2.6.11 you need mknitrd version 1.2.8
1.mkinitrd -b /boot -d /dev/sda2 -m 1024x768 -k /boot/vmlinuz-unique_name -i /boot/initrd-unique_name
unique_name is exactly the same for vmlinuz, System.map and config
it should be different from the kernel name in /boot
18.run the following command:
1.~/ cat /etc/fstab | grep /
you will see something like:
/dev/sda3 / reiserfs acl,user_xattr 1 1
/dev/sda2 / ext2 acl,user_xattr 1 2
................................................................................................
note your / device. In my case it is /dev/sda3

2.next run:
~/ ls -l /dev/sda3
you will see something like:
brw-rw---- 1 root disk 8, 3 2004-12-03 13:45 /dev/sda3
the numbers in bold are quite important, these will be different depending how hdd is attached

19.Now you are ready to modify GRUB (default SuSE boot loader, I don't know how to configure lilo)
1.run Yast “Control Center” -> System ->”Boot Loader Configuration”
press “Edit Configuration Files” button
2.add either as a first (then new kernel will be default, or second option:
###Don't change this comment - YaST2 identifier: Original name: linux###
title SUSE LINUX 9.2 YOUR_NEW_KERNEL_NAME (2.6.11.4)
kernel (hd0,1)/vmlinuz-unique_name root=0803
video=vesafb:ywrap,mtrr,noedid,nocrtc,1024x768-16@80 selinux=0 splash=silent
console=tty0 resume=/dev/sda1 desktop elevator=as showopts

NOTE: root=0803. It corresponds to the output of ls -l /dev/sda3. I have got 8, 3 and this is where it should be used.
You can try root=/dev/sda3 however in my case (SATA disk) kernel was unable to find the device, but it understood quite well device numbers.
NOTE: if you have IDE HD, then simply copy, settings from your original (default) kernel, remember though to change names of vmlinuz, initrd and system.map

3.add this line at the bottom of GRUB configuration:
###Don't change this comment - YaST2 identifier: Original name: failsafe###
title Failsafe -- SUSE LINUX 9.2 YOUR_NEW_KERNEL_NAME (2.6.11.4)
kernel (hd0,1)/vmlinuz-unique_name root=/dev/sda3 showopts acpi=off vga=normal noresume selinux=0 barrier=off iommu=noforce maxcpus=0 3

NOTE: vga=normal -> it will start vga video without any extra settings
NOTE value “3” at the end of the last line. It means that OS will start with init 3 (no GUI)
NOTE: I suggest that for each kernel added you add one “Failsafe” entry
NOTE: never remove from GRUB settings from your working kernel.

20.Save editor, and now lets test a new kernel. Restart computer

21.After restart, you should be presented with familiar menu of boot options. This time however select a new entry: “Failsafe” boot of a new kernel

22.If everything will go well you should see command prompt asking for login. Enter you user name and password. Next enter su and root password. Never ever login directly as root. This is very bad practice. And it suggest that you have to purge your bad windows habits.

23.If you will see after boot kernel panic. Don't worry, restart computer and boot your old and trusty default kernel.

24.Lets assume that your brand spanking new kernel worked (but it did not load nvidia module of course):

1.at the prompr enter your login and password, next su to root (never login as root!!)
2.cd to the directory where you downloaded latest NVIDIA kernel.
run:
redwood:/home/broch #sh NVIDIA-Linux-arch-version-pkg2.run
replace “arch-version” with current driver architecture and version
3.run:
redwood:/home/broch #modprobe nvidia
4.run:
redwood:/home/broch #sax2 -m 0=nvidia
“0” is zero
5.configure video
6.exit sax2 and restart computer:
redwood:/home/broch #shutdown -r now

25.After restart boot to the new kernel (not Failsafe)

26.This is the last part:
1.extract submount-0.9
2.redwood:/home/broch #cd /home/submount-0.9/subfs-0.9
3.redwood:/home/broch/submount-0.9/subfs-0.9 #make
4.redwood:/home/broch/submount-0.9/subfs-0.9 #make install
NOTE: no ./configure
5.redwood:/home/broch/submount-0.9/subfs-0.9 #cd /home/broch/submount-0.9/submountd-0.9
6.redwood:/home/broch/submount-0.9/submountd-0.9 #./configure
7.rredwood:/home/broch/submount-0.9/submountd-0.9 #make
8.rredwood:/home/broch/submount-0.9/submountd-0.9 #make install

27.Restart computer and select new kernel to boot. Now you have new kernel and video acceleration plus SuSE subfs fs to automount rmovable media. Remember that first time all must be mounted by root. Later user will be able to do that. Automount works too.

28.NOTE on IPv6
1.if you have removed IPv6 from kernel, SuSEfirewall2 will generate two benign errors:
FATAL: Module ip6table_filter not found.
FATAL: Module ip6table_manage not found.
2.If there are getting on your nerves you have to make following changes:
a)edit /sbin/SuSEfirewall2, find the line:
load_module ip_tables ip_conntrack ip_conntrack_ftp ip_nat_ftp ip6table_filter ip6table_mangle
and remove notions about IPv6:
load_module ip_tables ip_conntrack ip_conntrack_ftp ip_nat_ftp i
b)edit /etc/sysconfig/SuSEfirewall2
and change:
FW_IPv6=””
to
FW_IPv6=”no”
c)finally run (I am not sure if this step is necessary, though it will not hurt)
echo "alias net-pf-10 off" >> /etc/modprobe.conf
echo "alias ipv6 off" >> /etc/modprobe.conf

Sources:
http://kernel.org/
http://members.optusnet.com.au/ckolivas/kernel/
http://www.sepi.be/nitro.php
http://www.grsecurity.net/download.php
http://sourceforge.net/project/showfiles.php?group_id=81174
http://www.nvidia.com/content/drivers/drivers.asp
http://suse.cs.utah.edu/people/mantel/kernel-of-the-day/

Credits:
http://kerneltrap.org/forum?PHPSESSID=8b48...cd921ef03ae0890
http://www.suse.com/en/private/support/onl...p/mailinglists/
http://www.serverwatch.com/tutorials/article.php/3339551
http://linuxdevices.com/articles/AT3855888078.html
http://submount.sourceforge.net/
http://www.gnu.org/software/grub/
http://www-uxsup.csx.cam.ac.uk/pub/doc/sus...e_en/index.html

Questions:
Please contact me if you have any problems doing building your kernel.