内核/移除

From Gentoo Wiki
< Kernel
Jump to:navigation Jump to:search
This page is a translated version of the page Kernel/Removal and the translation is 41% complete.
Outdated translations are marked like this.

这篇文章描述如何移除旧的kernel

移除内核源代码

在安装新的内核并正常工作之后,旧的内核就可以移除了。emerge的 "--depclean" 选项(缩写为 "-c" )可以用来移除所有旧的或者不用的软件版本,例如sys-kernel/gentoo-sources

root #emerge --ask --depclean gentoo-sources:xx.yy.zzz

请确保不要移除正在运行的内核(关于如何升级请参考文章内核升级)。

保护内核源代码不被删除

在安装了新的内核文件之后,如果切换到新的内核之前你运行了 "--depclean",那么当前的内核源文件就会被移除。要是你需要这些源文件,比如升级外部的内核模块,所以并不想移除当前的内核,而是想保留它。为了不让 "--depclean" 操作删除它,你最好可以把指定版本的内核加入到你的 world 文件中。

An example of a way to do this:

root #emerge --depclean --exclude=sys-kernel/gentoo-sources

This will leave all of your kernel source build directories alone during cleanup, which you can then clean up with tools like eclean-kernel, referenced below.

移除内核残留文件

使用 eclean-kernel

app-admin/eclean-kernel是一个简单的工具,用来移除/清理旧的内核。它移除编译的内核文件和内核编译目录,如果这些目录文件都被再被任何保留的内核使用的话。

See eclean-kernel --help post-installation for usage instructions:

user $eclean-kernel --help
usage: eclean-kernel [-h] [-V] [-A] [-l] [-p] [-b BOOTLOADER] [-L LAYOUT] [-r ROOT] [-a] [-d] [-n NUM] [-s SORT_ORDER]
                      [-D] [-M] [--no-bootloader-update] [--no-kernel-install] [-x EXCLUDE]
 
 Remove old kernel versions, keeping either N newest kernels (with -n) or only those which are referenced by a bootloader
 (with -a).
 
 optional arguments:
   -h, --help            show this help message and exit
   -V, --version         show program's version number and exit
 
 action control:
   -A, --ask             Ask before removing each kernel
   -l, --list-kernels    List kernel files and exit
   -p, --pretend         Print the list of kernels to be removed and exit
 
 system configuration:
   -b BOOTLOADER, --bootloader BOOTLOADER
                         Bootloader used (auto, lilo, grub2, grub, yaboot, symlinks)
   -L LAYOUT, --layout LAYOUT
                         Layout used (auto, blspec, std)
   -r ROOT, --root ROOT  Alternate filesystem root to use
 
 kernel selection:
   -a, --all             Remove all kernels unless used by bootloader
   -d, --destructive     Destructive mode: remove kernels even when referenced by bootloader
   -n NUM, --num NUM     Leave only newest NUM kernels (see also: --sort-order)
   -s SORT_ORDER, --sort-order SORT_ORDER
                         Kernel sort order (mtime, version); default: version
 
 misc options:
   -D, --debug           Enable debugging output
   -M, --no-mount        Disable (re-)mounting /boot if necessary
   --no-bootloader-update
                         Do not update bootloader configuration after removing kernels (if supported by the bootloader
   --no-kernel-install   Do not call kernel-install while removing kernels (if installed)
   -x EXCLUDE, --exclude EXCLUDE
                         Exclude kernel parts from being removed (comma-separated, supported parts: vmlinuz, systemmap,
                         config, initramfs, modules, build, misc, emptydir)

例如,保留最新的三个内核:

root #eclean-kernel -n 3

手动移除

Portage只移除它安装的文件——在内核编译和安装时候产生的文件。他们可以被安全的删除。

  • 当内核在源文件目录编译的时候,在编译过程中生成的文件会保留,不会被Portage删除。
root #rm -r /usr/src/linux-3.X.Y
  • 在内核配置过程中,内核模块会被拷贝到 /lib/modules/ 子目录中:
root #rm -r /lib/modules/3.X.Y
  • /boot中的旧文件也可以删除:
root #rm /boot/vmlinuz-3.X.Y
root #rm /boot/System.map-3.X.Y
root #rm /boot/config-3.X.Y
root #rm /boot/initramfs-X.Y.Z
  • 最后,删除在你的引导程序的配置文件中的旧的条目。