I have to admit that Debian eases some administrations tasks like the kernel compiling process. At first sight, the procedure looks similar to compiling a kernel in the old-fashioned way but what it makes it different is that you will end up with a Linux kernel in a .deb file, so it will be easier to install the same image kernel in other computers by just installing the .deb file.
Another advantage of compiling a kernel in Debian is you don’t have to worry about building the initramfs image file or changing your boot loader, because Debian does it for you automagically.
So, I think you might be interested in how to compile a kernel the Debian way, sol let’s see how to do it…
Requisites
Due to you are about to compile a kernel, you’ll need some files and compilers. You will also need ncurses to display dialog on a consoles, and for building the .deb file you will need the kernel-package utility. In Debian you can install all this by typing:
aptitude install build-essential libncurses5-dev kernel-package
Working directory
It’s common to use the /usr/src/ directory when compiling the kernel, drivers and modules. So, go to the /usr/src/ directory:
cd /usr/src/
Procedure
You’ll need to get the kernel’s sources to compile them. They can be got from your distro’s repositories or from kernel.org directly. In Debian by installing the following package you will get a tar file in the /usr/src/ directory:
aptitude install linux-source-2.6.30
If you want to download it from kernel.org it would be something like this:
wget -c http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.32.2.tar.bz2
Now unzip the tar file:
tar xjfv linux-2.6.32.2.tar.bz2
rm linux
ln -s linux-source-2.6.30 linux
If you downloaded it from kernel.org, you have to type:
ln -s linux-2.6.32.2 linux
Go the linux directory:
cd linux
If you’ve compiled other kernels it’s a good idea to clean everything before starting to compile your new kernel:
make mrproper
Now proceed to set your kernel’s options. To do so, you can use make config (an interactive but annoying interface), make menuconfig (based on ncurses) or make xconfig (you’ll need X running).. I suggest to use the second option:
make menuconfig
After you have made you selection, choose Exit to write the .config file
The Debian way
Here is where things are different from the original procedure because you will compile your kernel and modules but the result of compilation will be a .deb file. Let’s say you want to compile a Linux image with its initramfs and headers files, the command and options to accomplish that is:
make-kpkg --revision lnv1 --initrd kernel_image kernel_headers
Where:
| Option | Description |
--revision lnv1 |
Revision number for the .deb file |
--initrd |
Include initramfs image and its installation scripts |
kernel_image |
Generate a .deb file with a kernel image |
kernel_headers |
Generate a .deb file with kernel's headers |
kernel_source |
Generate a .deb file with kernel' source files |
In order to install your new compiled kernel just install the .deb file as follow:
dpkg -i /usr/src/linux-image-2.6.32.2-mundungus_lnv1_i386.deb
This will install the kernel and initrd images into the /boot directory and run update-grub utility automatically, so your new kernel image will be listed on grub’s menu next time you reboot your computer.
Planeta Linux
#1 by Luis Gallardo on 28/10/2010 - 9:16 am
@LucMAN kernel_source te crea un .deb co el código fuente del kernel como bien comentas, pero debería se suficiente con los headers del kernel para compila otros programas/drivers. Ya actualicé la tabla…
Gracias por el aporte!!
#2 by LucMAN on 27/10/2010 - 10:34 pm
Hola! fijate que en la tabla te faltó agregar:
Option Description
kernel_source Paquete de código fuente del kernel, requerido para algunos drivers.
Saludos!
#3 by Luis Gallardo on 26/10/2010 - 9:28 pm
@Anónimo He acortado un poco la salida para concentramos en lo que falla. El problema está relacionado a que estás usando un libc-dev algo viejo (por ejemplo de Lenny) para la versión de kernel que estás intentando compilar, como lo comentan aquí http://cakebox.homeunix.net/wordpress/?p=100
Según allí bastaría con editar el archivo Documentation/lguest/Makefile cambiando:
por:
Suerte!!
#4 by Anónimo on 26/10/2010 - 5:35 pm
Gracias por el aporte Luis, segui todos los pasos y luego de mandar a debian a hacer el paquete de la imagen…
#make-kpkg –revision lnv1 –initrd kernel_image kernel_headers
(te copio aca abajo lo que quedo en el buffer del terminal virtual)
CC sound/drivers/mpu401/snd-mpu401-uart.mod.o
LD [M] sound/drivers/mpu401/snd-mpu401-uart.ko
CC sound/drivers/mpu401/snd-mpu401.mod.o
LD [M] sound/drivers/mpu401/snd-mpu401.ko
CC sound/drivers/snd-dummy.mod.o
LD [M] sound/drivers/snd-dummy.ko
CC sound/drivers/snd-virmidi.mod.o
LD [M] sound/drivers/snd-virmidi.ko
CC sound/pci/ac97/snd-ac97-codec.mod.o
LD [M] sound/pci/ac97/snd-ac97-codec.ko
CC sound/pci/snd-intel8x0.mod.o
LD [M] sound/pci/snd-intel8x0.ko
CC sound/pci/snd-intel8x0m.mod.o
LD [M] sound/pci/snd-intel8x0m.ko
CC sound/soundcore.mod.o
LD [M] sound/soundcore.ko
IHEX firmware/acenic/tg1.bin
IHEX firmware/acenic/tg2.bin
IHEX firmware/adaptec/starfire_rx.bin
IHEX firmware/tigon/tg3.bin
IHEX firmware/tigon/tg3_tso.bin
IHEX firmware/tigon/tg3_tso5.bin
IHEX firmware/3com/typhoon.bin
IHEX firmware/kaweth/new_code.bin
IHEX firmware/kaweth/trigger_code.bin
IHEX firmware/kaweth/new_code_fix.bin
IHEX firmware/kaweth/trigger_code_fix.bin
HOSTCC firmware/ihex2fw
H16TOFW firmware/edgeport/boot.fw
H16TOFW firmware/edgeport/boot2.fw
H16TOFW firmware/edgeport/down.fw
H16TOFW firmware/edgeport/down2.fw
IHEX firmware/edgeport/down3.bin
IHEX2FW firmware/keyspan_pda/keyspan_pda.fw
IHEX2FW firmware/keyspan_pda/xircom_pgs.fw
make[1]: se sale del directorio `/usr/src/linux-2.6.36′
/usr/bin/make ARCH=i386 \
-C Documentation/lguest
make[1]: se ingresa al directorio `/usr/src/linux-2.6.36/Documentation/lguest’
cc -m32 -Wall -Wmissing-declarations -Wmissing-prototypes -O3 -U_FORTIFY_SOURCE lguest.c -o lguest
lguest.c:21:25: error: sys/eventfd.h: No existe el fichero o el directorio
lguest.c:46:30: error: linux/virtio_rng.h: No existe el fichero o el directorio
lguest.c: In function ‘wait_for_vq_desc’:
lguest.c:715: error: ‘VRING_DESC_F_INDIRECT’ undeclared (first use in this function)
lguest.c:715: error: (Each undeclared identifier is reported only once
lguest.c:715: error: for each function it appears in.)
lguest.c: In function ‘create_thread’:
lguest.c:1026: warning: implicit declaration of function ‘eventfd’
lguest.c: In function ‘get_tun_device’:
lguest.c:1481: error: ‘IFF_VNET_HDR’ undeclared (first use in this function)
lguest.c:1486: error: ‘TUNSETOFFLOAD’ undeclared (first use in this function)
lguest.c:1487: error: ‘TUN_F_CSUM’ undeclared (first use in this function)
lguest.c:1487: error: ‘TUN_F_TSO4’ undeclared (first use in this function)
lguest.c:1487: error: ‘TUN_F_TSO6’ undeclared (first use in this function)
lguest.c:1487: error: ‘TUN_F_TSO_ECN’ undeclared (first use in this function)
lguest.c: In function ‘setup_tun_net’:
lguest.c:1568: error: ‘VIRTIO_RING_F_INDIRECT_DESC’ undeclared (first use in this function)
lguest.c: In function ‘setup_rng’:
lguest.c:1811: error: ‘VIRTIO_ID_RNG’ undeclared (first use in this function)
make[1]: *** [lguest] Error 1
make[1]: se sale del directorio `/usr/src/linux-2.6.36/Documentation/lguest’
make: *** [debian/stamp/build/kernel] Error 2
debian#
No tengo ni idea de por donde empezar a “ver” que sucede… alguna sugerencia?