I'm currently cleaning up several servers.
I noticed some strange behaviour:

When I do apt-get autoremove it lists several headers to be autoremoved when I go ahead, sometimes it leaves the files/folders in /usr/src, sometimes they will be removed.

Any reason as to why, or where I can start searching? Google didn't turn up much.

A machine where the headers still remain, even though autoremove gives a "0 to remove"

ubuntu@acc-ws-website-1:~$ sudo apt-get autoremove
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 65 not upgraded.

ubuntu@acc-ws-website-1:~$ ls -lart /usr/src
total 108
drwxr-xr-x 10 root   root   4096 Apr 16  2014 ..
drwxr-xr-x 24 root   root   4096 Jul  8  2014 linux-headers-3.13.0-24
drwxr-xr-x  7 root   root   4096 Jul  8  2014 linux-headers-3.13.0-24-generic
drwxr-xr-x  3 ubuntu ubuntu 4096 Apr 17  2015 ixgbevf-2.14.2
drwxr-xr-x 24 root   root   4096 Oct  6  2015 linux-headers-3.13.0-65
drwxr-xr-x  7 root   root   4096 Oct  6  2015 linux-headers-3.13.0-65-generic
drwxr-xr-x 24 root   root   4096 Oct 20  2015 linux-headers-3.13.0-66
drwxr-xr-x  7 root   root   4096 Oct 20  2015 linux-headers-3.13.0-66-generic
drwxr-xr-x 24 root   root   4096 Nov  5  2015 linux-headers-3.13.0-67
drwxr-xr-x  7 root   root   4096 Nov  5  2015 linux-headers-3.13.0-67-generic
drwxr-xr-x 24 root   root   4096 Nov 10  2015 linux-headers-3.13.0-68
drwxr-xr-x  7 root   root   4096 Nov 10  2015 linux-headers-3.13.0-68-generic
drwxr-xr-x 24 root   root   4096 Dec  1  2015 linux-headers-3.13.0-70
drwxr-xr-x  7 root   root   4096 Dec  1  2015 linux-headers-3.13.0-70-generic
drwxr-xr-x 24 root   root   4096 Dec  2  2015 linux-headers-3.13.0-71
drwxr-xr-x  7 root   root   4096 Dec  2  2015 linux-headers-3.13.0-71-generic
drwxr-xr-x 24 root   root   4096 Dec 17  2015 linux-headers-3.13.0-73
drwxr-xr-x  7 root   root   4096 Dec 17  2015 linux-headers-3.13.0-73-generic
drwxr-xr-x 24 root   root   4096 Dec 19  2015 linux-headers-3.13.0-74
drwxr-xr-x  7 root   root   4096 Dec 19  2015 linux-headers-3.13.0-74-generic
drwxr-xr-x 24 root   root   4096 Feb  2  2016 linux-headers-3.13.0-77
drwxr-xr-x  7 root   root   4096 Feb  2  2016 linux-headers-3.13.0-77-generic
drwxr-xr-x 24 root   root   4096 Feb 23  2016 linux-headers-3.13.0-79
drwxr-xr-x  7 root   root   4096 Feb 23  2016 linux-headers-3.13.0-79-generic
drwxr-xr-x 24 root   root   4096 Mar 30 06:50 linux-headers-3.13.0-115
drwxr-xr-x  7 root   root   4096 Mar 30 06:50 linux-headers-3.13.0-115-generic
drwxr-xr-x 27 root   root   4096 Mar 30 06:52 .

ubuntu@acc-ws-website-1:~$ uname -r
3.13.0-112-generic

Whereas I would expect something like this:

ubuntu@tools-jenkins:~$ sudo apt-get autoremove
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 94 not upgraded.

ubuntu@tools-jenkins:~$ ls -lart /usr/src
total 32
drwxr-xr-x 10 root root 4096 Mar 25  2015 ..
drwxr-xr-x 24 root root 4096 Dec  6 06:39 linux-headers-3.13.0-105
drwxr-xr-x  7 root root 4096 Dec  6 06:39 linux-headers-3.13.0-105-generic
drwxr-xr-x 24 root root 4096 Mar  8 06:44 linux-headers-3.13.0-112
drwxr-xr-x  7 root root 4096 Mar  8 06:44 linux-headers-3.13.0-112-generic
drwxr-xr-x 24 root root 4096 Mar 30 06:26 linux-headers-3.13.0-115
drwxr-xr-x  7 root root 4096 Mar 30 06:26 linux-headers-3.13.0-115-generic
drwxr-xr-x  8 root root 4096 Apr  3 10:50 .

ubuntu@tools-jenkins:~$ uname -r
3.13.0-105-generic
Answer
      • 1
    • Please share list of installed kernel header packages (dpkg-query -f '${binary:Package} ' -W linux-headers*) and tell if the /usr/src/linux-headers-* still contain full kernel headers tree.
      • 2
    • Sharing the output of the command might help. In itself, this is a very broad problem description with little details and it's very unlikely somebody can come up with a solution based on just this information.
      • 1
    • Were the "files not deleted" announced as "can be (auto)remove" by the APT process ? Either way, if they are not auto-removed, that's because there are some dependencies to them so they were never marked as "can be removed"

If you still have lots of linux-headers* packages installed on your system, you may try this simple approach to remove old headers:

dpkg-query -f '${binary:Package}\n' -W linux-headers\*|xargs apt-mark auto
apt-mark manual linux-headers-generic
apt-get -f autoremove

If my assumption is right, somehow you got your headers marked as manually installed and this prevents your system from removing these packages. For example, you had directly installed the packages i.e. asked apt to install exact version of the kernel headers package. The commands above try to mark all these packages as installed automatically and make things work as expected.

If by any chance the packages are already removed but folders still persist and have only some leftovers inside then this means that these files do not belong to the package. This prevents apt from removing top directory when deinstalling linux-headers* package. You should remove the files manually in this case.

Trivia: apt's autoremove feature works only for packages that got installed automatically. This means the package has to be literally marked as 'installed automatically' and there should be no packages that depend on it. In case for linux kernel and its headers we have this common scenario:

  • there is one or several meta-packages like linux-generic, linux-image-generic and linux-headers-generic that are usually marked as manually installed
  • there are lots of the 'real' packages with files inside like linux-image-4.8.0-45-generic and meta-packages depend on some of such packages; these are usually marked as 'installed automatically'
  • when the meta-package gets updated it usually requires newer versions of the 'real' package and thus new versions are being installed
  • the packages marked as 'installed automatically' can be autoremoved only when there is no manually installed package that depend on it, so when new packages got installed the old ones may be removed automatically later because no one depends on these packages any more
  • 4
Reply Report

Well you see that 94 not upgraded ? Thats the problem, i had similar problem and than I manually upgraded all items(that were not upgraded by apt-get upgrade, these files holds that dependencies) . And after that i used apt-get autoremove and it worked. When you upgrading with apt-get upgrade ,at the end of verbose text you can see list of not upgraded files. take them one by one (don't worry some upgrades will upgrade half of that list). Hope this helps, cheers mate.

P.S. Before upgrading make sure that u backUp image of working system if something goes wrong.

  • 0
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions