1.下载kernel sorce code,从kernel.org上下载或在直接用git clone,或者在国内mirror上下载镜像。
2.代码放在/usr/src/目录下,解压代码。
3.配置config:
a. 打开源码路径:cd /usr/src/linux-xxxx
b. cp /boot/config-xxxxx .config
c. make menuconfig-->load-->save
4. 编译内核:make -jN;
注意:这里可能会遇到因为key而编译不过的问题,可以删除下边的两个key值:
CONFIG_SYSTEM_TRUSTED_KEYS="debian/canonical-certs.pem"
CONFIG_SYSTEM_REVOCATION_KEYS="debian/canonical-revoked-certs.pem"
修改为:
CONFIG_SYSTEM_TRUSTED_KEYS=""
CONFIG_SYSTEM_REVOCATION_KEYS=""
5. 编译模块:make modules -jN
6.安装模块:make modules_install
网上有的说需要执行mkinitramfs和update-initramfs命令,其实不需要执行,因为在执行make install的时候就会执行这两个命令。
7.安装内核:make install
8. 更新grub:update-grub2,注意这里grub会默认选择最新版本的内核,如果更新内核后需要切换到旧版本的内核,需要在启动的过程中选择ubuntu高级选项里边选择之前的版本,如果开机不显示ubuntu高级选项,可以修改/etc/default/grub文件:
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'
GRUB_DEFAULT=0
# GRUB_TIMEOUT_STYLE=hidden ==》增加#,mark掉这一行
GRUB_TIMEOUT_STYLE=menu
GRUB_TIMEOUT=5 ==》修改为5秒
9. 重启电脑,使用uname -a 查看是否替换成功。