ubuntu16.04内核代码编译升级步骤

笔者最近在ubuntu基础平台上做开发,因此对于基础平台的探究再从新来一遍吧,下面是基础平台编译升级内核的方法。

下载源代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
root@ubuntu:~# apt-cache search linux-source
linux-source - Linux kernel source with Ubuntu patches
linux-source-4.4.0 - Linux kernel source for version 4.4.0 with Ubuntu patches
linux-source-4.10.0 - Linux kernel source for version 4.10.0 with Ubuntu patches
linux-source-4.11.0 - Linux kernel source for version 4.11.0 with Ubuntu patches
linux-source-4.13.0 - Linux kernel source for version 4.13.0 with Ubuntu patches
linux-source-4.8.0 - Linux kernel source for version 4.8.0 with Ubuntu patches
root@ubuntu:~#
root@ubuntu:~#
root@ubuntu:~#
root@ubuntu:~# uname -r
4.4.0-62-generic
root@ubuntu:~#
root@ubuntu:~# apt-get install linux-source-4.4.0
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
systemtap-common systemtap-runtime
Use 'apt autoremove' to remove them.
Suggested packages:
libncurses-dev | ncurses-dev kernel-package libqt3-dev
The following NEW packages will be installed:
linux-source-4.4.0
0 upgraded, 1 newly installed, 0 to remove and 153 not upgraded.
Need to get 112 MB of archives.
After this operation, 130 MB of additional disk space will be used.
Get:1 http://mirrors.aliyun.com/ubuntu xenial-updates/main amd64 linux-source-4.4.0 all 4.4.0-109.132 [112 MB]
Fetched 112 MB in 5min 2s (371 kB/s)
Selecting previously unselected package linux-source-4.4.0.
(Reading database ... 113915 files and directories currently installed.)
Preparing to unpack .../linux-source-4.4.0_4.4.0-109.132_all.deb ...
Unpacking linux-source-4.4.0 (4.4.0-109.132) ...
Setting up linux-source-4.4.0 (4.4.0-109.132) ...
root@ubuntu:~#

源代码下载目录

1
2
3
root@ubuntu:/usr/src# ls /usr/src/linux-source-4.4.0
debian debian.master linux-source-4.4.0.tar.bz2
root@ubuntu:/usr/src#

编译

apt-get install libncurses5-dev libncursesw5-dev

1
2
3
4
make menuconfig
make -j4
make modules_install
make install

更新引导项

1
2
3
4
5
6
root@ubuntu:/usr/src# cd /boot/grub/
root@ubuntu:/boot/grub# update-grub2
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.4.0-62-generic
Found initrd image: /boot/initrd.img-4.4.0-62-generic
done

重启

1
reboot