写这篇文章一是为了对遇到同样问题的人提供一个参考,二来也是为了自己便于总结和查阅。希望大神勿喷。
好了,废话不多说了,转入正题。
前几天给自己的电脑装了个Ubuntu16.04LTS,自己顺手就把里边的软件什么的升级了一下。不知怎么地把内核升级到了4.8.0-26-generic,然后电脑就USB老出毛病(在开机之前插上优盘的话可以读出优盘,开机后插上就没反应,但USB可以有电)。耳机也不能用了,喇叭也没声音。自己也不懂怎么回事,就各种搜索。网上好多人说是内核和硬件不兼容,一般把显卡驱动卸载了就好了。我试了一下没有成功。后来注意到开机的时候提示Failed to start Load Kernel Modules。然后就转战内核方向。
看到也有网友遇到相似问题,并提出了解决方法:
然而我的问题并未如愿解决。然后想到了修改启动配置文件,更改系统默认加载的内核。
grep menuentry /boot/grub/grub.cfg
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查看,内核即为想要的内核。
然而我的没成功,没办法,只能卸载内核了。看到有牛人的方法(http://www.linuxdiyf.com/linux/20445.html),顺便就使用了,在此不再做赘述。
我在恢复模式用低版本内核进入系统后,检查不到4.8.0-26-generic内核,不知道是什么原因。命令如下:
dpkg -l | tail -n +6| grep -E 'linux-image-[0-9]+'| grep -Fv $(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
}
10.总结,经过大半天的折腾,终于可以正常使用了。我感觉直接执行第7步就可以。只是个人感觉而已,并没有经过实践检验。