linux内核
国内镜像网站,列出来如下:
中科大内核下载镜像站:https://mirrors.ustc.edu.cn/kernel.org/
清华大学内核下载镜像站:https://mirrors.tuna.tsinghua.edu.cn/kernel/
阿里云内核下载镜像站:https://mirrors.aliyun.com/kernel/
网易内核下载镜像站:http://mirrors.163.com/kernel/
sudo uname -r
看到内核版本是5.4.0-100-generic
。
sudo lsb_release -a
看到操作系统版本是Ubuntu 20.04.4
。
sudo wget --no-check-certificate https://mirrors.tuna.tsinghua.edu.cn/kernel/v5.x/linux-5.5.19.tar.gz
可以下载源代码。
sudo tar -xf linux-5.5.19.tar.gz
进行不显示过程的解压。
sudo apt-get install -y libncurses5-dev flex bison libssl-dev dwarves
安装依赖包。
sudo cp /boot/config-5.4.0-100-generic ./.config
将当前内核编译的配置文件复制到源码目录里边,并且改名为.config
。
你可以按照自己的需求进行选择内核编译设置,我这里因为想要把TUN/TAP
安装上,所以进行下边的操作。
Device Drivers
> Network device support
> Universal TUN/TAP device driver support
按下m键,在<>
中有M
,要是不清楚如何操作可以参考《Linux学习之Ubuntu 20.04安装内核模块》。
一直操作上一个步骤,选择 < Exit >
,然后按Enter,直到退回到下边命令行这样。
重新配置一些参数。
sudo sed -i 's/CONFIG_MODULE_SIG=y/CONFIG_MODULE_SIG=n/g' .config # 把 CONFIG_MODULE_SIG=y 替换成 CONFIG_MODULE_SIG=n
sudo sed -i 's/CONFIG_MODULE_SIG_ALL=y/CONFIG_MODULE_SIG_ALL=n/g' .config
sudo sed -i 's/CONFIG_SYSTEM_TRUSTED_KEYS="debian\/canonical-certs.pem"/CONFIG_SYSTEM_TRUSTED_KEYS=""/g' .config
sudo sed -i 's/CONFIG_SYSTEM_REVOCATION_KEYS="debian\/canonical-revoked-certs.pem"/CONFIG_SYSTEM_REVOCATION_KEYS=""/g' .config
sudo sed -i 's/CONFIG_SYSTEM_TRUSTED_KEYRING=y/CONFIG_SYSTEM_TRUSTED_KEYRING=n/g' .config # 把 CONFIG_SYSTEM_TRUSTED_KEYRING=y 替换成 CONFIG_SYSTEM_TRUSTED_KEYRING=n
cat .config | grep "CONFIG_SYSTEM_TRUSTED_KEYRING=n" # 看一下 CONFIG_SYSTEM_TRUSTED_KEYRING 相关字符串是否成功替换。
sudo nohup make -j2 all &
开始编译。
sudo ps -aux | grep 58410
看一下58410
进程是否还在运行,如下图有两行输出,就是还在执行。
sudo ps -aux | grep 58410
发现只有一行显示出来,sudo tail -n 20 nohup.out
看到后20行也没有报错,这就是编译完了。
sudo make modules_install
安装内核。
sudo make install
进行安装。
sudo grep 'menuentry' /boot/grub/grub.cfg
看到
menuentry 'Ubuntu, with Linux 5.5.19' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.5.19-advanced-bbd3ea56-da3b-4e1a-b14e-159e41299ea3' {
menuentry 'Ubuntu, with Linux 5.5.19 (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.5.19-recovery-bbd3ea56-da3b-4e1a-b14e-159e41299ea3' {
/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=menu
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX="net.ifnames=0 consoleblank=600 console=tty0 console=ttyS0,115200n8 nospectre_v2 nopti noibrs noibpb"
# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"
# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console
# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480
# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true
# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"
# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"
现在需要把GRUB_DEFAULT=0
修改为GRUB_DEFAULT="gnulinux-advanced-bbd3ea56-da3b-4e1a-b14e-159e41299ea3>gnulinux-5.5.19-advanced-bbd3ea56-da3b-4e1a-b14e-159e41299ea3"
,修改之后/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="gnulinux-advanced-bbd3ea56-da3b-4e1a-b14e-159e41299ea3>gnulinux-5.5.19-advanced-bbd3ea56-da3b-4e1a-b14e-159e41299ea3"
GRUB_TIMEOUT_STYLE=menu
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX="net.ifnames=0 consoleblank=600 console=tty0 console=ttyS0,115200n8 nospectre_v2 nopti noibrs noibpb"
# Uncomment to enable BadRAM filtering, modify to suit your needs
# This works with Linux (no patch required) and with any kernel that obtains
# the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
#GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"
# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console
# The resolution used on graphical terminal
# note that you can use only modes which your graphic card supports via VBE
# you can see them in real GRUB with the command `vbeinfo'
#GRUB_GFXMODE=640x480
# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true
# Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"
# Uncomment to get a beep at grub start
#GRUB_INIT_TUNE="480 440 1"