grub2配置

環境:ubuntu14.04python

默認配置文件路徑/etc/default/grublinux

例子:ios

GRUB_DEFAULT=0 #默認啓動那一個
#GRUB_HIDDEN_TIMEOUT=15 #選擇菜單是否隱藏,註釋掉就直接顯示了
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""

更新grup調用ubuntu

ubuntu@ubuntu-Lenovo-Product:~$ sudo update-grub
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.16.0-031600-generic
Found initrd image: /boot/initrd.img-3.16.0-031600-generic
Found linux image: /boot/vmlinuz-3.13.0-43-generic
Found initrd image: /boot/initrd.img-3.13.0-43-generic
Found linux image: /boot/vmlinuz-3.13.0-41-generic
Found initrd image: /boot/initrd.img-3.13.0-41-generic
Found linux image: /boot/vmlinuz-3.13.0-24-generic
Found initrd image: /boot/initrd.img-3.13.0-24-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
done

而後如上所示update-grup會在系統裏找編譯好的內核,試過放在根目錄/也能找到。ide

update-grup找完內核後,開始更新文件/boot/grub/grub.cfgui

這個文件裏有開機啓動菜單入口信息,以下:spa

menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668' {
	recordfail
	load_video
	gfxmode $linux_gfx_mode
	insmod gzio
	insmod part_msdos
	insmod ext2
	set root='hd0,msdos1'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668
	else
	  search --no-floppy --fs-uuid --set=root e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668
	fi
	linux	/boot/vmlinuz-3.16.0-031600-generic root=UUID=e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668 ro  quiet splash $vt_handoff
	initrd	/boot/initrd.img-3.16.0-031600-generic
}
submenu 'Advanced options for Ubuntu' $menuentry_id_option 'gnulinux-advanced-e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668' {
	menuentry 'Ubuntu, with Linux 3.16.0-031600-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.16.0-031600-generic-advanced-e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668' {
		recordfail
		load_video
		gfxmode $linux_gfx_mode
		insmod gzio
		insmod part_msdos
		insmod ext2
		set root='hd0,msdos1'
		if [ x$feature_platform_search_hint = xy ]; then
		  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668
		else
		  search --no-floppy --fs-uuid --set=root e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668
		fi
		echo	'Loading Linux 3.16.0-031600-generic ...'
		linux	/boot/vmlinuz-3.16.0-031600-generic root=UUID=e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668 ro  quiet splash $vt_handoff
		echo	'Loading initial ramdisk ...'
		initrd	/boot/initrd.img-3.16.0-031600-generic
	}
	menuentry 'Ubuntu, with Linux 3.16.0-031600-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.16.0-031600-generic-recovery-e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668' {
		recordfail
		load_video
		insmod gzio
		insmod part_msdos
		insmod ext2
		set root='hd0,msdos1'
		if [ x$feature_platform_search_hint = xy ]; then
		  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668
		else
		  search --no-floppy --fs-uuid --set=root e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668
		fi
		echo	'Loading Linux 3.16.0-031600-generic ...'
		linux	/boot/vmlinuz-3.16.0-031600-generic root=UUID=e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668 ro recovery nomodeset 
		echo	'Loading initial ramdisk ...'
		initrd	/boot/initrd.img-3.16.0-031600-generic
	}
	menuentry 'Ubuntu, with Linux 3.13.0-43-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.13.0-43-generic-advanced-e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668' {
		recordfail
		load_video
		gfxmode $linux_gfx_mode
		insmod gzio
		insmod part_msdos
		insmod ext2
		set root='hd0,msdos1'
		if [ x$feature_platform_search_hint = xy ]; then
		  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668
		else
		  search --no-floppy --fs-uuid --set=root e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668
		fi
		echo	'Loading Linux 3.13.0-43-generic ...'
		linux	/boot/vmlinuz-3.13.0-43-generic root=UUID=e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668 ro  quiet splash $vt_handoff
		echo	'Loading initial ramdisk ...'
		initrd	/boot/initrd.img-3.13.0-43-generic
	}
	menuentry 'Ubuntu, with Linux 3.13.0-43-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.13.0-43-generic-recovery-e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668' {
		recordfail
		load_video
		insmod gzio
		insmod part_msdos
		insmod ext2
		set root='hd0,msdos1'
		if [ x$feature_platform_search_hint = xy ]; then
		  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668
		else
		  search --no-floppy --fs-uuid --set=root e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668
		fi
		echo	'Loading Linux 3.13.0-43-generic ...'
		linux	/boot/vmlinuz-3.13.0-43-generic root=UUID=e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668 ro recovery nomodeset 
		echo	'Loading initial ramdisk ...'
		initrd	/boot/initrd.img-3.13.0-43-generic
	}
	menuentry 'Ubuntu, with Linux 3.13.0-41-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.13.0-41-generic-advanced-e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668' {
		recordfail
		load_video
		gfxmode $linux_gfx_mode
		insmod gzio
		insmod part_msdos
		insmod ext2
		set root='hd0,msdos1'
		if [ x$feature_platform_search_hint = xy ]; then
		  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668
		else
		  search --no-floppy --fs-uuid --set=root e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668
		fi
		echo	'Loading Linux 3.13.0-41-generic ...'
		linux	/boot/vmlinuz-3.13.0-41-generic root=UUID=e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668 ro  quiet splash $vt_handoff
		echo	'Loading initial ramdisk ...'
		initrd	/boot/initrd.img-3.13.0-41-generic
	}
	menuentry 'Ubuntu, with Linux 3.13.0-41-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.13.0-41-generic-recovery-e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668' {
		recordfail
		load_video
		insmod gzio
		insmod part_msdos
		insmod ext2
		set root='hd0,msdos1'
		if [ x$feature_platform_search_hint = xy ]; then
		  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668
		else
		  search --no-floppy --fs-uuid --set=root e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668
		fi
		echo	'Loading Linux 3.13.0-41-generic ...'
		linux	/boot/vmlinuz-3.13.0-41-generic root=UUID=e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668 ro recovery nomodeset 
		echo	'Loading initial ramdisk ...'
		initrd	/boot/initrd.img-3.13.0-41-generic
	}
	menuentry 'Ubuntu, with Linux 3.13.0-24-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.13.0-24-generic-advanced-e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668' {
		recordfail
		load_video
		gfxmode $linux_gfx_mode
		insmod gzio
		insmod part_msdos
		insmod ext2
		set root='hd0,msdos1'
		if [ x$feature_platform_search_hint = xy ]; then
		  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668
		else
		  search --no-floppy --fs-uuid --set=root e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668
		fi
		echo	'Loading Linux 3.13.0-24-generic ...'
		linux	/boot/vmlinuz-3.13.0-24-generic root=UUID=e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668 ro  quiet splash $vt_handoff
		echo	'Loading initial ramdisk ...'
		initrd	/boot/initrd.img-3.13.0-24-generic
	}
	menuentry 'Ubuntu, with Linux 3.13.0-24-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-3.13.0-24-generic-recovery-e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668' {
		recordfail
		load_video
		insmod gzio
		insmod part_msdos
		insmod ext2
		set root='hd0,msdos1'
		if [ x$feature_platform_search_hint = xy ]; then
		  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668
		else
		  search --no-floppy --fs-uuid --set=root e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668
		fi
		echo	'Loading Linux 3.13.0-24-generic ...'
		linux	/boot/vmlinuz-3.13.0-24-generic root=UUID=e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668 ro recovery nomodeset 
		echo	'Loading initial ramdisk ...'
		initrd	/boot/initrd.img-3.13.0-24-generic
	}
}

### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_linux_xen ###

### END /etc/grub.d/20_linux_xen ###

### BEGIN /etc/grub.d/20_memtest86+ ###
menuentry 'Memory test (memtest86+)' {
	insmod part_msdos
	insmod ext2
	set root='hd0,msdos1'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668
	else
	  search --no-floppy --fs-uuid --set=root e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668
	fi
	knetbsd	/boot/memtest86+.elf
}
menuentry 'Memory test (memtest86+, serial console 115200)' {
	insmod part_msdos
	insmod ext2
	set root='hd0,msdos1'
	if [ x$feature_platform_search_hint = xy ]; then
	  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1  e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668
	else
	  search --no-floppy --fs-uuid --set=root e96bea5c-cd18-4b7d-b4a6-1f7ad59b6668
	fi
	linux16	/boot/memtest86+.bin console=ttyS0,115200n8
}

能夠看到地一個menuentry有submenu 'Advanced options for Ubuntu',submenu裏邊嵌套menuentry(結構同樣)code

以前提到的配置文件/etc/default/grub的DEFAULT_ENTRY指的是第一層的menuentry而不是submenu的。在上面的例子若是DEFAULT_ENTRY=1就表示默認啓動menuentry 'Memory test (memtest86+)。orm

在submenu裏看到有不少不一樣內核,update-grub會選能檢測到的版本最新的內核做爲默認啓動項目,若是要換內核啓動能夠:ci

  1. 開機時手工選擇submenu的啓動項。

  2. 讓update-grub選擇爲默認內核,能夠把不用的高版本內核備份起來(update-grub搜索的時候就找不到該內核),或者可能有命令選擇內核(暫時沒找到)。

相關文章
相關標籤/搜索