经常使用Ubuntu 作为开发平台,有降低内核版本的需求。下面介绍 Ubuntu 怎么降级到指定的 Linux 内核版本。
ubuntu@ubuntu:~/Downloads$ uname -r
5.4.0-120-generic # 默认内核版本是: 5.4.0-120 现更改内核版本为: 5.4.0-148
# 每个内核版本都有一个带 -generic 和不带 -generic 的内核头文件,对于同一版本内核的这两个文件
# 夹都只是头文件,并不是源代码。带有 -generic 的目录里面均是指向不带 -generic 文件夹内容的
# 符号链接
ubuntu@ubuntu:/lib/modules$ uname -r
5.4.0-120-generic
ubuntu@ubuntu:/lib/modules$ cd 5.4.0-120-generic
ubuntu@ubuntu:/lib/modules/5.4.0-120-generic$ ls
build kernel modules.alias.bin modules.builtin.bin modules.dep modules.devname modules.softdep modules.symbols.bin
initrd modules.alias modules.builtin modules.builtin.modinfo modules.dep.bin modules.order modules.symbols vdso
ubuntu@ubuntu:/lib/modules/5.4.0-120-generic$ ls -l
total 5812
lrwxrwxrwx 1 root root 40 6月 10 2022 build -> /usr/src/linux-headers-5.4.0-120-generic
drwxr-xr-x 2 root root 4096 6月 10 2022 initrd
drwxr-xr-x 17 root root 4096 6月 19 2022 kernel
-rw-r--r-- 1 root root 1403204 6月 19 2022 modules.alias
-rw-r--r-- 1 root root 1380114 6月 19 2022 modules.alias.bin
-rw-r--r-- 1 root root 8105 6月 10 2022 modules.builtin
-rw-r--r-- 1 root root 10257 6月 19 2022 modules.builtin.bin
-rw-r--r-- 1 root root 63668 6月 10 2022 modules.builtin.modinfo
-rw-r--r-- 1 root root 610840 6月 19 2022 modules.dep
-rw-r--r-- 1 root root 853423 6月 19 2022 modules.dep.bin
-rw-r--r-- 1 root root 330 6月 19 2022 modules.devname
-rw-r--r-- 1 root root 219972 6月 10 2022 modules.order
-rw-r--r-- 1 root root 947 6月 19 2022 modules.softdep
-rw-r--r-- 1 root root 615433 6月 19 2022 modules.symbols
-rw-r--r-- 1 root root 748480 6月 19 2022 modules.symbols.bin
drwxr-xr-x 3 root root 4096 6月 19 2022 vdso
ubuntu@ubuntu:/lib/modules/5.4.0-120-generic$ ls -l /usr/src/linux-headers-5.4.0-120-generic/
total 1612
drwxr-xr-x 3 root root 4096 6月 19 2022 arch
lrwxrwxrwx 1 root root 40 6月 10 2022 block -> ../linux-hwe-5.4-headers-5.4.0-120/block
lrwxrwxrwx 1 root root 40 6月 10 2022 certs -> ../linux-hwe-5.4-headers-5.4.0-120/certs
lrwxrwxrwx 1 root root 41 6月 10 2022 crypto -> ../linux-hwe-5.4-headers-5.4.0-120/crypto
lrwxrwxrwx 1 root root 48 6月 10 2022 Documentation -> ../linux-hwe-5.4-headers-5.4.0-120/Documentation
lrwxrwxrwx 1 root root 42 6月 10 2022 drivers -> ../linux-hwe-5.4-headers-5.4.0-120/drivers
lrwxrwxrwx 1 root root 37 6月 10 2022 fs -> ../linux-hwe-5.4-headers-5.4.0-120/fs
drwxr-xr-x 4 root root 4096 6月 19 2022 include
lrwxrwxrwx 1 root root 39 6月 10 2022 init -> ../linux-hwe-5.4-headers-5.4.0-120/init
lrwxrwxrwx 1 root root 38 6月 10 2022 ipc -> ../linux-hwe-5.4-headers-5.4.0-120/ipc
lrwxrwxrwx 1 root root 41 6月 10 2022 Kbuild -> ../linux-hwe-5.4-headers-5.4.0-120/Kbuild
lrwxrwxrwx 1 root root 42 6月 10 2022 Kconfig -> ../linux-hwe-5.4-headers-5.4.0-120/Kconfig
drwxr-xr-x 2 root root 4096 6月 19 2022 kernel
lrwxrwxrwx 1 root root 38 6月 10 2022 lib -> ../linux-hwe-5.4-headers-5.4.0-120/lib
lrwxrwxrwx 1 root root 43 6月 10 2022 Makefile -> ../linux-hwe-5.4-headers-5.4.0-120/Makefile
lrwxrwxrwx 1 root root 37 6月 10 2022 mm -> ../linux-hwe-5.4-headers-5.4.0-120/mm
-rw-r--r-- 1 root root 1620851 6月 10 2022 Module.symvers
lrwxrwxrwx 1 root root 38 6月 10 2022 net -> ../linux-hwe-5.4-headers-5.4.0-120/net
lrwxrwxrwx 1 root root 42 6月 10 2022 samples -> ../linux-hwe-5.4-headers-5.4.0-120/samples
drwxr-xr-x 8 root root 12288 6月 19 2022 scripts
lrwxrwxrwx 1 root root 43 6月 10 2022 security -> ../linux-hwe-5.4-headers-5.4.0-120/security
lrwxrwxrwx 1 root root 40 6月 10 2022 sound -> ../linux-hwe-5.4-headers-5.4.0-120/sound
drwxr-xr-x 3 root root 4096 6月 19 2022 tools
lrwxrwxrwx 1 root root 41 6月 10 2022 ubuntu -> ../linux-hwe-5.4-headers-5.4.0-120/ubuntu
lrwxrwxrwx 1 root root 38 6月 10 2022 usr -> ../linux-hwe-5.4-headers-5.4.0-120/usr
lrwxrwxrwx 1 root root 39 6月 10 2022 virt -> ../linux-hwe-5.4-headers-5.4.0-120/virt
# 查看已经安装的内核镜像
ubuntu@ubuntu:~$ dpkg --get-selections | grep linux-image
linux-image-4.18.0-15-generic deinstall
linux-image-5.4.0-120-generic install
linux-image-5.4.0-147-generic install
linux-image-5.4.0-148-generic install
linux-image-5.4.0-45-generic deinstall
linux-image-5.4.0-47-generic deinstall
linux-image-5.4.0-52-generic deinstall
linux-image-5.4.0-53-generic deinstall
linux-image-5.4.0-58-generic deinstall
linux-image-5.4.0-60-generic deinstall
linux-image-5.4.0-62-generic deinstall
linux-image-5.4.0-65-generic deinstall
linux-image-5.4.0-66-generic deinstall
linux-image-5.4.0-67-generic deinstall
linux-image-5.4.0-70-generic deinstall
linux-image-5.4.0-72-generic deinstall
linux-image-5.4.0-81-generic deinstall
linux-image-5.4.0-89-generic deinstall
linux-image-5.4.0-90-generic deinstall
linux-image-5.4.0-91-generic deinstall
linux-image-5.4.0-92-generic deinstall
linux-image-generic-hwe-18.04 install
linux-image-unsigned-6.3.3-060303-generic install
# 查看指定版本的内核包 ,我需要的是 : 5.4.0-148
ubuntu@ubuntu:~$ apt-cache search linux | grep 5.4.0-148
linux-buildinfo-5.4.0-148-generic - Linux kernel buildinfo for version 5.4.0 on 64 bit x86 SMP
linux-buildinfo-5.4.0-148-lowlatency - Linux kernel buildinfo for version 5.4.0 on 64 bit x86 SMP
linux-cloud-tools-5.4.0-148-generic - Linux kernel version specific cloud tools for version 5.4.0-148
linux-cloud-tools-5.4.0-148-lowlatency - Linux kernel version specific cloud tools for version 5.4.0-148
linux-headers-5.4.0-148-generic - Linux kernel headers for version 5.4.0 on 64 bit x86 SMP
linux-headers-5.4.0-148-lowlatency - Linux kernel headers for version 5.4.0 on 64 bit x86 SMP
linux-hwe-5.4-cloud-tools-5.4.0-148 - Linux kernel version specific cloud tools for version 5.4.0-148
linux-hwe-5.4-headers-5.4.0-148 - Header files related to Linux kernel version 5.4.0
linux-hwe-5.4-tools-5.4.0-148 - Linux kernel version specific tools for version 5.4.0-148
linux-image-5.4.0-148-generic - Signed kernel image generic
linux-image-5.4.0-148-lowlatency - Signed kernel image lowlatency
linux-image-unsigned-5.4.0-148-generic - Linux kernel image for version 5.4.0 on 64 bit x86 SMP
linux-image-unsigned-5.4.0-148-lowlatency - Linux kernel image for version 5.4.0 on 64 bit x86 SMP
linux-modules-5.4.0-148-generic - Linux kernel extra modules for version 5.4.0 on 64 bit x86 SMP
linux-modules-5.4.0-148-lowlatency - Linux kernel extra modules for version 5.4.0 on 64 bit x86 SMP
linux-modules-extra-5.4.0-148-generic - Linux kernel extra modules for version 5.4.0 on 64 bit x86 SMP
linux-tools-5.4.0-148-generic - Linux kernel version specific tools for version 5.4.0-148
linux-tools-5.4.0-148-lowlatency - Linux kernel version specific tools for version 5.4.0-148
# 安装指定的内核版本
sudo apt-get install linux-headers-5.4.0-148-generic linux-image-5.4.0-148-generic
# 当前系统中内核的启动顺序
ubuntu@ubuntu:~$ grep menuentry /boot/grub/grub.cfg
if [ x"${feature_menuentry_id}" = xy ]; then
menuentry_id_option="--id"
menuentry_id_option=""
export menuentry_id_option
menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-79c7761d-9676-433e-884c-516b6c45d576' {
submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-79c7761d-9676-433e-884c-516b6c45d576' {
menuentry 'Ubuntu, with Linux 6.3.3-060303-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-6.3.3-060303-generic-advanced-79c7761d-9676-433e-884c-516b6c45d576' {
menuentry 'Ubuntu, with Linux 6.3.3-060303-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-6.3.3-060303-generic-recovery-79c7761d-9676-433e-884c-516b6c45d576' {
menuentry 'Ubuntu, with Linux 5.4.0-148-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-148-generic-advanced-79c7761d-9676-433e-884c-516b6c45d576' {
menuentry 'Ubuntu, with Linux 5.4.0-148-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-148-generic-recovery-79c7761d-9676-433e-884c-516b6c45d576' {
menuentry 'Ubuntu, with Linux 5.4.0-147-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-147-generic-advanced-79c7761d-9676-433e-884c-516b6c45d576' {
menuentry 'Ubuntu, with Linux 5.4.0-147-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-147-generic-recovery-79c7761d-9676-433e-884c-516b6c45d576' {
menuentry 'Ubuntu, with Linux 5.4.0-120-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-120-generic-advanced-79c7761d-9676-433e-884c-516b6c45d576' {
menuentry 'Ubuntu, with Linux 5.4.0-120-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.4.0-120-generic-recovery-79c7761d-9676-433e-884c-516b6c45d576' {
menuentry 'Memory test (memtest86+)' {
menuentry 'Memory test (memtest86+, serial console 115200)' {
# 修改内核启动顺序
sudo vim /etc/default/grub
第一步:GRUB_DEFAULT=0
第二步: GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 5.4.0-120-generic"
将 第一步 修改为 第二步
# 执行update-grub 命令更新启动配置
sudo update-grub
# 重启系统查看内核版本
ubuntu@ubuntu:~$ uname -r
5.4.0-120-generic
#如果想要开机启动自由选择内核版本 请做如下配置
sudo vim /etc/default/grub
第一步 GRUB_TIMEOUT_STYLE=hidden
第一步 GRUB_TIMEOUT=0
第二步 # GRUB_TIMEOUT_STYLE=hidden
第二步 GRUB_TIMEOUT=10
第三步 执行update-grub 命令更新启动配置 sudo update-grub
将 第一步 修改为 第二步 然后执行 第三步
# 重启系统查看内核版本
ubuntu@ubuntu:~$ uname -r
5.4.0-120-generic
# 查看当前系统版本信息
ubuntu@ubuntu:~$ cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.2 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.2 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
ubuntu@ubuntu:~$
ubuntu@ubuntu:~$ uname -r
5.4.0-120-generic