10

In the interest of conserving bandwidth, I'm considering mounting a VirtualBox host's /var/cache/apt as /var/cache/apt in the guest. Both host and guest are Ubuntu 10.10 32-bit. Would there be any negative consequences to doing this?

I'm aware of the more robust solutions like apt-proxy, but I'd prefer this simpler solution if it's possible in order to spare the host the overhead of running extra services.

3 Answers 3

10

I believe that /var/cache/apt/{,src}pkgcache.bin contains the current installed packages.

Instead of sharing /var/cache/apt/, share the /var/cache/apt/archives/ directory, which contains independent files. You have to do some tweaking, because /var/cache/apt/archives is owned and writable only by root. One option would be setting the group of /var/cache/apt/archives to apt-cache-writer and adding the setgid bit to the directory. Add yourself to the apt-cache-writer group and set the umask to something like 0002 or 0007 instead of 0022.

Note that sudo apt-get clean clears this directory (/var/cache/apt/archives).

1
  • On Ubuntu 14 I tried this to find that the exclusive apt lock is based on a file in this directory! (What!? a lock file in a cache directory!) So sharing the literal file system with a VM or the like may not be a good solution. I would too recommend using a proper apt-caching service, discussed in detail here: askubuntu.com/q/3503/250556 Sep 5, 2016 at 19:06
4

Rather than share that folder, will be more "healty" create a LAN repository using APT-CACHER

here 's a tutorial about that software

1
  • A downside of this approach is that VirtualBox will consume more disk space. This should not be a problem if you have a 1TB HDD, but with small SSDs, it is.
    – Lekensteyn
    Mar 9, 2011 at 9:59
4

Your best solution is to use Apt-Cacher-NG on the host machine. You don't need to worry about dedicating a networked computer for aptcacher because it runs as a simple program with a simple instalation/configuration. The only think to watch out for is the amount of disk space you have fee but I have been using this setup for quite a while so far and it hasn't been a problem.

It may seem odd but you can also use apt-cacher for the machine that apt-cacher is installed on. This means that if your VM updates before your host it will populate the cache and the Host will be able to get the package from the cache.

You will also be able to see statistics of how much is being cached and what the hit rate is by putting the url: "http://your-apt-cacher-ng-server:3142" in your browser (see below).

A good simple explanation of how to configure the apt-cacher can be found here: http://acidborg.wordpress.com/2010/06/24/how-to-install-and-configure-apt-cacher-ng-on-ubuntu-server-10-04/ which I will paste below for completeness.

  1. Installation: apt-get install apt-cacher-ng
  2. Configuration: Edit /etc/apt-cacher-ng/acng.conf with the following content:
CacheDir: /var/cache/apt-cacher-ng
LogDir: /var/log/apt-cacher-ng
Port:3142
BindAddress: 0.0.0.0
Remap-debrep: file:deb_mirror*.gz /debian ; file:backends_debian
Remap-uburep: file:ubuntu_mirrors /ubuntu ; file:backends_ubuntu
PidFile: /var/run/apt-cacher-ng/pid
ExTreshold: 4
  1. Restart Apt-Cacher NG: /etc/init.d/apt-cacher-ng restart
  2. Create on the rest of the Debian/Ubuntu machines on the network the file /etc/apt/apt.conf.d/02proxy with the following content:

    Acquire::http { Proxy "http://your-apt-cacher-ng-server:3142"; };

1
  • Before wasting an afternoon on one particular piece of apt caching software (as I did), I recommend reading up on askubuntu.com/q/3503/250556 - I've had the least problems with squid-deb-proxy, neither apt-cacher (gross perl blob) or apt-cacaher-ng (nicer python mess with config files) worked very well for me on 14.04 LTS near the timestamp of this message. Sep 5, 2016 at 19:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .