Ubuntu下如何删除旧内核

如果登录的时候碰到提示/boot分区空间已满,类似

=> /boot is using 99.1% of 235MB

或者更新版本的时候报/boot分区空间已满,导致更新报错,并且无法安装或者卸载文件,

Unpacking linux-image-3.13.0-65-generic (3.13.0-65.105) ...
dpkg: error processing archive /var/cache/apt/archives/linux-image-3.13.0-65-generic_3.13.0-65.105_amd64.deb (--unpack):
 cannot copy extracted data for './boot/System.map-3.13.0-65-generic' to '/boot/System.map-3.13.0-65-generic.dpkg-new': 
failed to write (No space left on device)
No apport report written because the error message indicates a disk full error
dpkg-deb: error: subprocess paste was killed by signal (Broken pipe)

这个时候得删除旧内核了,一般思路如下

#判断当前运行的版本,免得误删除当前运行版本
>sudo uname -r 
3.13.0-65-generic

#查看当前安装的内核版本
>sudo dpkg --list | grep linux-image 

ii  linux-image-3.13.0-61-generic       3.13.0-61.100                    amd64        Linux kernel image for version 3.13.0 on 64 bit x86 SMP
rc  linux-image-3.13.0-62-generic       3.13.0-62.102                    amd64        Linux kernel image for version 3.13.0 on 64 bit x86 SMP
rc  linux-image-3.13.0-63-generic       3.13.0-63.103                    amd64        Linux kernel image for version 3.13.0 on 64 bit x86 SMP
ii  linux-image-3.13.0-65-generic       3.13.0-65.105                    amd64        Linux kernel image for version 3.13.0 on 64 bit x86 SMP
rc  linux-image-extra-3.13.0-62-generic 3.13.0-62.102                    amd64        Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
rc  linux-image-extra-3.13.0-63-generic 3.13.0-63.103                    amd64        Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
ii  linux-image-extra-3.13.0-65-generic 3.13.0-65.105                    amd64        Linux kernel extra modules for version 3.13.0 on 64 bit x86 SMP
ii  linux-image-generic                 3.13.0.65.71                     amd64        Generic Linux kernel image

#找到卸载除较低的版本
sudo apt-get purge linux-image-3.13.0-61-generic  linux-image-3.13.0-62-generic

#如果无法卸载,可以到/boot目录下把较低版本的文件手工删除(rm),然后把没有完成的安装完成(一般是sudo apt-get -f install),再做步骤三

#自动删除没有用的packages
sudo apt-get autoremove 

#别忘了执行下面的代码
sudo update-grub2

一条语句删除除运行之外的内核,

sudo apt-get purge ~ilinux-image-.*\(\!`uname -r`\)

如果是桌面程序,可以选择使用ubuntu-tweak在桌面环境下完成各种工作,当然包括旧内核的删除