address http://www.fogonacaixadagua.com.br/2009/09/how-to-compile-a-new-kernel-in-linux-centos-red-hat/ 2009.9.22 쓰여짐 * Home * Contact * Suggestion How to compile a new kernel (2.6.30.5) in Linux CentOS 5.3 / Red Hat 5.3 Posted by Daniel Kühl Lima in Featured Articles, Linux on 22/Sep/2009 | 0 comments You purchased a new hardware but the current kernel does not support it, or need to add functionality to the kernel that does not come from the factory. It is at those times that is necessary to compile a new kernel for the device to be recognized or a new functionality can be used by the software, for example. I will show you how to compile a new kernel on CentOS / Red Hat Linux. Pre-requisite * CentOS / RedHat 5.3 minimal installation (Portuguese only) Download latest kernel do Linux The latest version can be get straight from http://www.kernel.org/pub/linux/kernel/v2.6/ Downloading the kernel source (at this moment is 2.6.30.5) view source print? 1 wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.30.5.tar.bz2 After you have done it, extract to /usr/src view source print? 1 tar jxvf linux-2.6.30.5.tar.bz2 -C /usr/src view source print? 01 ... 02 linux-2.6.30.5/virt/ 03 linux-2.6.30.5/virt/kvm/ 04 linux-2.6.30.5/virt/kvm/coalesced_mmio.c 05 linux-2.6.30.5/virt/kvm/coalesced_mmio.h 06 linux-2.6.30.5/virt/kvm/ioapic.c 07 linux-2.6.30.5/virt/kvm/ioapic.h 08 linux-2.6.30.5/virt/kvm/iodev.h 09 linux-2.6.30.5/virt/kvm/iommu.c 10 linux-2.6.30.5/virt/kvm/irq_comm.c 11 linux-2.6.30.5/virt/kvm/kvm_main.c 12 linux-2.6.30.5/virt/kvm/kvm_trace.c To made things simple, go to /usr/src and create a symlink to source code called linux, do this: view source print? 1 cd /usr/src 2 ln -sf linux-2.6.30.5 linux Result: view source print? 1 ls -al view source print? 1 drwxr-xr-x 3 root root 4.0K Sep 2 06:18 . 2 drwxr-xr-x 13 root root 4.0K Aug 31 14:25 .. 3 lrwxrwxrwx 1 root root 14 Sep 2 06:18 linux -> linux-2.6.30.5 4 drwxrwxr-x 22 root root 4.0K Aug 16 18:19 linux-2.6.30.5 Preparing the environment to compile Kernel To compile the Kernel on Linux, the OS need to be prepared, with gcc, ncurses etc. If your CentOS or Red Hat installation is the minimal, the devel packages weren’t installed, it is needed to do it now, it’s simple with Yum that will resolve all dependencies. view source print? yum install gcc make bison ncurses-devel rpm-build view source print? 1 ... 2 Installed: bison.i386 0:2.3-2.1 gcc.i386 0:4.1.2-44.el5 ncurses-devel.i386 0:5.5-24.20060715 3 Dependency Installed: cpp.i386 0:4.1.2-44.el5 glibc-devel.i386 0:2.5-34.el5_3.1 glibc-headers.i386 0:2.5-34.el5_3.1 kernel-headers.i386 0:2.6.18-128.7.1.el5 libgomp.i386 0:4.3.2-7.el5 4 Updated: glibc.i686 0:2.5-34.el5_3.1 glibc-common.i386 0:2.5-34.el5_3.1 nscd.i386 0:2.5-34.el5_3.1 Compiling the kernel to CentOS or Red Hat Before starting the compilation, it is interesting to clean the garbage that should left behind. view source print? 1 make clean A good idea is to take the parameters of configuration that comes with the factory one, this file can be found at /boot dir, let’s copy it to the root of our kernel source and execute make menuconfig. view source print? 1 cd /usr/src/linux 2 cp /boot/config-`uname -r` .config Be sure to stay on /usr/src/linux. Accessing the configuration menu is the easy way to configure it. view source print? 1 make menuconfig kernel-01 As this is a custom compilation, I suggest you to add a custom tag that will identify the new kernel, to accomplish this, do that: * On initial screen, go to General setup —> kernel-02 * Select Local version – append to kernel release kernel-03 With this done, the resulting kernel.rpm will have the tag identifying it. It is time to customize the kernel configuration to fit with your hardware. After this task, it’s time to quit from menuconfig and start the compilation. While you get out the configuration, you will be asked to save the changes. Answer Yes. kernel-04 The most awaited time… compiling! Run make rpm view source print? 1 make rpm view source print? ... HOSTLD scripts/kconfig/conf scripts/kconfig/conf -s arch/x86/Kconfig make clean set -e; cd ..; ln -sf /usr/src/linux-2.6.30.5 kernel-2.6.30.5fogonacaixadagua /bin/sh /usr/src/linux-2.6.30.5/scripts/setlocalversion > /usr/src/linux-2.6.30.5/.scmversion set -e; cd ..; tar -cz --exclude SCCS --exclude BitKeeper --exclude .svn --exclude CVS --exclude .pc --exclude .hg --exclude .git -f kernel-2.6.30.5fogonacaixadagua.tar.gz kernel-2.6.30.5fogonacaixadagua/. ... The compilation will start, it will take a looong time. At the end of process, without errors: view source print? 1 ... 2 Wrote: /usr/src/redhat/SRPMS/kernel-2.6.30.5fogonacaixadagua-1.src.rpm 3 Wrote: /usr/src/redhat/RPMS/i386/kernel-2.6.30.5fogonacaixadagua-1.i386.rpm 4 ... The kernel was compiled and a .rpm was generated to be installed. To confirm that the new kernel really exists in a rpm format, run: view source print? 1 ls -alh /usr/src/redhat/RPMS/i386/ view source print? 1 total 164M 2 drwxr-xr-x 2 root root 4.0K Sep 2 11:45 . 3 drwxr-xr-x 9 root root 4.0K Sep 2 10:39 .. 4 -rw-r--r-- 1 root root 164M Sep 2 11:45 kernel-2.6.30.5fogonacaixadagua-1.i386.rpm RPM of the new kernel (32 bits) I’m putting the compiled kernel and packaged here, feel free to download it. * kernel-2.6.30.5fogonacaixadagua-1.i386.rpm Installing the new kernel How was generated a RPM of kernel, the installation becomes quite simple view source print? rpm -ivh /usr/src/redhat/RPMS/i386/kernel-2.6.30.5fogonacaixadagua-1.i386.rpm view source print? Preparing... ########################################### [100%] 1:kernel ########################################### [100%] Confirming that the new kernel was installed. view source print? 1 ls /boot view source print? 1 config-2.6.18-128.el5 symvers-2.6.18-128.el5.gz 2 config-2.6.30.5-fogonacaixadagua System.map-2.6.18-128.el5 3 grub System.map-2.6.30.5-fogonacaixadagua 4 initrd-2.6.18-128.el5.img vmlinux-2.6.30.5-fogonacaixadagua.bz2 5 initrd-2.6.30.5-fogonacaixadagua.img vmlinuz-2.6.18-128.el5 6 lost+found vmlinuz-2.6.30.5-fogonacaixadagua Creating the initrd for the new kernel To create the dependencies for the modules: view source print? 1 depmod 2.6.30.5-fogonacaixadagua You must create a new initrd so the OS can start and pre-load the modules necessary to your hardware. view source print? 1 mkinitrd -v /boot/initrd-2.6.30.5-fogonacaixadagua.img 2.6.30.5-fogonacaixadagua In case the following error occour: view source print? 1 No module dm-mem-cache found for kernel 2.6.30.5-fogonacaixadagua, aborting. To work around this, use the parameter--without-dmraid with mkinitrd view source print? 1 mkinitrd --without-dmraid -v /boot/initrd-2.6.30.5-fogonacaixadagua.img 2.6.30.5-fogonacaixadagua Editing grub Final phase, it remains only edit the grub.conf to use the new kernel. With your favorite text editor, add the following lines: view source print? 1 title CentOS (2.6.30.5-fogonacaixadagua) 2 root (hd0,0) 3 kernel /vmlinuz-2.6.30.5-fogonacaixadagua ro root=/dev/VolGroup00/LogVol00 4 initrd /initrd-2.6.30.5-fogonacaixadagua.img The file /boot/grub/grub.conf will be like this: view source print? 01 # grub.conf generated by anaconda 02 # 03 # Note that you do not have to rerun grub after making changes to this file 04 # NOTICE: You have a /boot partition. This means that 05 # all kernel and initrd paths are relative to /boot/, eg. 06 # root (hd0,0) 07 # kernel /vmlinuz-version ro root=/dev/VolGroup00/LogVol00 08 # initrd /initrd-version.img 09 #boot=/dev/sda 10 default=0 11 timeout=5 12 splashimage=(hd0,0)/grub/splash.xpm.gz 13 hiddenmenu 14 title CentOS (2.6.18-128.el5) 15 root (hd0,0) 16 kernel /vmlinuz-2.6.18-128.el5 ro root=/dev/VolGroup00/LogVol00 17 initrd /initrd-2.6.18-128.el5.img 18 title CentOS (2.6.30.5-fogonacaixadagua) 19 root (hd0,0) 20 kernel /vmlinuz-2.6.30.5-fogonacaixadagua ro root=/dev/VolGroup00/LogVol00 21 initrd /initrd-2.6.30.5-fogonacaixadagua.img For the first boot, let the line default=0 to test, if the new kernel boot with no trouble it will be ok to change the line to default=1 to always boot with the new kernel. Testing a boot with the new kernel Reboot. view source print? 1 shutdown -r now * Press any key on boot screen to enter the selection kernel kernel-05 * Select the new kernel configured into Grub kernel-06 * At the end of the boot, it will be possible to see that the new one booted properly kernel-07 Gostou? Ajude a compartilhar * Print * PDF * email * Twitter * del.icio.us * Digg * Identi.ca  banner ad Tópicos relacionados * iotop, your best friend when LED of HD stays on * iotop, amigo das horas que o LED do HD não apaga * Compilando um novo kernel (2.6.30.5) no Linux CentOS 5.3 / Red Hat 5.3 * Script shell com expect para atualização em massa para o horário de verão 2009/2010 * Find: mostrar apenas links simbólicos * Como habilitar o Query Cache no MySQL  Leave a Reply Click here to cancel reply. Name (required) Mail (will not be published) (required) Website Login Username: Password: Remember me * Register * Lost your password? Navegação * Banco de dados * Comic * Email * Featured Articles * FreeBSD * Linux o Bash o JBoss o Virtualização * Misc * Pânico * Seguranca * Troubleshoot Últimos posts * Apresentação sobre IPv6, por Luciano Borguetti * SCSI ID: Pinagem para HD SCSI 68 pinos Maxtor e Seagate * FreeBSD troubleshooting Samba AD * FreeBSD: como montar uma imagem de CD .iso (iso9660) localmente * Comportamento de um servidor comprometido * Script shell com expect para atualização em massa para o horário de verão 2009/2010 Tags antivírus Bash CentOS clamav CLI Comic Conectividade Social Email Fogo na caixa d'água FreeBSD fstab Imagem Instalação JBoss kernel Keylogger Lei de Murphy Linux localtime LVM Mínima Monitoração MySQL OpenSSH Pânico Packet filter PF python25 RedHat repositório RPM samba Seguranca Shell snmp squid Steve Jobs Suse syslog timezone Troubleshoot Virtualização VMware Xen Yum Fogo na Caixa dAgua