Ubuntu Compile and Install Linux Kernel

  1. Get Linux kernel source code from www.kernel.org

I choose linux-4.14.150.tar.gz to download the tarball
Ubuntu Compile and Install Linux Kernel_第1张图片

  1. decompress the tarball
 tar -xvf linux-4.14.150.tar.xz
  1. Install build dependency tools
sudo apt-get install build-essential libncurses-dev bison flex libssl-dev libelf-dev
  1. Linux kernel default configuration
    Linux kernel default configuration is named as
    xxx_defconfig under arch/ folder,
cd  linux-4.14.150/arch
find -name *defconfig | grep x86 -i

you will see following search results

./x86/configs/x86_64_defconfig
./x86/configs/i386_defconfig
./um/configs/x86_64_defconfig

the x86_64_defconfig only contains the basic features, if to support multiple device drivers, it is better to use the current kernel configuration on ubuntu system

  1. Customize kernel configuration
cd  linux-4.14.150
cp /boot/config-4.8.0+ .config
make menuconfig

using exist ubuntu 4.8.0 config, then make menuconfig to customize specific kernel configuration you want
Ubuntu Compile and Install Linux Kernel_第2张图片

  1. Compile Linux Kernel
cd  linux-4.14.150
make

or to speed up compiling use “make -j4”, here i use “make” to easy track the first scene if any bug happens during compiling
Ubuntu Compile and Install Linux Kernel_第3张图片if finished compiling Linux kernel, following messages will be shown in your terminal

Ubuntu Compile and Install Linux Kernel_第4张图片

  1. Install Linux kernel modules
sudo make modules_install

Ubuntu Compile and Install Linux Kernel_第5张图片

  1. Install Linux kernel
sudo make install

you will see following messages shown in the terminal for boot menu entry generation

sh ./arch/x86/boot/install.sh 4.14.150 arch/x86/boot/bzImage \
	System.map "/boot"
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.14.150 /boot/vmlinuz-4.14.150
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.14.150 /boot/vmlinuz-4.14.150
update-initramfs: Generating /boot/initrd.img-4.14.150
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.14.150 /boot/vmlinuz-4.14.150
run-parts: executing /etc/kernel/postinst.d/update-notifier 4.14.150 /boot/vmlinuz-4.14.150
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.14.150 /boot/vmlinuz-4.14.150
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.0.0-27-generic
Found initrd image: /boot/initrd.img-5.0.0-27-generic
Found linux image: /boot/vmlinuz-5.0.0-23-generic
Found initrd image: /boot/initrd.img-5.0.0-23-generic
Found linux image: /boot/vmlinuz-4.14.150
Found initrd image: /boot/initrd.img-4.14.150
Found linux image: /boot/vmlinuz-4.8.0+
Found initrd image: /boot/initrd.img-4.8.0+
Adding boot menu entry for EFI firmware configuration
done
  1. reboot ubuntu and choose the boot entry for 4.14.150

你可能感兴趣的:(Ubuntu,Ubuntu,Linux,Kernel,Compile,Install)