孤儿 發表於 2019-8-8 18:34:00

UBUNTU切换内核

<p>查询可更换内核的序号<br><br>&nbsp;&nbsp;&nbsp; gedit /boot/grub/grub.cfg<br><br>查询已安装的内核和内核的序号。找到文件中的menuentry (图中在一大堆fi-else底下)<br><br>menuentry底下还有submenu,submenu底下就包含了 带有缩进的 menuentry。以下是计数规则:<br><br>&nbsp;&nbsp;&nbsp; 第一个menuentry 的序号是0,第二个submenu的序号是1,以此类推<br>&nbsp;&nbsp;&nbsp; 在submenu中,第一个menuentry的序号是0,第二个是1,以此类推<br><br>我摘录图中submenu中的第一个menuentry如下:<br><br>menuentry 'Ubuntu,Linux 4.15.0-34-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.15.0-34-generic-advanced-261d46dc-b223-49ee-a561-439009b15519' {<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;recordfail<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;load_video<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;gfxmode $linux_gfx_mode<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;insmod gzio<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;insmod part_gpt<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;insmod ext2<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;set root='hd0,gpt2'<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if [ x$feature_platform_search_hint = xy ]; then<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2&nbsp; 261d46dc-b223-49ee-a561-439009b15519<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; search --no-floppy --fs-uuid --set=root 261d46dc-b223-49ee-a561-439009b15519<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;fi<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;echo&nbsp;&nbsp; &nbsp;'载入 Linux 4.15.0-34-generic ...'<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; linux&nbsp;&nbsp; &nbsp;/boot/vmlinuz-4.15.0-34-generic root=UUID=261d46dc-b223-49ee-a561-439009b15519 ro&nbsp; quiet splash $vt_handoff<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;echo&nbsp;&nbsp; &nbsp;'载入初始化内存盘...'<br>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;initrd&nbsp;&nbsp; &nbsp;/boot/initrd.img-4.15.0-34-generic<br><br><br>意思是,这个menuentry就是内核 Linux 4.15.0-34-generic 的序号菜单了。这里就假设我需要把内核更换为它。它在submenu 的第一个menuentry。记住它,下一步要用。<br><br>(3)修改grub更换内核<br><br>&nbsp;&nbsp;&nbsp; sudo gedit /etc/default/grub<br><br>打开grub的编辑窗,如图所示:<br><br><br>如果没有使用grub修改过内核,除注释第一行应该显示的是<br><br>&nbsp;&nbsp;&nbsp; GRUB_DEFAULT=0<br><br>0就是默认的kernel了。我们要做的就是把GRUB_DEFAULT=0 改成<br><br>&nbsp;&nbsp;&nbsp; GRUB_DEFAULT=“1 &gt;0”<br><br>即可。请注意在(2)中提到的需要更换的内核Linux 4.15.0-34-generic在 submenu 的第一个menuentry,因此是“1 &gt;0“。如果它在submenu的第5个,那么就是 ”1 &gt;4“,唯一需要的就是数好这个!<br><br>同时,请注意一对英文分号""和1后面的空格也是必须的,万万不可少,也不可多!<br><br>(4)更新内核和重启<br><br>&nbsp;&nbsp;&nbsp; sudo update-grub<br>&nbsp;&nbsp;&nbsp; sudo reboot<br><br>重启完可以用uname -a查询内核已更换。<br><br></p><br><br>
来源:https://www.cnblogs.com/penuel/p/11323004.html
頁: [1]
查看完整版本: UBUNTU切换内核