1.下载内核并且解压
安装依赖
sudo apt-get install gcc libncurses5-dev build-essential kernel-package libssl-dev flex bison libelf-dev dwarves
2.执行make menuconfig,并不修改,使用默认然后退出,默认使用的配置是x86_64_defconfig
所以也可以直接:make x86_64_defconfig
还可以拷贝/boot/目录下的既有的config文件来作为编译内核的配置文件来编译。但是需要两个内核版本号差别不大,可以互通使用。
$ cp /boot/config-5.4.0-84-generic .config
将CONFIG_SYSTEM_TRUSTED_KEYS字符串置空。
3.执行make -j4
因为之前编译过,再次编译输出很少
4.执行sudo make modules_install
5.执行sudo make headers_install,用于开发应用程序
也是因为之前安装过,所以输出很少
6.最后,执行sudo make install,更新内核,文件系统和grub.
7:重启内核完成升级
注意:有些PC需要将security boot功能关闭才能完成升级,否则启动的时候对内核签名校验失败,无法正确启动,再bios里面有关闭开关,首先设置密码,再通过密码关闭security boot.
方式:
make -j4 deb-pkg
HDRINST usr/include/asm/unistd_x32.h
HDRINST usr/include/asm/unistd_64.h
HDRINST usr/include/asm/ipcbuf.h
HDRINST usr/include/asm/socket.h
HDRINST usr/include/asm/termios.h
HDRINST usr/include/asm/unistd_32.h
HDRINST usr/include/asm/sockios.h
HDRINST usr/include/asm/bpf_perf_event.h
HDRINST usr/include/asm/poll.h
HDRINST usr/include/asm/errno.h
HDRINST usr/include/asm/param.h
HDRINST usr/include/asm/fcntl.h
HDRINST usr/include/asm/resource.h
HDRINST usr/include/asm/ioctls.h
HDRINST usr/include/asm/types.h
HDRINST usr/include/asm/ioctl.h
HDRINST usr/include/asm/termbits.h
INSTALL ./debian/headertmp/usr/include
dpkg-deb: 正在 '../linux-headers-5.4.138-rt62+_5.4.138-rt62+-1_amd64.deb' 中构建软件包 'linux-headers-5.4.138-rt62+'。
dpkg-deb: 正在 '../linux-libc-dev_5.4.138-rt62+-1_amd64.deb' 中构建软件包 'linux-libc-dev'。
dpkg-deb: 正在 '../linux-image-5.4.138-rt62+_5.4.138-rt62+-1_amd64.deb' 中构建软件包 'linux-image-5.4.138-rt62+'。
dpkg-genbuildinfo
dpkg-genchanges >../linux-5.4.138-rt62+_5.4.138-rt62+-1_amd64.changes
dpkg-genchanges: 警告: 控制文件声明了包 linux-image-5.4.138-rt62+-dbg 但它却不在文件列表中
dpkg-genchanges: info: 上传数据中包含完整的原始代码
dpkg-source -i.git --after-build linux-5.4.138
dpkg-buildpackage: info: 完整上载(包含原始的代码)
caozilong@caozilong-Vostro-3268:~/Workspace/linux-rt/linux-5.4.138$ find ./ -type f -name "*.deb"
在内核的上级目录,生成了3个deb文件,分别为内核,头文件以及libc.
安装:
sudo dpkg -i *.deb
czl@czl-RedmiBook-14:~/kernel$ sudo dpkg -i *.deb
[sudo] czl 的密码:
正在选中未选择的软件包 linux-headers-4.14.119。
(正在读取数据库 ... 系统当前共安装有 256271 个文件和目录。)
正准备解包 linux-headers-4.14.119_4.14.119-1_amd64.deb ...
正在解包 linux-headers-4.14.119 (4.14.119-1) ...
正在选中未选择的软件包 linux-image-4.14.119。
正准备解包 linux-image-4.14.119_4.14.119-1_amd64.deb ...
正在解包 linux-image-4.14.119 (4.14.119-1) ...
正在选中未选择的软件包 linux-image-4.14.119-dbg。
正准备解包 linux-image-4.14.119-dbg_4.14.119-1_amd64.deb ...
正在解包 linux-image-4.14.119-dbg (4.14.119-1) ...
正准备解包 linux-libc-dev_4.14.119-1_amd64.deb ...
正在将 linux-libc-dev (4.14.119-1) 解包到 (4.4.0-210.242) 上 ...
正在设置 linux-headers-4.14.119 (4.14.119-1) ...
正在设置 linux-image-4.14.119 (4.14.119-1) ...
* dkms: running auto installation service for kernel 4.14.119
Kernel preparation unnecessary for this kernel. Skipping...
Building module:
cleaning build area....
make KERNELRELEASE=4.14.119 -C /lib/modules/4.14.119/build M=/var/lib/dkms/virtualbox/5.1.38/build.........
Signing module:
- /var/lib/dkms/virtualbox/5.1.38/4.14.119/x86_64/module/vboxpci.ko
- /var/lib/dkms/virtualbox/5.1.38/4.14.119/x86_64/module/vboxnetadp.ko
- /var/lib/dkms/virtualbox/5.1.38/4.14.119/x86_64/module/vboxdrv.ko
- /var/lib/dkms/virtualbox/5.1.38/4.14.119/x86_64/module/vboxnetflt.ko
Secure Boot not enabled on this system.
cleaning build area....
DKMS: build completed.
vboxdrv.ko:
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/4.14.119/updates/dkms/
vboxnetadp.ko:
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/4.14.119/updates/dkms/
vboxnetflt.ko:
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/4.14.119/updates/dkms/
vboxpci.ko:
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/4.14.119/updates/dkms/
depmod....
DKMS: install completed.
[ OK ]
update-initramfs: Generating /boot/initrd.img-4.14.119
W: Possible missing firmware /lib/firmware/i915/kbl_guc_ver9_14.bin for module i915
W: Possible missing firmware /lib/firmware/i915/bxt_guc_ver8_7.bin for module i915
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.15.0-142-generic
Found initrd image: /boot/initrd.img-4.15.0-142-generic
Found linux image: /boot/vmlinuz-4.15.0-112-generic
Found initrd image: /boot/initrd.img-4.15.0-112-generic
Found linux image: /boot/vmlinuz-4.14.119
Found initrd image: /boot/initrd.img-4.14.119
Found Windows Boot Manager on /dev/sda1@/EFI/Microsoft/Boot/bootmgfw.efi
Adding boot menu entry for EFI firmware configuration
done
正在设置 linux-image-4.14.119-dbg (4.14.119-1) ...
正在设置 linux-libc-dev (4.14.119-1) ...
czl@czl-RedmiBook-14:~/kernel$
按照上述方法安装的,默认是没有安装.ko模块的,需要在源码目录中编译安装:
make modules
sudo make modules_install
第一步:
make mrproper
第二步:
make ARCH=x86_64 headers_check
第三步:
make ARCH=x86_64 INSTALL_HDR_PATH=/home1/caozilong/WorkSpace/linux/headers headers_install
安装结果:
下载ubuntu-mainline-kernel脚本
wget https://raw.githubusercontent.com/pimlie/ubuntu-mainline-kernel.sh/master/ubuntu-mainline-kernel.sh
将脚本放在可执行路径中
sudo install ubuntu-mainline-kernel.sh /usr/local/bin/
检查最新的可用内核版本
ubuntu-mainline-kernel.sh -c
获得最新版本并确认这就是您想要安装在系统上的版本之后,运行
sudo ubuntu-mainline-kernel.sh -i
$ ubuntu-mainline-kernel.sh -c
Finding latest version available on kernel.ubuntu.com: v6.1.8
Finding latest installed version: none
A newer kernel version (v6.1.8) is available
$ sudo ubuntu-mainline-kernel.sh -i
Finding latest version available on kernel.ubuntu.com
Latest version is: v6.1.8, continue? (y/N)
Will download 6 files from kernel.ubuntu.com:
Downloading amd64/linux-headers-6.1.8-060108-generic_6.1.8-060108.202301240742_amd64.deb: 100%
Downloading amd64/linux-headers-6.1.8-060108_6.1.8-060108.202301240742_all.deb: 100%
Downloading amd64/linux-image-unsigned-6.1.8-060108-generic_6.1.8-060108.202301240742_amd64.deb: 100%
Downloading amd64/linux-modules-6.1.8-060108-generic_6.1.8-060108.202301240742_amd64.deb: 100%
Downloading amd64/CHECKSUMS: 100%
Downloading amd64/CHECKSUMS.gpg: 100%
Importing kernel-ppa gpg key ok
Signature of checksum file has been successfully verified
Checksums of deb files have been successfully verified with sha256sum
Installing 4 packages
Cleaning up work folder
$ ls -l /boot/
config-5.4.0-135-generic grub/ initrd.img-6.1.8-060108-generic System.map-5.4.0-135-generic vmlinuz-5.4.0-135-generic
config-5.4.0-136-generic initrd.img-5.4.0-135-generic memtest86+.bin System.map-5.4.0-136-generic vmlinuz-5.4.0-136-generic
config-5.4.0-137-generic initrd.img-5.4.0-136-generic memtest86+.elf System.map-5.4.0-137-generic vmlinuz-5.4.0-137-generic
config-6.1.8-060108-generic initrd.img-5.4.0-137-generic memtest86+_multiboot.bin System.map-6.1.8-060108-generic vmlinuz-6.1.8-060108-generic
重新启动系统并检查内核版本
uname -rs
卸载最新的Linux Kernel
sudo ubuntu-mainline-kernel.sh -u
首先重启系统,然后运行以下命令:
uname -rs
-r 选项可以查看所有可用的内核版本。
$ ubuntu-mainline-kernel.sh -r
Downloading index from kernel.ubuntu.com
v3.2.85 v3.2.90 v3.2.92 v3.2.93 v3.2.94 v3.2.95 v3.2.96 v3.2.97 v3.2.98 v3.2.99 v3.2.100
v3.2.101 v3.4.113 v3.8.3 v3.8.7 v3.12.65 v3.12.66 v3.12.67 v3.12.68 v3.12.69 v3.12.70 v3.12.71
v3.12.72 v3.12.73 v3.12.74 v3.14.74 v3.14.75 v3.14.77 v3.14.78 v3.14.79 v3.16.40 v3.16.45 v3.16.50
v3.16.55 v3.16.60 v3.16.65 v3.16.70 v3.16.75 v3.16.76 v3.16.77 v3.16.78 v3.16.79 v3.16.80 v3.16.81
v3.16.82 v3.16.83 v3.16.84 v3.16.85 v3.18.40 v3.18.45 v3.18.50 v3.18.55 v3.18.60 v3.18.70 v3.18.75
v3.18.80 v3.18.85 v3.18.90 v3.18.95 v3.18.100 v3.18.105 v3.18.110 v3.18.115 v3.18.120 v3.18.125 v3.18.130
v3.18.131 v3.18.132 v3.18.133 v3.18.134 v3.18.135 v3.18.136 v3.18.137 v3.18.138 v3.18.139 v3.18.140 v4.1.30
v4.1.35 v4.1.40 v4.1.43 v4.1.44 v4.1.45 v4.1.46 v4.1.47 v4.1.48 v4.1.49 v4.1.50 v4.1.51
v4.1.52 v4.4.20 v4.4.30 v4.4.40 v4.4.50 v4.4.60 v4.4.70 v4.4.80 v4.4.90 v4.4.100 v4.4.110
v4.4.120 v4.4.130 v4.4.140 v4.4.150 v4.4.155 v4.4.160 v4.4.165 v4.4.170 v4.4.175 v4.4.180 v4.4.185
v4.4.190 v4.4.195 v4.4.200 v4.4.205 v4.4.210 v4.4.215 v4.4.220 v4.4.225 v4.4.230 v4.4.235 v4.4.240
v4.4.245 v4.4.250 v4.4.255 v4.4.260 v4.4.265 v4.4.270 v4.4.275 v4.4.280 v4.4.285 v4.4.290 v4.4.293
v4.4.294 v4.4.295 v4.4.296 v4.4.297 v4.4.298 v4.4.299 v4.4.300 v4.4.301 v4.4.302 v4.6.4 v4.6.5
v4.6.6 v4.6.7 v4.7.0