Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Because you automatically upgrade your kernels, your VMs get clogged up with old kernels and headers. Example:

 

Code Block
visser@test-omegavisser@cajones:~$ ls -la /lib/modules
total 32
drwxr-xr-x  8 root root 4096 Mar 15 06:47 .
drwxr-xr-x 21 root root 4096 Sep  3  2014 ..
drwxr-xr-x  5 root root 4096 Jan 16 02:50 3.13.0-71-generic
drwxr-xr-x  5 root root 4096 Jan 16 02:51 3.13.0-74-generic
drwxr-xr-x  5 root root 4096 Jan 20 06:53 3.13.0-76-generic
drwxr-xr-x  5 root root 4096 Feb  2 06:37 3.13.0-77-generic
drwxr-xr-x  5 root root 4096 Feb 23 06:35 3.13.0-79-generic
drwxr-xr-x  5 root root 4096 Mar 15 06:48 3.13.0-83-generic

...

To list all installed kernels and accompanying headers:

Code Block
root@test-omegaroot@cajones:~# apt-show-versions -b | grep -E 'linux-(headers|image(-extra)?)-[0-9]+'
linux-headers-3.13.0-71:all/trusty-security
linux-headers-3.13.0-71-generic:amd64/trusty-security
linux-headers-3.13.0-74:all/trusty-security
linux-headers-3.13.0-74-generic:amd64/trusty-security
linux-headers-3.13.0-76:all/trusty-security
linux-headers-3.13.0-76-generic:amd64/trusty-security
linux-headers-3.13.0-77:all/trusty-security
linux-headers-3.13.0-77-generic:amd64/trusty-security
linux-headers-3.13.0-79:all/trusty-security
linux-headers-3.13.0-79-generic:amd64/trusty-security
linux-headers-3.13.0-83:all/trusty-security
linux-headers-3.13.0-83-generic:amd64/trusty-security
linux-image-3.13.0-71-generic:amd64/trusty-security
linux-image-3.13.0-74-generic:amd64/trusty-security
linux-image-3.13.0-76-generic:amd64/trusty-security
linux-image-3.13.0-77-generic:amd64/trusty-security
linux-image-3.13.0-79-generic:amd64/trusty-security
linux-image-3.13.0-83-generic:amd64/trusty-security
linux-image-extra-3.13.0-71-generic:amd64/trusty-security
linux-image-extra-3.13.0-74-generic:amd64/trusty-security
linux-image-extra-3.13.0-76-generic:amd64/trusty-security
linux-image-extra-3.13.0-77-generic:amd64/trusty-security
linux-image-extra-3.13.0-79-generic:amd64/trusty-security
linux-image-extra-3.13.0-83-generic:amd64/trusty-security

You can't just purge all of these because you will trash your current kernel. So you need to exclude that, preferably using the uname command:

Code Block
visser@test-omegavisser@cajones:~$ uname -r
3.13.0-83-generic

So this will yield:

Code Block
visser@test-omegavisser@cajones:~$ apt-show-versions -b | grep -E 'linux-(headers|image(-extra)?)-[0-9]+' | grep -v `uname -r`
linux-headers-3.13.0-71:all/trusty-security
linux-headers-3.13.0-71-generic:amd64/trusty-security
linux-headers-3.13.0-74:all/trusty-security
linux-headers-3.13.0-74-generic:amd64/trusty-security
linux-headers-3.13.0-76:all/trusty-security
linux-headers-3.13.0-76-generic:amd64/trusty-security
linux-headers-3.13.0-77:all/trusty-security
linux-headers-3.13.0-77-generic:amd64/trusty-security
linux-headers-3.13.0-79:all/trusty-security
linux-headers-3.13.0-79-generic:amd64/trusty-security
linux-headers-3.13.0-83:all/trusty-security
linux-image-3.13.0-71-generic:amd64/trusty-security
linux-image-3.13.0-74-generic:amd64/trusty-security
linux-image-3.13.0-76-generic:amd64/trusty-security
linux-image-3.13.0-77-generic:amd64/trusty-security
linux-image-3.13.0-79-generic:amd64/trusty-security
linux-image-extra-3.13.0-71-generic:amd64/trusty-security
linux-image-extra-3.13.0-74-generic:amd64/trusty-security
linux-image-extra-3.13.0-76-generic:amd64/trusty-security
linux-image-extra-3.13.0-77-generic:amd64/trusty-security
linux-image-extra-3.13.0-79-generic:amd64/trusty-security

...

However this will also remove the headers of the current kernel, so we have to strip the -generic part from the uname output:

