美文网首页
Linux修改默认内核

Linux修改默认内核

作者: SilentDawn | 来源:发表于2018-07-04 11:24 被阅读0次

    CentOS 7

      1. 查看系统内部有多少个内核:
    cat /boot/grub2/grub.cfg |grep menuentry
    
      1. 配置从默认内核启动,下面命令的内核名称根据系统内部查到的实际名称来替换:
    grub2-set-default “CentOS Linux (4.4.138) 7 (Core)”
    
      1. 验证是否配置成功:
    grub2-editenv list
    

    Ubuntu16.04

    • 0.环境准备
      Ubuntu16.04,内核版本4.10.0,新内核版本4.4.137
    • 1.修改grub配置文件
      编辑/etc/default/grub文件,将其中的GRUB_DEFAULT的值修改为saved
    sudo gedit /etc/default/grub
    
    • 2.查看系统内部已安装的内核
    sudo cat /boot/grub/grub.cfg | grep menuentry
    

    选择新的默认内核,内核名称在menuentry后的双引号内,例如上述命令显示结果如下,从其中选择Ubuntu, with Linux 4.4.137作为新的启动内核

    menuentry 'Ubuntu, with Linux 4.10.0-28-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.10.0-28-generic-advanced-a58882f8-c86d-4817-8517-0b846a106892' {
        menuentry 'Ubuntu, with Linux 4.10.0-28-generic (upstart)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.10.0-28-generic-init-upstart-a58882f8-c86d-4817-8517-0b846a106892' {
        menuentry 'Ubuntu, with Linux 4.10.0-28-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.10.0-28-generic-recovery-a58882f8-c86d-4817-8517-0b846a106892' {
        menuentry 'Ubuntu, with Linux 4.4.137' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.137-advanced-a58882f8-c86d-4817-8517-0b846a106892' {
        menuentry 'Ubuntu, with Linux 4.4.137 (upstart)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.137-init-upstart-a58882f8-c86d-4817-8517-0b846a106892' {
        menuentry 'Ubuntu, with Linux 4.4.137 (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.137-recovery-a58882f8-c86d-4817-8517-0b846a106892' {
        menuentry 'Ubuntu, with Linux 4.4.137.old' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.137.old-advanced-a58882f8-c86d-4817-8517-0b846a106892' {
        menuentry 'Ubuntu, with Linux 4.4.137.old (upstart)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.137.old-init-upstart-a58882f8-c86d-4817-8517-0b846a106892' {
        menuentry 'Ubuntu, with Linux 4.4.137.old (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.137.old-recovery-a58882f8-c86d-4817-8517-0b846a106892'
    
    • 2.配置从默认内核启动
    sudo grub-set-default xxx
    

    其中xxx为选定的新内核的名称,例如此处的具体命令为

    sudo grub-set-default "Ubuntu, with Linux 4.4.137"
    

    更新grub配置

    sudo update-grub
    

    但Ubuntu16.04此处会报warning,warning信息如下

    Warning: Please don't use old title `Ubuntu, with Linux 4.4.137' for GRUB_DEFAULT, use `Advanced options for Ubuntu>Ubuntu, with Linux 4.4.137' (for versions before 2.00) or `gnulinux-advanced-a58882f8-c86d-4817-8517-0b846a106892>gnulinux-4.4.137-advanced-a58882f8-c86d-4817-8517-0b846a106892' (for 2.00 or later)
    
    

    warning中推荐使用Advanced options for Ubuntu>Ubuntu, with Linux 4.4.137,因此使用推荐的启动项(双引号内的内容)修改默认启动内核,例如

    sudo grub-set-default "Advanced options for Ubuntu>Ubuntu, with Linux 4.4.137"
    

    PS.在本人的测试中发下如果不使用Advanced选项,重启后仍为旧内核;每次grub-set-default后都需要update-grub

    • 3.重启验证
    sudo reboot
    uname -r
    

    相关文章

      网友评论

          本文标题:Linux修改默认内核

          本文链接:https://www.haomeiwen.com/subject/qzceuftx.html