Unbenutzte Linux Kernel Headers, Images und Modules entfernen

Aus Laub-Home Wiki

Mit der Zeit landen doch so einige Dateien durch die Kernel Header, Images und Modules auf einem System - um die mittlerweile nicht mehr verwendeten Files zu entfernen kann wie folgt vorgegangen werden:
Anmerkung: sofern rückwirkend Kernel Updates eingespielt wurden, muss auf jeden Fall das System neu gestartet werden!

Getestet auf einem Ubuntu 12.04.4 LTS


1. Übersicht der installierten Kernel Files

dpkg -l 'linux-*'
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                   Version                                Description
+++-======================================-======================================-============================================================================================
ii  linux-firmware                         1.79.11                                Firmware for Linux kernel drivers
ii  linux-generic-lts-raring               3.8.0.38.38                            Generic Linux kernel image and headers
un  linux-headers                          <none>                                 (no description available)
un  linux-headers-3.0                      <none>                                 (no description available)
ii  linux-headers-3.8.0-29                 3.8.0-29.42~precise1                   Header files related to Linux kernel version 3.8.0
ii  linux-headers-3.8.0-29-generic         3.8.0-29.42~precise1                   Linux kernel headers for version 3.8.0 on 64 bit x86 SMP
ii  linux-headers-3.8.0-32                 3.8.0-32.47~precise1                   Header files related to Linux kernel version 3.8.0
ii  linux-headers-3.8.0-32-generic         3.8.0-32.47~precise1                   Linux kernel headers for version 3.8.0 on 64 bit x86 SMP
ii  linux-headers-3.8.0-33                 3.8.0-33.48~precise1                   Header files related to Linux kernel version 3.8.0
ii  linux-headers-3.8.0-33-generic         3.8.0-33.48~precise1                   Linux kernel headers for version 3.8.0 on 64 bit x86 SMP
ii  linux-headers-3.8.0-34                 3.8.0-34.49~precise1                   Header files related to Linux kernel version 3.8.0
ii  linux-headers-3.8.0-34-generic         3.8.0-34.49~precise1                   Linux kernel headers for version 3.8.0 on 64 bit x86 SMP
ii  linux-headers-3.8.0-35                 3.8.0-35.52~precise1                   Header files related to Linux kernel version 3.8.0
ii  linux-headers-3.8.0-35-generic         3.8.0-35.52~precise1                   Linux kernel headers for version 3.8.0 on 64 bit x86 SMP
ii  linux-headers-3.8.0-36                 3.8.0-36.52~precise1                   Header files related to Linux kernel version 3.8.0
ii  linux-headers-3.8.0-36-generic         3.8.0-36.52~precise1                   Linux kernel headers for version 3.8.0 on 64 bit x86 SMP
ii  linux-headers-3.8.0-37                 3.8.0-37.53~precise1                   Header files related to Linux kernel version 3.8.0
ii  linux-headers-3.8.0-37-generic         3.8.0-37.53~precise1                   Linux kernel headers for version 3.8.0 on 64 bit x86 SMP
ii  linux-headers-3.8.0-38                 3.8.0-38.56~precise1                   Header files related to Linux kernel version 3.8.0
ii  linux-headers-3.8.0-38-generic         3.8.0-38.56~precise1                   Linux kernel headers for version 3.8.0 on 64 bit x86 SMP
ii  linux-headers-generic-lts-raring       3.8.0.38.38                            Generic Linux kernel headers
un  linux-image                            <none>                                 (no description available)
un  linux-image-3.0                        <none>                                 (no description available)
ii  linux-image-3.8.0-29-generic           3.8.0-29.42~precise1                   Linux kernel image for version 3.8.0 on 64 bit x86 SMP
ii  linux-image-3.8.0-32-generic           3.8.0-32.47~precise1                   Linux kernel image for version 3.8.0 on 64 bit x86 SMP
ii  linux-image-3.8.0-33-generic           3.8.0-33.48~precise1                   Linux kernel image for version 3.8.0 on 64 bit x86 SMP
ii  linux-image-3.8.0-34-generic           3.8.0-34.49~precise1                   Linux kernel image for version 3.8.0 on 64 bit x86 SMP
ii  linux-image-3.8.0-35-generic           3.8.0-35.52~precise1                   Linux kernel image for version 3.8.0 on 64 bit x86 SMP
ii  linux-image-3.8.0-36-generic           3.8.0-36.52~precise1                   Linux kernel image for version 3.8.0 on 64 bit x86 SMP
ii  linux-image-3.8.0-37-generic           3.8.0-37.53~precise1                   Linux kernel image for version 3.8.0 on 64 bit x86 SMP
ii  linux-image-3.8.0-38-generic           3.8.0-38.56~precise1                   Linux kernel image for version 3.8.0 on 64 bit x86 SMP
ii  linux-image-generic-lts-raring         3.8.0.38.38                            Generic Linux kernel image
un  linux-initramfs-tool                   <none>                                 (no description available)
un  linux-kernel-headers                   <none>                                 (no description available)
un  linux-kernel-log-daemon                <none>                                 (no description available)
ii  linux-libc-dev                         3.2.0-60.91                            Linux Kernel Headers for development
un  linux-lts-raring-doc-3.8.0             <none>                                 (no description available)
un  linux-lts-raring-source-3.8.0          <none>                                 (no description available)
un  linux-lts-raring-tools                 <none>                                 (no description available)
un  linux-restricted-common                <none>                                 (no description available)


2. Übersicht der unbenutzen Kernel Files

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'
linux-headers-3.8.0-29
linux-headers-3.8.0-29-generic
linux-headers-3.8.0-32
linux-headers-3.8.0-32-generic
linux-headers-3.8.0-33
linux-headers-3.8.0-33-generic
linux-headers-3.8.0-34
linux-headers-3.8.0-34-generic
linux-headers-3.8.0-35
linux-headers-3.8.0-35-generic
linux-headers-3.8.0-36
linux-headers-3.8.0-36-generic
linux-headers-3.8.0-37
linux-headers-3.8.0-37-generic
linux-image-3.8.0-29-generic
linux-image-3.8.0-32-generic
linux-image-3.8.0-33-generic
linux-image-3.8.0-34-generic
linux-image-3.8.0-35-generic
linux-image-3.8.0-36-generic
linux-image-3.8.0-37-generic


3. Sofern keine Ausgabefehler kommen bzw. der aktuelle Kernel NICHT in der Liste der unbenutzen Kernel Files auftaucht diese entfernen

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
  linux-headers-3.8.0-29* linux-headers-3.8.0-29-generic* linux-headers-3.8.0-32* linux-headers-3.8.0-32-generic* linux-headers-3.8.0-33* linux-headers-3.8.0-33-generic*
  linux-headers-3.8.0-34* linux-headers-3.8.0-34-generic* linux-headers-3.8.0-35* linux-headers-3.8.0-35-generic* linux-headers-3.8.0-36* linux-headers-3.8.0-36-generic*
  linux-headers-3.8.0-37* linux-headers-3.8.0-37-generic* linux-image-3.8.0-29-generic* linux-image-3.8.0-32-generic* linux-image-3.8.0-33-generic*
  linux-image-3.8.0-34-generic* linux-image-3.8.0-35-generic* linux-image-3.8.0-36-generic* linux-image-3.8.0-37-generic*
0 upgraded, 0 newly installed, 21 to remove and 0 not upgraded.
After this operation, 1,740 MB disk space will be freed.

[..]
# dann gehts los


Quelle