Code Block
visser@test-omegavisser@cajones:~$ apt-show-versions -b | grep -E 'linux-(headers|image(-extra)?)-[0-9]+' | grep -v $(uname -r | sed -E 's/-[a-z]+$//')
linux-headers-3.13.0-71:all/trusty-security
linux-headers-3.13.0-71-generic:amd64/trusty-security
linux-headers-3.13.0-74:all/trusty-security
linux-headers-3.13.0-74-generic:amd64/trusty-security
linux-headers-3.13.0-76:all/trusty-security
linux-headers-3.13.0-76-generic:amd64/trusty-security
linux-headers-3.13.0-77:all/trusty-security
linux-headers-3.13.0-77-generic:amd64/trusty-security
linux-headers-3.13.0-79:all/trusty-security
linux-headers-3.13.0-79-generic:amd64/trusty-security
linux-image-3.13.0-71-generic:amd64/trusty-security
linux-image-3.13.0-74-generic:amd64/trusty-security
linux-image-3.13.0-76-generic:amd64/trusty-security
linux-image-3.13.0-77-generic:amd64/trusty-security
linux-image-3.13.0-79-generic:amd64/trusty-security
linux-image-extra-3.13.0-71-generic:amd64/trusty-security
linux-image-extra-3.13.0-74-generic:amd64/trusty-security
linux-image-extra-3.13.0-76-generic:amd64/trusty-security
linux-image-extra-3.13.0-77-generic:amd64/trusty-security
linux-image-extra-3.13.0-79-generic:amd64/trusty-security

...

This looks good. Now we can purge these packages:

 

Code Block
visser@test-omegavisser@cajones:~$ sudo apt-get purge `apt-show-versions -b | grep -E 'linux-(headers|image(-extra)?)-[0-9]+' | grep -v $(uname -r | sed -E 's/-[a-z]+$//')`
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Selected version '3.13.0-71.114' (Ubuntu:14.04/trusty-updates [all]) for 'linux-headers-3.13.0-71'
Selected version '3.13.0-71.114' (Ubuntu:14.04/trusty-updates [amd64]) for 'linux-headers-3.13.0-71-generic'
Selected version '3.13.0-74.118' (Ubuntu:14.04/trusty-updates [all]) for 'linux-headers-3.13.0-74'
Selected version '3.13.0-74.118' (Ubuntu:14.04/trusty-updates [amd64]) for 'linux-headers-3.13.0-74-generic'
Selected version '3.13.0-76.120' (Ubuntu:14.04/trusty-updates [all]) for 'linux-headers-3.13.0-76'
Selected version '3.13.0-76.120' (Ubuntu:14.04/trusty-updates [amd64]) for 'linux-headers-3.13.0-76-generic'
Selected version '3.13.0-77.121' (Ubuntu:14.04/trusty-updates [all]) for 'linux-headers-3.13.0-77'
Selected version '3.13.0-77.121' (Ubuntu:14.04/trusty-updates [amd64]) for 'linux-headers-3.13.0-77-generic'
Selected version '3.13.0-79.123' (Ubuntu:14.04/trusty-updates [all]) for 'linux-headers-3.13.0-79'
Selected version '3.13.0-79.123' (Ubuntu:14.04/trusty-updates [amd64]) for 'linux-headers-3.13.0-79-generic'
Selected version '3.13.0-71.114' (Ubuntu:14.04/trusty-updates [amd64]) for 'linux-image-3.13.0-71-generic'
Selected version '3.13.0-74.118' (Ubuntu:14.04/trusty-updates [amd64]) for 'linux-image-3.13.0-74-generic'
Selected version '3.13.0-76.120' (Ubuntu:14.04/trusty-updates [amd64]) for 'linux-image-3.13.0-76-generic'
Selected version '3.13.0-77.121' (Ubuntu:14.04/trusty-updates [amd64]) for 'linux-image-3.13.0-77-generic'
Selected version '3.13.0-79.123' (Ubuntu:14.04/trusty-updates [amd64]) for 'linux-image-3.13.0-79-generic'
Selected version '3.13.0-71.114' (Ubuntu:14.04/trusty-updates [amd64]) for 'linux-image-extra-3.13.0-71-generic'
Selected version '3.13.0-74.118' (Ubuntu:14.04/trusty-updates [amd64]) for 'linux-image-extra-3.13.0-74-generic'
Selected version '3.13.0-76.120' (Ubuntu:14.04/trusty-updates [amd64]) for 'linux-image-extra-3.13.0-76-generic'
Selected version '3.13.0-77.121' (Ubuntu:14.04/trusty-updates [amd64]) for 'linux-image-extra-3.13.0-77-generic'
Selected version '3.13.0-79.123' (Ubuntu:14.04/trusty-updates [amd64]) for 'linux-image-extra-3.13.0-79-generic'
The following packages will be REMOVED:
  linux-headers-3.13.0-71* linux-headers-3.13.0-71-generic*
  linux-headers-3.13.0-74* linux-headers-3.13.0-74-generic*
  linux-headers-3.13.0-76* linux-headers-3.13.0-76-generic*
  linux-headers-3.13.0-77* linux-headers-3.13.0-77-generic*
  linux-headers-3.13.0-79* linux-headers-3.13.0-79-generic*
  linux-image-3.13.0-71-generic* linux-image-3.13.0-74-generic*
  linux-image-3.13.0-76-generic* linux-image-3.13.0-77-generic*
  linux-image-3.13.0-79-generic* linux-image-extra-3.13.0-71-generic*
  linux-image-extra-3.13.0-74-generic* linux-image-extra-3.13.0-76-generic*
  linux-image-extra-3.13.0-77-generic* linux-image-extra-3.13.0-79-generic*
0 upgraded, 0 newly installed, 20 to remove and 35 not upgraded.
After this operation, 1,357 MB disk space will be freed.
Do you want to continue? [Y/n] 

...