• Ubuntu 指定默认启动内核


    版本:Ubuntu 18.04

    可以通过开机启动Ubuntu时按 ESC 键来进入GRUB选项,

    选择 Advanced options for Ubuntu,然后可以看到所有内核启动菜单,Index从0开始。

    或者输入以下命令:

    wayde@wayde-desktop:~$ cat /boot/grub/grub.cfg |grep menuentry
    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-a0b77529-08f4-4fbc-b3a8-85bb77db44e8' {
    submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-a0b77529-08f4-4fbc-b3a8-85bb77db44e8' {
        menuentry 'Ubuntu, with Linux 5.3.0-59-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.3.0-59-generic-advanced-a0b77529-08f4-4fbc-b3a8-85bb77db44e8' {
        menuentry 'Ubuntu, with Linux 5.3.0-59-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.3.0-59-generic-recovery-a0b77529-08f4-4fbc-b3a8-85bb77db44e8' {
        menuentry 'Ubuntu, with Linux 5.3.0-53-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.3.0-53-generic-advanced-a0b77529-08f4-4fbc-b3a8-85bb77db44e8' {
        menuentry 'Ubuntu, with Linux 5.3.0-53-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.3.0-53-generic-recovery-a0b77529-08f4-4fbc-b3a8-85bb77db44e8' {
        menuentry 'Ubuntu, with Linux 5.3.0' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.3.0-advanced-a0b77529-08f4-4fbc-b3a8-85bb77db44e8' {
        menuentry 'Ubuntu, with Linux 5.3.0 (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.3.0-recovery-a0b77529-08f4-4fbc-b3a8-85bb77db44e8' {
        menuentry 'Ubuntu, with Linux 4.19.65-d1' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.19.65-d1-advanced-a0b77529-08f4-4fbc-b3a8-85bb77db44e8' {
        menuentry 'Ubuntu, with Linux 4.19.65-d1 (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.19.65-d1-recovery-a0b77529-08f4-4fbc-b3a8-85bb77db44e8' {
    menuentry 'System setup' $menuentry_id_option 'uefi-firmware' {

    Index同样从0开始,记住你需要指定内核的Index

    修改grub文件,修改后如下:

    wayde@wayde-desktop:~$ cat /etc/default/grub
    # If you change this file, run 'update-grub' afterwards to update
    # /boot/grub/grub.cfg.
    # For full documentation of the options in this file, see:
    #   info -f grub -n 'Simple configuration'
    
    GRUB_DEFAULT="1>6"
    GRUB_TIMEOUT_STYLE=hidden
    GRUB_TIMEOUT=0
    GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash ignore_loglevel log_buf_len=32M console=tty i915.enable_gvt=1 i915.enable_fbc=0 kvm.ignore_msrs=1 intel_iommu=on,igfx_off drm.debug=0"
    GRUB_CMDLINE_LINUX=""
    
    # Uncomment to enable BadRAM filtering, modify to suit your needs
    # This works with Linux (no patch required) and with any kernel that obtains
    # the memory map information from GRUB (GNU Mach, kernel of FreeBSD ...)
    #GRUB_BADRAM="0x01234567,0xfefefefe,0x89abcdef,0xefefefef"
    
    # Uncomment to disable graphical terminal (grub-pc only)
    #GRUB_TERMINAL=console
    
    # The resolution used on graphical terminal
    # note that you can use only modes which your graphic card supports via VBE
    # you can see them in real GRUB with the command `vbeinfo'
    #GRUB_GFXMODE=640x480
    
    # Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
    #GRUB_DISABLE_LINUX_UUID=true
    
    # Uncomment to disable generation of recovery mode menu entries
    #GRUB_DISABLE_RECOVERY="true"
    
    # Uncomment to get a beep at grub start
    #GRUB_INIT_TUNE="480 440 1"

    以上只修改了 GRUB_DEFAULT="1>6" 部分,1代表启动时第一层菜单里的 Advanced options for Ubuntu,6即为指定内核的Index。

    注意引号是必须的。

    另一种方法是直接填入内核的名称:

    GRUB_DEFAULT="Ubuntu, with Linux 4.19.65-d1"

    update grub后会有警告提示使用新的名称格式:

    root@wayde-desktop:/home/wayde# update-grub
    Sourcing file `/etc/default/grub'
    Generating grub configuration file ...
    Found linux image: /boot/vmlinuz-5.3.0-59-generic
    Found initrd image: /boot/initrd.img-5.3.0-59-generic
    Found linux image: /boot/vmlinuz-5.3.0-53-generic
    Found initrd image: /boot/initrd.img-5.3.0-53-generic
    Found linux image: /boot/vmlinuz-5.3.0
    Found initrd image: /boot/initrd.img-5.3.0
    Found linux image: /boot/vmlinuz-4.19.65-d1
    Found initrd image: /boot/initrd.img-4.19.65-d1
    Warning: Please don't use old title `Ubuntu, with Linux 4.19.65-d1' for GRUB_DEFAULT, use `Advanced options for Ubuntu>Ubuntu, with Linux 4.19.65-d1' (for versions before 2.00) or `gnulinux-advanced-a0b77529-08f4-4fbc-b3a8-85bb77db44e8>gnulinux-4.19.65-d1-advanced-a0b77529-08f4-4fbc-b3a8-85bb77db44e8' (for 2.00 or later)
    Adding boot menu entry for EFI firmware configuration
    done

    按照其提示的名字再次进行修改即可。

    修改完毕之后:

    sudo update-grub

    重启即可自动从指定内核启动。

  • 相关阅读:
    java中数组的相关知识
    如何搭建Java开发环境(包括下载、安装和配置JDK)和Eclipse的安装
    java 8种基本数据类型的默认值及所占字节数
    C语言编写的简单的电话本管理系统
    C语言题库的上机题
    Spring Boot使用AJAX从数据库读取数据异步刷新前端表格
    JS,jQuery获取select标签中选中值的方法
    jQuery效果与扩展:左右滑动
    使用EasyUI创建分页对比效果
    一些关于链表操作的代码
  • 原文地址:https://www.cnblogs.com/zoneofmine/p/13229347.html
Copyright © 2020-2023  润新知