rackerlabs / kthresher

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

kthresher assumes there is always a kernel installed #39

Open tonyskapunk opened 7 years ago

tonyskapunk commented 7 years ago

Running inside a container will throw this error:

# kthresher --dry-run --verbose
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': False, 'headers': False, 'verbose': True, 'dry_run': True, 'include': '/etc/kthresher.d/*.conf', 'keep': 1}
INFO: ----- DRY RUN -----
Traceback (most recent call last):
  File "/usr/bin/kthresher", line 9, in <module>
    load_entry_point('kthresher==1.2.6', 'console_scripts', 'kthresher')()
  File "/usr/lib/python2.7/dist-packages/kthresher.py", line 337, in main
    keep=options['keep']
  File "/usr/lib/python2.7/dist-packages/kthresher.py", line 194, in kthreshing
    kernel_pkg = apt_cache["linux-image-%s" % current_kernel_ver]
  File "/usr/lib/python2.7/dist-packages/apt/cache.py", line 200, in __getitem__
    raise KeyError('The cache has no package named %r' % key)
KeyError: "The cache has no package named 'linux-image-3.10.0-514.10.2.el7.x86_64'"

# uname -r
3.10.0-514.10.2.el7.x86_64

# dpkg -l linux-image
dpkg-query: no packages found matching linux-image

An extra validation would be nice

tonyskapunk commented 7 years ago

In the case above the main reason of the error is due to looking for the running kernel: 3.10.0-514.10.2.el7.x86_64

jkirk commented 5 years ago

On our latest Grml release, we also get a similar error and we have the following kernel and kernel-packages installed:

root@grml ~ # uname -r                  
4.19.0-1-grml-amd64
root@grml ~ # dpkg -l | grep linux-image
ii  linux-image-4.19.0-1-grml-amd64-unsigned 4.19.8-1+grml.1                     amd64        Linux 4.19 for 64-bit PCs
ii  linux-image-amd64-grml                   4.19.8-1+grml.1                     amd64        The newest Linux kernel for amd64, Grml Edition
tonyskapunk commented 5 years ago

It has been noted that the problem in the Grml is due to the way kthresher is looking for the kernel package, in which is not expecting the -unsigned addition to it.

It will take me longer to address this issue since there is another feature in the works.

Thanks.

jkirk commented 5 years ago

Right, copy/pasting our conversation: the following might help to identify the running kernel (even with an -unsigned suffix).

% dpkg -S /boot/vmlinuz-$(uname -r)
linux-image-4.19.0-1-grml-amd64-unsigned: /boot/vmlinuz-4.19.0-1-grml-amd64