标题: Ubuntu 22用指定版本内核启动 最近在VM中新装了Ubuntu 22.04.1 LTS (Jammy Jellyfish),要测试些东西,比如 SystemTap、crash、eBPF、rr-debugger之流。一时不查,这货自动升级内核了。一 般情况下倒也没啥大不了的,但因故需要 aptitude install linux-headers-$(uname -r) linux-image-$(uname -r)-dbgsym dbgsym下载时有1G左右,在寡妇王为祸人间的岁月里,谁特么受得了这升级频率啊。 赶紧把Ubuntu 22的自动升级停了,参看 《Ubuntu 22禁用自动升级》 https://scz.617.cn/unix/202204211533.txt 紧停慢停自动升级,仍偷摸给我升了两个内核版本,最初的5.15.0-48渣都不剩了。 $ ls -lh /boot/vmlinuz* lrwxrwxrwx 1 root root 25 Oct 21 06:18 /boot/vmlinuz -> vmlinuz-5.15.0-52-generic -rw------- 1 root root 12M Sep 20 20:58 /boot/vmlinuz-5.15.0-50-generic -rw------- 1 root root 12M Oct 13 15:49 /boot/vmlinuz-5.15.0-52-generic lrwxrwxrwx 1 root root 25 Oct 21 06:18 /boot/vmlinuz.old -> vmlinuz-5.15.0-50-generic 下了这两个版本的dbgsym $ ls -lh /usr/lib/debug/boot/vmlinux-* -rw-r--r-- 1 root root 703M Sep 20 17:17 /usr/lib/debug/boot/vmlinux-5.15.0-50-generic -rw-r--r-- 1 root root 703M Oct 13 15:40 /usr/lib/debug/boot/vmlinux-5.15.0-52-generic 突然想起,启动时没出现GRUB菜单,没让我选vmlinuz.old。随手搜了一下,做个笔 记。参看 -------------------------------------------------------------------------- How can I boot with an older kernel version - [2011-11-23] https://askubuntu.com/questions/82140/how-can-i-boot-with-an-older-kernel-version Editing the default boot item in grub menu - [2011-10-18] https://askubuntu.com/questions/68547/editing-the-default-boot-item-in-grub-menu-a-definitive-answer -------------------------------------------------------------------------- 重启时按住Shift,出现菜单,选"Advanced options for Ubuntu",选旧版内核启动, Shift不灵时试试ESC。 $ vi /etc/default/grub 关注这三行 GRUB_DEFAULT=0 GRUB_TIMEOUT_STYLE=hidden GRUB_TIMEOUT=0 改成 GRUB_DEFAULT="1>0" #GRUB_TIMEOUT_STYLE=hidden GRUB_TIMEOUT=5 "1>0"表示先在第一张菜单里选第1项(从0计),再在第二张菜单里选第0项,实际使用 5.15.0-52版内核。若想用5.15.0-50版内核,改成"1>2"。启动时按Shift能看到这两 张菜单,若未记住第二张菜单,可用如下命令查看 $ grub-mkconfig | grep -E "menuentry 'Ubuntu, with Linux" | awk '{print i++ " : "$1, $2, $3, $4, $5, $6, $7}' ... 0 : menuentry 'Ubuntu, with Linux 5.15.0-52-generic' --class ubuntu 1 : menuentry 'Ubuntu, with Linux 5.15.0-52-generic (recovery mode)' 2 : menuentry 'Ubuntu, with Linux 5.15.0-50-generic' --class ubuntu 3 : menuentry 'Ubuntu, with Linux 5.15.0-50-generic (recovery mode)' 注释掉GRUB_TIMEOUT_STYLE,不按Shift就会直接出现第一张菜单。GRUB_TIMEOUT为 -1时表示无限等待,否则就是秒数。 update-grub systemctl reboot uname -r 我是那种需求驱动型的,没有需求时绝不折腾,所以一直不曾配过这茬,贻笑大方了。 在技术分享这件事情上,我一般是搂草打兔子,不刻意分享,分享的都是自己过去不 曾折腾过、现下刚学习的新技能。所以很容易发现,我不会的东西超级多,这与不少 人对我的想象有出入,换个说法,每一次分享都是自曝其短。二十多年来,发现一些 有意思的现象,我分享的那种之前放狗搜不着答案的内容,其实是有价值的,偏生那 种内容无人欣赏,反倒只是随手搜来翻译测试一番的大路货,应者云集,对此现象颇 为感慨。