我如何移除主线内核并回到支持的内核?

我最近在我的Ubuntu 12.04上升级到了3.4内核。之后,电脑无法启动。所以我使用了之前的内核来启动。实际上,我不想要3.4内核。那么我该如何删除它并继续使用之前的内核呢?
2个回答

你是怎么安装的?如果你只是下载了一堆deb文件并安装它们,那么想要卸载它就很简单了,只需要找到这些软件包并运行apt-get remove命令来逐个卸载它们。
我刚喝了一杯咖啡,所以你今天早上将会承受我全部的技术能力... 这个命令可以告诉你都安装了哪些内核:
dpkg -l | awk '/linux-[^ ]+-[0-9]/ {print $2}'

浏览这些并记录您想要删除的版本。请注意记录您当前的安装情况(uname -a)或自启动以来安装的任何新内核。您不希望删除最新的内核。
总之,当您有了想法后,可以通过调整以下命令批量删除它们:
sudo apt-get purge linux-{headers,image,image-extra}-3.5.0-{7,8,9}.*

在运行时,花括号中的单词和数字将被展开,因此实际上将针对以下包进行定位:
linux-headers-3.5.0-7*
linux-headers-3.5.0-8*
linux-headers-3.5.0-9*
linux-image-3.5.0-7*
linux-image-3.5.0-8*
linux-image-3.5.0-9*
linux-image-extra-3.5.0-7*
linux-image-extra-3.5.0-8*
linux-image-extra-3.5.0-9*

你可以为所欲为,但是在清理时,我发现这比使用通配符更安全(因为我目前使用的是3.5.*内核)。
无论如何,在选择“是”之前,请仔细阅读apt-get将要执行的操作。移除当前内核和所有内核是Ubuntu用户常见的困境。虽然不是无法修复,但是千万别这样做!
在使用通配符和apt-get时特别小心。如果你不相信我,请运行apt-get -s remove linux-image-3.4*并查看它选择了哪些内容(是的,所有内核)。不用担心,该命令处于“模拟模式”,因此不会执行任何操作(也不需要root权限)。

1将近四年过去了,你的警告依然属实。那天我刚好懒得动脑筋,准备度过一个头痛的一天,当我比平时更仔细地阅读确认信息时,真是险之又险! - Fissure King
你可以从中恢复过来,只是当你没有预料到的时候,这会让你感到非常痛苦。 - Oli

Uninstalling Mainline Kernels

The mainline kernels have their own ABI namespace so they install side by side with the stock Ubuntu kernels (each kernel has a separate directory under /lib/modules/VERSION for example). This means that you can keep several mainline and Ubuntu stock kernels installed at the same time and select the one you need from the GRUB boot menu.

If you would like to uninstall a mainline kernel anyway, first use:

dpkg -l | grep "linux\-[a-z]*\-"

to find the exact name of the kernel packages you want to uninstall, and then do:

sudo apt-get remove KERNEL_PACKAGES_TO_REMOVE

Remember that several packages belong to one kernel version: common headers, architecture specific headers and the architecture specific image.

来源: https://wiki.ubuntu.com/Kernel/MainlineBuilds#Uninstalling_Mainline_Kernels