Gentoo Linux uninstalls useless kernel
Remove kernel source code
After the new kernel is installed and functioning properly, the old kernel can be removed.
emerge
The " --depclean
" option (abbreviated as " -c
") can be used to remove all old or unused software versions,
For example sys-kernel/gentoo-sources
.
root # emerge --ask --depclean gentoo-sources:xx.yy.zzz
Please make sure not to remove the running kernel (see the article Kernel Upgrade for how to upgrade ).
Protect kernel source code from deletion
After installing a new kernel file, if " " is run before switching to the new kernel --depclean
, the current kernel source files will be removed.
If you need these source files, such as upgrading external kernel modules, you don't want to remove the current kernel, but want to keep them.
In order to prevent the " --depclean
" operation from deleting, you can add the specified version of the kernel to world
the file.
Remove kernel residual files
useeclean-kernel
app-admin/eclean-kernel
is a simple tool for removing/cleaning old kernels.
Remove compiled kernel files and kernel build directories if they are no longer in use by any remaining kernels.
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)
For example, keep the latest three cores:
Manual removal
Portage
Remove only installed files - files generated during kernel compilation and installation.
Can be safely deleted.
- When the kernel is compiled in the source file directory, the files generated during the compilation process will be retained and will not be
Portage
deleted.
root # rm -r /usr/src/linux-3.X.Y
- During the kernel configuration process, kernel modules are copied to
/lib/modules/
subdirectories:
root #rm -r /lib/modules/3.X.Y
/boot
Old files in can also be deleted:
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
- Finally, delete the old entry in the bootstrap configuration file.