9

I have a machine who is using Apt-Cacher NG running on another machine as caching proxy.

When I try to run sudo apt-get update I get the following errors:

W: Failed to fetch gzip:/var/lib/apt/lists/partial/it.archive.ubuntu.com_ubuntu_dists_oneiric-updates_main_source_Sources  Hash Sum mismatch
W: Failed to fetch gzip:/var/lib/apt/lists/partial/it.archive.ubuntu.com_ubuntu_dists_oneiric-updates_main_binary-amd64_Packages  Hash Sum mismatch
W: Failed to fetch gzip:/var/lib/apt/lists/partial/it.archive.ubuntu.com_ubuntu_dists_oneiric-updates_universe_binary-amd64_Packages  Hash Sum mismatch
W: Failed to fetch gzip:/var/lib/apt/lists/partial/it.archive.ubuntu.com_ubuntu_dists_oneiric-updates_main_binary-i386_Packages  Hash Sum mismatch
E: Some index files failed to download. They have been ignored, or old ones used instead.

The directory /etc/apt/sources.list.d is empty.

To fix that I have already tried the following with no success:

Solution 1:

sudo rm -fr /var/lib/apt/lists
sudo mkdir -p /var/lib/apt/lists/partial
sudo apt-get clean
sudo apt-get autoclean

Solution 2:

sudo apt-get update -o Acquire::http::No-Cache=True

Any suggestion?

2
  • I have seen this behaviour sometimes. Running sudo apt-get update several times consecutively helped in this case but I don't know why, never investigated this issue more closely.
    – oddfellow
    Apr 6, 2012 at 10:10
  • 1
    This happens also on machines which don't use Apt-Cacher NG. In those cases Solution 1 fixes the problem. Apr 19, 2012 at 11:57

8 Answers 8

12

I would suggest to switch away from APT-cacher-ng and check out Squid-deb-proxy.

APT-cacher-ng has proven to be very buggy in my experience and tons of bug reports are outstanding. Only recently it has been proposed again to get unblocked in Debian now that some major bugs are squashed. For Ubuntu I've switched to Squid-deb-proxy a long time ago and I don't regret it. It's a great alternative and the best APT-cacher I've come around.

For Squid-deb-proxy, just install the package squid-deb-proxy and add allowed destination domains in a new file in /etc/squid-deb-proxy/mirror-dstdomain.acl.d. As a bonus, clients can auto-discover caching-enabled machines in the local network by having the squid-deb-proxy-client package installed.

10

You can fix this right now by running:

http://your-cache-server:3142/acng-report.html?abortOnErrors=aOe&byPath=bP&byChecksum=bS&truncNow=tN&incomAsDamaged=iad&purgeNow=pN&doExpire=Start+Scan+and%2For+Expiration&calcSize=cs&asNeeded=an#bottom

This will delete all the broken files in your cache.

To make this permananet, have a look at https://www.unix-ag.uni-kl.de/~bloch/acng/html/maint.html#auto-cleanup

Basically, you can set up the daily cache cleanup cron to do a full checksum match on your entire cache. This will catch all the bad sizes and any other corruption and clean out those files. I edited /etc/cron.daily/apt-cacher-ng and added the following after the comments:

export ACNGREQ="abortOnErrors=aOe&byPath=bP&byChecksum=bS&truncNow=tN&incomAsDamaged=iad&purgeNow=pN&doExpire=Start+Scan+and%2For+Expiration&calcSize=cs&asNeeded=an"

This is equivalent to clicking all the expiry options on the maintenance page except "Skip header checks..."

2
  • 1
    This was the only answer that got rid of the error on my systems!
    – Jan
    Apr 22, 2015 at 19:48
  • I think you may need a ? at the start of your export string.
    – TafT
    Oct 26, 2016 at 7:44
3

Suggestion 1

sudo rm /var/lib/apt/lists/*gzip*
sudo rm /var/lib/apt/lists/partial/*gzip*
sudo apt-get update

Suggestion 2

sudo rm -f /var/cache/apt/partial/*
sudo rm -f /var/cache/apt/*.deb
sudo apt-get update

Suggestion 3

sudo touch /etc/apt/apt.conf.d/no-cache
sudo nano /etc/apt/apt.conf.d/no-cache

And paste this in:

Acquire::http {No-Cache=True;};

Now try:

sudo apt-get update
2
  • 1
    Thanks but none of the three worked. Apr 24, 2012 at 16:02
  • Worked like a charm setting no-cache to true! Thanks a million! :)
    – mhenrixon
    May 15, 2014 at 11:13
3

I have been fighting VERY frequently (1 in 50 downloads) with "Hash Sum Mismatch" and "Invalid Header" errors using apt-cacher-ng on Ubuntu Precise 12.04 LTS since the day of upgrading the distro. Ubuntu Precise uses apt-cacher-ng version 0.7.2-1, to date there are MANY bug fixes to this software, and the newer version: 0.7.26-1 is much more stable.

I have installed the Ubuntu Quantal version of apt-cacher-ng from packages.ubuntu.com, which is version 0.7.26-1.

I highly recommend grabbing the future/testing version of apt-cacher-ng, and manually installing this newer package.

1

My upgrades would always almost succeed -- 95% of the files would download through the proxy, leaving maybe the last ~100 files failing with 'hash sum mismatch', and none of the proposed solutions would ever work.

And then, just for grins-and-giggles, I moved 01proxy over to 01proxy.ng, ran aptitude update, then update-manager and selected the distribution-upgrade. It proceeded to download the remaining files from archive.ubuntu.com (~70M rather than ~1G), and the rest of the upgrade went smoothly. After rebooting, I moved 01proxy.ng back to 01proxy, and everything was back to normal.

I've done this twice now, once on the proxy server itself and once on a client, and both succeeded just beautifully after failing (at that 95% mark) when going through the proxy.

1

Removing the /var/cache/apt-cacher-ng/download.virtualbox.org folder did help me to fix the problem with Failed to fetch ... Hash Sum mismatch on apt-get update that prevented virtualbox-4.3 package from Oracle server.

0

Suggestion 4

Running sudo apt-get update && sudo apt-get upgrade -y on the Apt-Cacher NG server may fix the problem. You need to do that every time the problem occurs.

Suggestion 5

Sometimes the problem is on the mirror: changing the mirror in /etc/apt/sources.list, both on the server and the clients, may fix this problem.

0

You can also remove the whole repository folder

rm -r /var/cache/apt-cacher-ng/<repository_folder>

where the package with the hash sum mismatch is stored.

On next apt request a new folder with clean hash sum will by automaticaly created by apt-cacher-ng.

You must log in to answer this question.

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