Keeping apt archives empty…or not.

Posted by cas on Apr 26th, 2008
2008
Apr 26

In this post, Steven Hanley wonders how to keep /var/cache/apt/archives empty on a machine that has a full mirror of debian on it.

That’s actually the wrong question.

The right question is ‘Why is /var/cache/apt/archives even relevant on a machine with a full mirror of debian?’

/etc/apt/sources.list has always supported file:/ URLs. for example, sources.list on my local debian mirror looks like this:

deb file:/home/ftp/debian unstable main contrib non-free
deb file:/home/ftp/debian-multimedia/ unstable main

With a file URL, apt-get doesn’t need to download any packages, and thus doesn’t need to cache anything in /var/cache/apt/archives. No need to keep it empty, it just is empty.

In a related post, Andrew Pollock suggests adding DPkg::Post-Invoke { “apt-get clean”; }; to /etc/apt/apt.conf.

That would be fine if you ONLY ever ran “apt-get update ; apt-get dist-upgrade”.

It’s not fine if you run “apt-get -d” to download packages first, then install a few packages with “apt-get install package”, and then run “apt-get dist-upgrade”.

If you try that, then the DPKG::Post-Invoke rule will clean out /var/cache/apt/archives when you install the individual package(s). When you then run the dist-upgrade, apt-get will have to download all the packages again.

Better just to get into the habit of running apt-get clean or autoclean occasionally when you want to reclaim some disk space.

7 Responses

  1. Jack Says:

    I’m wondering same thing. But my problem is slightly different. I use apt-cacher for my local machine and my chroots, and I want to keep those /var/cache/apt/archives clean. But since there is no apt mirror, I can’t use file:// adresses in sources.list.
    Thanks

  2. cas Says:

    just run “apt-get clean” after running “apt-get upgrade”

  3. Jack Says:

    Unfortunately this is manual way. I want to clean archive after installation is done, automatically. Because sometimes builds in chroots fail because of lack of space, and apt archive contains hundreds of megabytes packages

  4. cas Says:

    So use the DPkg::Post-Invoke method that Andrew P blogged about. It’s a good solution for some circumstances, including yours.

    The price is that because it always cleans the /v/c/a/archives, it will occasionally delete something before you want it deleted so you’ll have to download it again. no big deal if it’s cached in a local apt-cacher proxy.

  5. Jack Says:

    Unfortunately DPkg::Post-Invoke { “apt-get clean”; }; gives this error:
    E: Could not get lock /var/cache/apt/archives/lock - open (11 Resource temporari ly unavailable)
    E: Unable to lock the download directory
    E: Problem executing scripts DPkg::Post-Invoke ‘apt-get clean’
    E: Sub-process returned an error code

    But DPkg::Post-Invoke { “/bin/rm var/cache/apt/archives/*.deb”; };
    does the job well.

    Thanks

  6. cas Says:

    yeah, of course. it can’t run ‘apt-get clean’ because apt is still running and has a lock on the archives.

    you could also try something like:

    DPkg::Post-Invoke { “echo apt-get clean | at now + 5 minutes”; };

    no idea if it works. just the first thing that came into my head.

  7. Jack Says:

    It may not be guaranteed to run. We can’t know if installation is done n minutes after the first package installed

Leave a Comment












XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>



Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.


Subscribe without commenting