说明:
因原机器硬件比较老旧,安装新版本的Ubuntu系统出现硬件不兼容情况,在使用过程中工程师执行sudo apt upgrade会导致系统启动黑屏或网卡连接不到,采用固定内核版本避免此类问题。
查看系统版本与当前使用内核
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.4 LTS
Release: 22.04
Codename: jammy
$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.4 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.4 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
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"
UBUNTU_CODENAME=jammy
$ uname -r
6.8.0-40-generic
$ grep submenu /boot/grub/grub.cfg
submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-fdcfa179-9776-4e47-87ec-acce29837d3e' {
grep gnulinux /boot/grub/grub.cfg
系统可用内核
$ dpkg --get-selections | grep linux-image
linux-image-6.5.0-18-generic install
linux-image-6.8.0-40-generic install
linux-image-generic-hwe-22.04 install
$ grep gnulinux /boot/grub/grub.cfg
menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-fdcfa179-9776-4e47-87ec-acce29837d3e' {
submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-fdcfa179-9776-4e47-87ec-acce29837d3e' {
menuentry 'Ubuntu, with Linux 6.8.0-40-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-6.8.0-40-generic-advanced-fdcfa179-9776-4e47-87ec-acce29837d3e' {
menuentry 'Ubuntu, with Linux 6.8.0-40-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-6.8.0-40-generic-recovery-fdcfa179-9776-4e47-87ec-acce29837d3e' {
menuentry 'Ubuntu, with Linux 6.5.0-18-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-6.5.0-18-generic-advanced-fdcfa179-9776-4e47-87ec-acce29837d3e' {
menuentry 'Ubuntu, with Linux 6.5.0-18-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-6.5.0-18-generic-recovery-fdcfa179-9776-4e47-87ec-acce29837d3e' {
系统内核配置文件
vim /etc/default/grub
GRUB_DEFAULT=0 # 这里修改内核版本:GRUB_DEFAULT="gnulinux-6.8.0-40-generic-advanced-fdcfa179-9776-4e47-87ec-acce29837d3e"
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""
更新grub
$ sudo update-grub
$ reboot
禁止启用升级内核命令
sudo apt-mark hold linux-image-6.8.0-40-generic # 禁用
sudo apt-mark unhold linux-image-6.8.0-40-generic # 启用
小结:
ubuntu系统在安装后会打开自动更新,可以通过图形界面关闭,同样也可以通过命令配置,在生产过程中尽可能保证系统的稳定和一致性。