I've created a Rubygem to help with removing old kernels that have built up over years and are eating disk space. (My laptop had 19 kernels on it alone, and on a small SSD...)
I want to use apt-get or dpkg as the uninstaller since some people will not have aptitude installed and I do not want users of the gem to have to install anything.
The problem comes when some users do use aptitude
for other things. Scenario:
- User uses my gem which successfully
apt-get purge
's the kernel packages. - User starts
aptitude
in interactive mode for any reason, - User presses the 'g' key (Download/Install/Remove Pkgs) immediately without marking any changes, -->
aptitude
re-downloads and re-installs the packages thatapt-get
had purged.
Currently, the gem uses apt-get purge <packages>
to purge the kernel packages. (Seen here.)
I also tried with dpkg --purge <packages>
, but the result is the same, aptitude still wants to reinstall them.
I've read through the entire aptitude
manual and googled many things, no dice.
Maybe I could programmatically manage aptitude
's marked/unmarked packages list if I could find where it is (although I'd prefer a cleaner solution.) I assume it's not /var/lib/dpkg/status
or else there would be no disparity?
dpkg-query shows the package status
as Not
and the desired
state as Unknown
.
deKernel$ dpkg-query -l linux-image-3.2.0-39-generic
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
+++-==========================================-==========================================-====================================================================================================
un linux-image-3.2.0-39-generic <none> (no description available)
deKernel$
It's possible to go into aptitude and manually un-mark those kernel packages and the problem disappears, however this is obviously quite impractical.
aptitude
first, then fall back toapt-get
. (Why do you need Ruby for this?)dpkg-query -l
shows thelinux-headers
package in the same states as the specific packages.dpkg-query -W *[paste kernel number]*
, then typingapt-get purge [copy and paste in each of the 3 different kernel package names]
. Now do all of that 15 more times for each other kernel you want to remove. Now do that on ~70 host machines that have been running Ubuntu for ~5 years and built up a lot of kernels. :)dpkg-query -l
does show thelinux-headers-generic
package as installed, but it's version matches my current kernel like it's supposed to.