Method 1:
1. Use apt-get source
to download the Ubuntu version of the kernel
apt-get source linux-image-$(uname -r)
gives a folder that contains, for example:
linux-3.2.0 linux_3.2.0-26.41.dsc
linux_3.2.0-26.41.diff.gz linux_3.2.0.orig.tar.gz
The bolded diff includes all the Ubuntu/Debian customizations.
2. To build a stock kernel with your own .config
, use the "old-fashioned" Debian make-kpkg
method
sudo apt-get install kernel-package
If you are compiling a kernel for the first time:
sudo apt-get build-dep linux-image-$(uname -r)
Then
cd
into the source directory (here,
linux-3.2.0
), and either run
make oldconfig
to create
.config
file with your running kernel's configuration, or copy a third-part
.config
to this directory.
Depending on whether you want a text or graphical config, install:
(Text)
sudo apt-get install libncurses5 libncurses5-dev
(Graphical)
sudo apt-get install qt3-dev-tools libqt3-mt-dev
And then run:
(Text)
make menuconfig
(Graphical)
make xconfig
When done, just run
make-kpkg
make-kpkg -j N --initrd --append-to-version=my-very-own-kernel kernel-image kernel-headers
where
N
is how many jobs to run in parallel (usually the number of CPUs you have), and
my-very-own-kernel
is a custom string to identify this build.
When done, the kernel image and header files will be ready as debs in the parent directory; you can simply install them with sudo dpkg -i
, which will also take care of adding GRUB entries, etc.
method 2:
1. download kernel code(linux.3.16.1.tar.xz)
, untar the file, then run
make; make modules;
2. install the modules by running:
sudo make modules_install
Install the kernel itself by:
sudo make install
That puts
vmlinuz-3.16.1
(a copy of
vmlinuz
),
config-3.16.1
(a text file storing kernel configuration parameters), and
System.map-3.16.1
(the
kernel symbol lookup table) in
/boot
. For more details, see
this comp.os.linux.misc post by Hadron and
man installkernel
.
Final setup, so the kernel can be started and boot the system:
This section is partly based on information in Kernel/Compile.
With the kernel now where it needs to be, it needs:
-
an entry in the boot loader's configuration, so you can select and boot from it.
-
an initial RAM filesystem, the environment from which the kernel loads drivers and mounts the
/
filesystem.(If you're installing an old kernel or have configured your kernel to use devfs instead of the newer udev, you may need or wish to set up an initial ramdisk instead. If you know you need that instead, see
man initrd
.)
Generate your initramfs with mkinitramfs
:
cd /boot
sudo mkinitramfs -ko initrd.img-3.16.1 3.16.1
or:
sudo update-initramfs -u -k 3.16.1
or:
sudo update-initramfs -c -k 3.0.0
When you update the configuration of the GRUB2 boot loader--which has been the default in Ubuntu since 9.10--should automatically detect the new kernel and add an option to boot from it.
sudo update-grub
It could be possible that the create initrd.img is very large (over 100MB), and the boot partiiton maybe don't have enough free space. In this case, apply the strip parameter when installing modules:
make INSTALL_MOD_STRIP=1 modules_install
Similarly, for building the deb packages:
make INSTALL_MOD_STRIP=1 deb-pkg