升级内核后如何删除旧内核

在升级新的内核后,如何删除旧的内核文件?

举例来说,假设我们刚刚运行了 apt-get dist-upgrade 升级到了仓库中最新的内核版本(如从 3.2.0-30 升级到了 3.2.0-34)

Default

$ sudo apt-get dist-upgrade
Reading package lists… Done
Building dependency tree
Reading state information… Done
Calculating upgrade… Done
The following NEW packages will be installed:
libframe6 libgeis1 libgrail5 linux-headers-3.2.0-34
linux-headers-3.2.0-34-generic linux-image-3.2.0-34-generic
The following packages will be upgraded:
libgrip0 linux-headers-generic linux-image-generic
3 upgraded, 6 newly installed, 0 to remove and 0 not upgraded.
Need to get 50.9 MB of archives.
After this operation, 181 MB of additional disk space will be used.
Do you want to continue [Y/n]? y

$ sudo apt-get dist-upgrade
Reading package lists… Done
Building dependency tree
Reading state information… Done
Calculating upgrade… Done
The following NEW packages will be installed:
libframe6 libgeis1 libgrail5 linux-headers-3.2.0-34
linux-headers-3.2.0-34-generic linux-image-3.2.0-34-generic
The following packages will be upgraded:
libgrip0 linux-headers-generic linux-image-generic
3 upgraded, 6 newly installed, 0 to remove and 0 not upgraded.
Need to get 50.9 MB of archives.
After this operation, 181 MB of additional disk space will be used.
Do you want to continue [Y/n]? y

首先我们需要知道已经安装了哪些内核版本,可以使用下面的命令:

Default

$ dpkg --get-selections | grep linux
fonts-linuxlibertine install
libselinux1 install
linux-firmware install
linux-headers-3.2.0-30 install
linux-headers-3.2.0-30-generic install
linux-headers-3.2.0-34 install
linux-headers-3.2.0-34-generic install
linux-headers-generic install
linux-image-3.2.0-30-generic install
linux-image-3.2.0-34-generic install
linux-image-generic install
linux-libc-dev install
linux-sound-base install
pptp-linux install
syslinux install
syslinux-common install
util-linux install

$ dpkg --get-selections | grep linux
fonts-linuxlibertine install
libselinux1 install
linux-firmware install
linux-headers-3.2.0-30 install
linux-headers-3.2.0-30-generic install
linux-headers-3.2.0-34 install
linux-headers-3.2.0-34-generic install
linux-headers-generic install
linux-image-3.2.0-30-generic install
linux-image-3.2.0-34-generic install
linux-image-generic install
linux-libc-dev install
linux-sound-base install
pptp-linux install
syslinux install
syslinux-common install
util-linux install
这样,我们就可以从中找到旧的内核文件(linux-headers-3.2.0-30 linux-headers-3.2.0-30-generic linux-image-3.2.0-30-generic),相应地将他们删除:

Default

$ sudo apt-get purge linux-headers-3.2.0-30 linux-headers-3.2.0-30-generic linux-image-3.2.0-30-generic
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following packages will be REMOVED:
linux-headers-3.2.0-30* linux-headers-3.2.0-30-generic*
linux-image-3.2.0-30-generic*
0 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
After this operation, 180 MB disk space will be freed.
Do you want to continue [Y/n]? y

$ sudo apt-get purge linux-headers-3.2.0-30 linux-headers-3.2.0-30-generic linux-image-3.2.0-30-generic
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following packages will be REMOVED:
linux-headers-3.2.0-30* linux-headers-3.2.0-30-generic*
linux-image-3.2.0-30-generic*
0 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
After this operation, 180 MB disk space will be freed.
Do you want to continue [Y/n]? y

Linux Deepin 在使用 apt-get 更新与删除旧内核后会自动调用 update-grub 更新 grub.cfg 文件,这样,我们就不用担心删除旧内核后因为 grub 的配置原因而无法从新的内核启动的问题。

重启后,我们即可在新的 grub 菜单中从新内核启动。

你可能感兴趣的:(linux)