Ubuntu 指定默认启动内核
Posted Zero to One
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
重启即可自动从指定内核启动。
以上是关于Ubuntu 指定默认启动内核的主要内容,如果未能解决你的问题,请参考以下文章
python 一个终端代码片段,在mac上生成可启动的usb live CD,以运行类似ubuntu或debian的内容。
LINUX PID 1和SYSTEMD PID 0 是内核的一部分,主要用于内进换页,内核初始化的最后一步就是启动 init 进程。这个进程是系统的第一个进程,PID 为 1,又叫超级进程(代码片段