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

 

重啟即可自動從指定內核啟動。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM