Ubuntu16.04切换内核启动

时间:2021-08-01 03:49:30

1.该命令显示内核的启动顺序


zgw@zgw-ThinkPad:~$ grep menuentry /boot/grub/grub.cfg
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-5bce3795-da96-4c6f-bed2-67d37185a77d' {
submenu 'Ubuntu 高级选项' $menuentry_id_option 'gnulinux-advanced-5bce3795-da96-4c6f-bed2-67d37185a77d' {
menuentry 'Ubuntu,Linux 4.8.0-26-lowlatency' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.0-45-lowlatency-advanced-5bce3795-da96-4c6f-bed2-67d37185a77d' {
menuentry 'Ubuntu, with Linux 4.8.0-26-lowlatency (upstart)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.0-45-lowlatency-init-upstart-5bce3795-da96-4c6f-bed2-67d37185a77d' {
menuentry 'Ubuntu, with Linux 4.8.0-26-lowlatency (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.0-45-lowlatency-recovery-5bce3795-da96-4c6f-bed2-67d37185a77d' {
menuentry 'Ubuntu,Linux 4.8.0-26-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.0-45-generic-advanced-5bce3795-da96-4c6f-bed2-67d37185a77d' {
menuentry 'Ubuntu, with Linux 4.8.0-26-generic (upstart)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.0-45-generic-init-upstart-5bce3795-da96-4c6f-bed2-67d37185a77d' {
menuentry 'Ubuntu, with Linux 4.8.0-26-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.0-45-generic-recovery-5bce3795-da96-4c6f-bed2-67d37185a77d' {
menuentry 'Ubuntu,Linux 4.4.0-21-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.0-21-generic-advanced-5bce3795-da96-4c6f-bed2-67d37185a77d' {
menuentry 'Ubuntu, with Linux 4.4.0-21-generic (upstart)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.0-21-generic-init-upstart-5bce3795-da96-4c6f-bed2-67d37185a77d' {
menuentry 'Ubuntu, with Linux 4.4.0-21-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.4.0-21-generic-recovery-5bce3795-da96-4c6f-bed2-67d37185a77d' {
menuentry 'Memory test (memtest86+)' {
menuentry 'Memory test (memtest86+, serial console 115200)' {
 

2. 假设你要以4.4.0-21内核版本启动,则将文件/etc/default/grub中 

        

GRUB_DEFAULT=0 

改为 

GRUB_DEFAULT=6

或者改为

GRUB_DEFAULT=”Ubuntu,Linux 4.4.0-21-generic“

 保存后

3. 然后使用命令sudo update-grub

4.重新启动后输入uname -r查看,内核即为想要的内核。

 

5.直接把/boot/中4.8.0-26相关的文件及文件夹全部删除。命令如下:

sudo rm -rf *4.8.0-26*

6.然后修改了配置文件:/boot/grub/grub.cfg

sudo cp /etc/boot/grub/grub.cfg /etc/boot/grub/grub.cfg.bak.zgw
sudo vim /etc/boot/grub/grub.cfg

7.找到如下代码块(我的为148,149行):

linux    /vmlinuz-4.8.0-26-generic root=UUID=5bce3795-da96-4c6f-bed2-67d37185a77d ro  quiet splash $vt_handoff
initrd /initrd.img-4.8.0-26-generic

将其改为自己想使用的内核,我的如下:

linux    /vmlinuz-4.4.0-45-generic root=UUID=5bce3795-da96-4c6f-bed2-67d37185a77d ro  quiet splash $vt_handoff
initrd /initrd.img-4.5.0-45-generic

8.然后重启电脑就可以了,如若不行,请找如下代码块(我的为151行)。

submenu 'Ubuntu 高级选项' $menuentry_id_option 'gnulinux-advanced-5bce3795-da96-4c6f-bed2-67d37185a77d' 

9.将此行代码下的与4.8.0-26相关的代码全部删除(我的为152~263行)然后重启就可以了。

menuentry 'Ubuntu,Linux 4.8.0-26-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.8.0-26-generic-advanced-5bce3795-da96-4c6f-bed2-67d37185a77d' {
recordfail
load_video
gfxmode $linux_gfx_mode
insmod gzio
if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
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 88421677-a988-4ff9-bf29-6c56aa4a9027
else
search --no-floppy --fs-uuid --set=root 88421677-a988-4ff9-bf29-6c56aa4a9027
fi
echo '载入 Linux 4.8.0-26-generic ...'
linux /vmlinuz-4.8.0-26-generic root=UUID=5bce3795-da96-4c6f-bed2-67d37185a77d ro quiet splash $vt_handoff
echo '载入初始化内存盘...'
initrd /initrd.img-4.8.0-26-generic
}
menuentry 'Ubuntu, with Linux 4.8.0-26-generic (upstart)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.8.0-26-generic-init-upstart-5bce3795-da96-4c6f-bed2-67d37185a77d' {
recordfail
load_video
gfxmode $linux_gfx_mode
insmod gzio
if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
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 88421677-a988-4ff9-bf29-6c56aa4a9027
else
search --no-floppy --fs-uuid --set=root 88421677-a988-4ff9-bf29-6c56aa4a9027
fi
echo '载入 Linux 4.8.0-26-generic ...'
linux /vmlinuz-4.8.0-26-generic root=UUID=5bce3795-da96-4c6f-bed2-67d37185a77d ro quiet splash $vt_handoff init=/sbin/upstart
echo '载入初始化内存盘...'
initrd /initrd.img-4.8.0-26-generic
}
menuentry 'Ubuntu, with Linux 4.8.0-26-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.8.0-26-generic-recovery-5bce3795-da96-4c6f-bed2-67d37185a77d' {
recordfail
load_video
insmod gzio
if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
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 88421677-a988-4ff9-bf29-6c56aa4a9027
else
search --no-floppy --fs-uuid --set=root 88421677-a988-4ff9-bf29-6c56aa4a9027
fi
echo '载入 Linux 4.8.0-26-generic ...'
linux /vmlinuz-4.8.0-26-generic root=UUID=5bce3795-da96-4c6f-bed2-67d37185a77d ro recovery nomodeset
echo '载入初始化内存盘...'
initrd /initrd.img-4.8.0-26-generic
}
menuentry 'Ubuntu,Linux 4.8.0-22-generic' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.8.0-22-generic-advanced-5bce3795-da96-4c6f-bed2-67d37185a77d' {
recordfail
load_video
gfxmode $linux_gfx_mode
insmod gzio
if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
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 88421677-a988-4ff9-bf29-6c56aa4a9027
else
search --no-floppy --fs-uuid --set=root 88421677-a988-4ff9-bf29-6c56aa4a9027
fi
echo '载入 Linux 4.8.0-22-generic ...'
linux /vmlinuz-4.8.0-22-generic root=UUID=5bce3795-da96-4c6f-bed2-67d37185a77d ro quiet splash $vt_handoff
echo '载入初始化内存盘...'
initrd /initrd.img-4.8.0-22-generic
}
menuentry 'Ubuntu, with Linux 4.8.0-22-generic (upstart)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.8.0-22-generic-init-upstart-5bce3795-da96-4c6f-bed2-67d37185a77d' {
recordfail
load_video
gfxmode $linux_gfx_mode
insmod gzio
if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
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 88421677-a988-4ff9-bf29-6c56aa4a9027
else
search --no-floppy --fs-uuid --set=root 88421677-a988-4ff9-bf29-6c56aa4a9027
fi
echo '载入 Linux 4.8.0-22-generic ...'
linux /vmlinuz-4.8.0-22-generic root=UUID=5bce3795-da96-4c6f-bed2-67d37185a77d ro quiet splash $vt_handoff init=/sbin/upstart
echo '载入初始化内存盘...'
initrd /initrd.img-4.8.0-22-generic
}
menuentry 'Ubuntu, with Linux 4.8.0-22-generic (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-4.8.0-22-generic-recovery-5bce3795-da96-4c6f-bed2-67d37185a77d' {
recordfail
load_video
insmod gzio
if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
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 88421677-a988-4ff9-bf29-6c56aa4a9027
else
search --no-floppy --fs-uuid --set=root 88421677-a988-4ff9-bf29-6c56aa4a9027
fi
echo '载入 Linux 4.8.0-22-generic ...'
linux /vmlinuz-4.8.0-22-generic root=UUID=5bce3795-da96-4c6f-bed2-67d37185a77d ro recovery nomodeset
echo '载入初始化内存盘...'
initrd /initrd.img-4.8.0-22-generic
}