rackerlabs / kthresher

Tool to remove unused kernels in Debian/Ubuntu
Apache License 2.0
17 stars 12 forks source link

The include headers option doesn't work correctly #45

Closed jamrok closed 7 years ago

jamrok commented 7 years ago

The -H option doesn't remove headers when the corresponding kernel images have already been removed.

# kthresher -k2 -pvH
INFO: Attempting to read /etc/kthresher.conf.
INFO: Options found: ['include'].
INFO: Valid setting found "include"
INFO:   include = /etc/kthresher.d/*.conf
INFO: Options: {'purge': True, 'headers': True, 'verbose': True, 'dry_run': False, 'include': '/etc/kthresher.d/*.conf', 'keep': 2}
INFO: Running kernel is linux-image-4.4.0-96-generic v[4.4.0-96.119]
INFO: Attempting to keep 2 kernel package(s)
INFO: Found 2 kernel image(s) installed and available for autoremoval
INFO: Pre-sorting: ['4.4.0-89.112', '4.4.0-91.114']
INFO: Post-sorting: ['4.4.0-89.112', '4.4.0-91.114']
ERROR: Nothing to do, attempting to keep 2 out of 2 kernel images.

The following are the available packages that were detected for autoremoval:

# kthresher -s
List of kernel packages available for autoremoval:
       Version Package       
   4.4.0-53.74 linux-headers-4.4.0-53-generic
   4.4.0-65.86 linux-headers-4.4.0-65-generic
   4.4.0-66.87 linux-headers-4.4.0-66-generic
   4.4.0-70.91 linux-headers-4.4.0-70-generic
   4.4.0-71.92 linux-headers-4.4.0-71-generic
   4.4.0-72.93 linux-headers-4.4.0-72-generic
   4.4.0-78.99 linux-headers-4.4.0-78-generic
  4.4.0-79.100 linux-headers-4.4.0-79-generic
  4.4.0-81.104 linux-headers-4.4.0-81-generic
  4.4.0-83.106 linux-headers-4.4.0-83-generic
  4.4.0-87.110 linux-headers-4.4.0-87-generic
  4.4.0-89.112 linux-headers-4.4.0-89-generic
  4.4.0-91.114 linux-headers-4.4.0-91-generic
  4.4.0-89.112 linux-image-4.4.0-89-generic
  4.4.0-91.114 linux-image-4.4.0-91-generic

This has been corrected in PR #44.

The new expected behaviour is shown below:

# kthresher -d -k2 -pvH
INFO: Attempting to read /etc/kthresher.conf.
INFO: Options found: ['include'].
INFO: Valid setting found "include"
INFO:   include = /etc/kthresher.d/*.conf
INFO: Options: {'purge': True, 'headers': True, 'verbose': True, 'dry_run': True, 'include': '/etc/kthresher.d/*.conf', 'keep': 2}
INFO: ----- DRY RUN -----
INFO: Running kernel is linux-image-4.4.0-96-generic v[4.4.0-96.119]
INFO: Attempting to keep 2 kernel package(s)
INFO: Found 13 kernel image(s) installed and available for autoremoval
INFO: Pre-sorting: ['4.4.0-65.86', '4.4.0-87.110', '4.4.0-70.91', '4.4.0-81.104', '4.4.0-89.112', '4.4.0-71.92', '4.4.0-91.114', '4.4.0-72.93', '4.4.0-66.87', '4.4.0-83.106', '4.4.0-78.99', '4.4.0-53.74', '4.4.0-79.100']
INFO: Post-sorting: ['4.4.0-53.74', '4.4.0-65.86', '4.4.0-66.87', '4.4.0-70.91', '4.4.0-71.92', '4.4.0-72.93', '4.4.0-78.99', '4.4.0-79.100', '4.4.0-81.104', '4.4.0-83.106', '4.4.0-87.110', '4.4.0-89.112', '4.4.0-91.114']
INFO:   Purging packages from version: 4.4.0-53.74
INFO:       Purging: linux-headers-4.4.0-53-generic
INFO:   Purging packages from version: 4.4.0-65.86
INFO:       Purging: linux-headers-4.4.0-65-generic
INFO:   Purging packages from version: 4.4.0-66.87
INFO:       Purging: linux-headers-4.4.0-66-generic
INFO:   Purging packages from version: 4.4.0-70.91
INFO:       Purging: linux-headers-4.4.0-70-generic
INFO:   Purging packages from version: 4.4.0-71.92
INFO:       Purging: linux-headers-4.4.0-71-generic
INFO:   Purging packages from version: 4.4.0-72.93
INFO:       Purging: linux-headers-4.4.0-72-generic
INFO:   Purging packages from version: 4.4.0-78.99
INFO:       Purging: linux-headers-4.4.0-78-generic
INFO:   Purging packages from version: 4.4.0-79.100
INFO:       Purging: linux-headers-4.4.0-79-generic
INFO:   Purging packages from version: 4.4.0-81.104
INFO:       Purging: linux-headers-4.4.0-81-generic
INFO:   Purging packages from version: 4.4.0-83.106
INFO:       Purging: linux-headers-4.4.0-83-generic
INFO:   Purging packages from version: 4.4.0-87.110
INFO:       Purging: linux-headers-4.4.0-87-generic

The following confirms that the existing behaviour also works as expected:

# kthresher -d -k0 -pvH
INFO: Attempting to read /etc/kthresher.conf.
INFO: Options found: ['include'].
INFO: Valid setting found "include"
INFO:   include = /etc/kthresher.d/*.conf
INFO: Options: {'purge': True, 'headers': True, 'verbose': True, 'dry_run': True, 'include': '/etc/kthresher.d/*.conf', 'keep': 0}
INFO: ----- DRY RUN -----
INFO: Running kernel is linux-image-4.4.0-96-generic v[4.4.0-96.119]
INFO: Attempting to keep 0 kernel package(s)
INFO: Found 13 kernel image(s) installed and available for autoremoval
INFO: Pre-sorting: ['4.4.0-65.86', '4.4.0-87.110', '4.4.0-70.91', '4.4.0-81.104', '4.4.0-89.112', '4.4.0-71.92', '4.4.0-91.114', '4.4.0-72.93', '4.4.0-66.87', '4.4.0-83.106', '4.4.0-78.99', '4.4.0-53.74', '4.4.0-79.100']
INFO: Post-sorting: ['4.4.0-53.74', '4.4.0-65.86', '4.4.0-66.87', '4.4.0-70.91', '4.4.0-71.92', '4.4.0-72.93', '4.4.0-78.99', '4.4.0-79.100', '4.4.0-81.104', '4.4.0-83.106', '4.4.0-87.110', '4.4.0-89.112', '4.4.0-91.114']
INFO:   Purging packages from version: 4.4.0-53.74
INFO:       Purging: linux-headers-4.4.0-53-generic
INFO:   Purging packages from version: 4.4.0-65.86
INFO:       Purging: linux-headers-4.4.0-65-generic
INFO:   Purging packages from version: 4.4.0-66.87
INFO:       Purging: linux-headers-4.4.0-66-generic
INFO:   Purging packages from version: 4.4.0-70.91
INFO:       Purging: linux-headers-4.4.0-70-generic
INFO:   Purging packages from version: 4.4.0-71.92
INFO:       Purging: linux-headers-4.4.0-71-generic
INFO:   Purging packages from version: 4.4.0-72.93
INFO:       Purging: linux-headers-4.4.0-72-generic
INFO:   Purging packages from version: 4.4.0-78.99
INFO:       Purging: linux-headers-4.4.0-78-generic
INFO:   Purging packages from version: 4.4.0-79.100
INFO:       Purging: linux-headers-4.4.0-79-generic
INFO:   Purging packages from version: 4.4.0-81.104
INFO:       Purging: linux-headers-4.4.0-81-generic
INFO:   Purging packages from version: 4.4.0-83.106
INFO:       Purging: linux-headers-4.4.0-83-generic
INFO:   Purging packages from version: 4.4.0-87.110
INFO:       Purging: linux-headers-4.4.0-87-generic
INFO:   Purging packages from version: 4.4.0-89.112
INFO:       Purging: linux-image-4.4.0-89-generic
INFO:       Purging: linux-headers-4.4.0-89-generic
INFO:   Purging packages from version: 4.4.0-91.114
INFO:       Purging: linux-image-4.4.0-91-generic
INFO:       Purging: linux-headers-4.4.0-91-generic
tonyskapunk commented 7 years ago

Hi @jamrok thaks for opening this issue and contributing with the fix.

While kthresher is not doing what you expect it is doing the corresponding kernel <--> header by design, i.e. it will not remove a header of a kernel that is not candidate for removal nor remove a header of a kernel that is not installed.

Anyway, that design is probably not the most accurate, and I've been thinking about this for a while and your proposal makes sense to me as is unlikely that someone will make use of headers without a kernel image and mostly being a candidate for auto-removal.

tonyskapunk commented 7 years ago

Ok, this was fixed when merged #44 closing this one.