Operating system-kernel compilation

Kernel compilation

0 Necessary software download

Need to downloadlibncurses5-dev build-essential kernel-package

sudo apt-get install libncurses5-dev build-essential kernel-package

Generally speaking, the default download source is very slow, you can go to Baidu to ubuntuchange the source and change to Tsinghua source or Ali source.

1 Download the kernel

wget https://mirrors.edge.kernel.org/pub/linux/kernel/v3.x/linux-3.18.24.tar.xz

2 Unzip and move

tar -Jxvf linux-3.18.24.tar.xz -C /usr/src/

3 Move to the above directory

cd /usr/src/linux-3.18.24/

4 Generate .config file/kernel function selection

There are two ways to generate configuration files:

  • Copy the configuration file of the current kernel directly
  • Generate the kernel configuration file yourself

Copy current

cp/boot/config-`uname-r` .config

Self-generated

In fact, there are many ways, it is recommended heremake menuconfig

make menuconfig

Next, an interface will appear. For the specific meaning of each option, you can refer to the above description of CSDN or ppt, and you can directly select the one below saveto generate the default configuration.

5 make

Compile the kernel

make clean bzImage modules

The above steps will take about 2-3 hours. Which make can add parameters -j nto speed up the compilation. n can be the number of computer threads (generally speaking, one core of Intel cpu can open two threads, so the number of threads is twice the number of cores)
Insert picture description here

Compile the module:

make modules_install

Perform kernel installation

make install

6 Change grub

According to ppt or online methods, at least my ubuntu14.04 modification does not work.

It is recommended to use the following methods to change:

Check the available kernels and write down the label of the kernel that needs to be started (labeled from 0)

grep -Ei 'submenu|menuentry ' /boot/grub/grub.cfg | sed -re "s/(.? )'([^']+)'.*/\1 \2/"

The approximate output is as follows:

Insert picture description here

What needs to be started is 3.18.24, so the label is 4

Change the default boot kernel

vi /etc/default/grub

Insert picture description here

Change the sixth line above to "1>x" (x is the label of the previous kernel)

Update grub

 update-grub

Reboot

reboot

After restarting, uname -rcheck the kernel version through.

Guess you like

Origin blog.csdn.net/LordTech/article/details/109141920