`

【译】Remove Old Kernels in Ubuntu手动删除Ubuntu旧的内核

阅读更多

I've written a new post that shows a bash one-liner command that will remove the old kernels from your system in one step. You can check it out here .
我写了一篇文章,显示一个一行的bash命令,教你用一步删除您系统旧的内核。你可以看看这里

 

If you've been using Ubuntu Linux for a while, then you probably have a number of Linux kernel updates that have been installed on your system. (I've got a total of 3 kernels in my Karmic system already.) In all likelihood, these updates get installed and you boot into the latest kernel, never to use the older kernels again. But these old kernels are still hanging around on your system, cluttering up your grub boot screen and taking up space on your hard drive. 
如果你已经使用了一段时间的Ubuntu Linux,那么您可能有在更新的时候在你的系统上安装了好几个Linux内核里(在我的Karmic版本我都有总共三个内核版本了)。有很大的可能性, 这些更新的Linux版内核自从安装到你的电脑上,你永远不会再用旧的内核了。但是这些旧内核仍然徘徊在你的系统,搞乱你的grub开机画面并且占用了您 的硬盘驱动器空间。

There have been attempts made to create an automatic tool to clean these up for you along with much discussion on the Ubuntu Forums , but so far there's nothing officially in the repositories.
目前在Ubuntu论坛大量讨论尝试制作一个自动的工具来清洁这些,但至今还没有什么正式的仓库。

 

In the past, I've gone into Synaptic and searched for the older kernels and related packages and manually marked them for removal. This method works fine, but the search process is a little slow in Synaptic and you have to run a few searches to catch all of the packages to remove. I decided to come up with a way to do this from the terminal and hopefully save some time. The commands I'm going to use can be a bit daunting, so just copy and paste.
在过去,我总是进入新立得搜索和手动标记为删除旧的内核和相关的包。此方法效果很好,但是搜索过程是一个漫长的过程,你必须运行少量搜索,捕捉所有的软件 包删除。我决定想出一个办法做到这一点,希望节省一些时间。我使用的这些令可能会有点吓人,所以只要复制并粘贴就可以了。

Warning

Don't follow this process unless you're sure you don't need to boot into the older kernels. If you're not sure, just leave things alone. Also, it is possible to remove all of the kernels from your system and make it unbootable. I suggest leaving the latest kernel and one version previous to that. You can find out the kernel version that you're currently running with
除非你确定你不需要到老内核启动,否则别这样做。如果你不太确定,最好也别接下来的操作。此外,它可以从系统中删除所有的内核,使之无法启动。我强烈建议你保留最新版本的内核和一个最新的版本的前一个版本。你可以通过下边的命令找到你电脑上的内核的版本信息

uname -r

Find and remove old kernels

The first step is to figure out what kernels are installed. The following command will do the job.

第一步是配置出什么内核需要安装,运行下边的命令

ls /boot | grep vmlinuz | cut -d'-' -f2,3

Your result should look something like this.

运行之后你的结果可能是这样的

2.6.28-15
2.6.28-16
2.6.28-17

This is the list of kernels installed on your system. Now you want to find out which packages are installed relative to the kernel you want to remove. For my example I'm going to remove the oldest one, 2.6.28-15.

这个列表列出的是你的系统中安装的内横,现在你就应该找到你想删除的内核的关联包了,例如我想删除最老的版本2.6.28-15。

dpkg -l | grep ^ii | grep 2.6.28-15 | awk -F' ' '{ print $2 }'

On my system, (Jaunty) the resulting list is:

在我的系统上,出现这样的结果

linux-headers-2.6.28-15
linux-headers-2.6.28-15-generic
linux-image-2.6.28-15-gener
linux-restricted-modules-2.6.28-15-generic

Now that we know what packages to remove we can remove them with dpkg, apt-get or aptitude.

现在我们知道我们要上出的包了,并且用命令dpkg,apt-get或者aptitude。

sudo aptitude remove linux-headers-2.6.28-15 linux-headers-2.6.28-15-generic linux-image-2.6.28-15-generic linux-restricted-modules-2.6.28-15-generic

That's it. You've removed an old kernel and related packages. Now you can keep your system as clean as it is right after you install Ubuntu. The commands are a bit complex, so maybe I'll write up a bash script when I have some time. Proceed with caution!

就是这样的,你已经删除里老的内核还有关联的包资源了,现在你就可以保持 你的 干净的系统 ,因为它是 安装唯一的Ubuntu 命令是 有点复杂 所以如果 我有 时间 也许 我会写 了一个 bash脚本 谨慎行事

 

下边是我删除内核的shell文字

txlong@txlong-K40AB:~$ sudo -s
[sudo] password for txlong: 
root@txlong-K40AB:~# aptitude remove linux-image-2.6.35-22-generic
下列软件包将被“删除”:           
 linux-image-2.6.35-22-generic 
0 个软件包被升级,新安装 0 个, 1 个将被删除, 同时 0 个将不升级。
需要获取 0B 的存档。 解包后将释放 107MB。
(正在读取数据库 ... 系统当前共安装有 129056 个文件和目录。)
正在卸载 linux-image-2.6.35-22-generic ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 2.6.35-22-generic /boot/vmlinuz-2.6.35-22-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 2.6.35-22-generic /boot/vmlinuz-2.6.35-22-generic
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-2.6.35-28-generic
Found initrd image: /boot/initrd.img-2.6.35-28-generic
Found memtest86+ image: /boot/memtest86+.bin
Found Windows 7 (loader) on /dev/sda2
done
The link /vmlinuz.old is a damaged link
Removing symbolic link vmlinuz.old 
 you may need to re-run your boot loader[grub]
The link /initrd.img.old is a damaged link
Removing symbolic link initrd.img.old 
 you may need to re-run your boot loader[grub]

root@txlong-K40AB:~# 

 

使用Ubuntu一段时间后,就会发觉由于自动升级,系统里安装了很多内核。
像我,竟然安装了下面那么多,这个造成了漫长的启动列表。必须删掉一些不用的。

首先就是使用如下命令,列出所有安装的内核,下表中,带有image的就是内核文件。
从中选择要卸载的包,用apt-get来卸载

[tc@ibm:~]$ dpkg --get-selections|grep linux
libselinux1 install
linux-386 install
linux-image-2.6.15-23-386 install
linux-image-2.6.15-27-386 install
linux-image-2.6.15-27-686 install
linux-image-2.6.15-28-386 install
linux-image-2.6.15-28-686 deinstall
linux-image-386 install
linux-kernel-headers install
linux-restricted-modules-2.6.15-23-386 install
linux-restricted-modules-2.6.15-27-386 install
linux-restricted-modules-2.6.15-27-686 install
linux-restricted-modules-2.6.15-28-386 install
linux-restricted-modules-2.6.15-28-686 deinstall
linux-restricted-modules-386 install
linux-restricted-modules-common install
linux-sound-base install
util-linux install 

具体的卸载方法为

sudo apt-get remove linux-image-2.6.15-23-386 

 这样就可以实现自动删除内核文件了,还可以释放磁盘空间。


另外还要记录一个命令。

uname -a 

使用这个命令可以查看当前系统使用的内核。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics