How can I troubleshoot `apt-get update` giving Hash Sum mismatch

6,874

Solution 1

I have encountered the same situation.

W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/vivid-security/main/binary-amd64/Packages  Hash Sum mismatch

W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/vivid-security/main/binary-i386/Packages  Hash Sum mismatch

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/vivid-updates/main/binary-amd64/Packages  Hash Sum mismatch

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/vivid-updates/universe/binary-amd64/Packages  Hash Sum mismatch

W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/vivid-updates/universe/binary-i386/Packages  Hash Sum mismatch

E: Some index files failed to download. They have been ignored, or old ones used instead.

First,I edited apt.conf

Debug::Acquire::http true;
Debug::pkgAcquire::Auth true;
Debug::Hashs true;

then,searched http://security.ubuntu.com/ubuntu/dists/vivid-security/main/binary-amd64/Packages in the apt-get update command output, and found this:

Get:1 http://security.ubuntu.com vivid-security/main amd64 Packages [115 kB]
100% [1 Packages 115 kB/115 kB 100%] [Waiting for headers] [Connecting to security.ubuntu.com (91.189.91.15)]201 URI Done: http://security.ubuntu.com/ubuntu/dists/vivid-security/main/binary-amd64/Packages.bz2
RecivedHash: SHA256:0460b45fe9ace5ddb1e2080df5f75a6ee5d950fa451733991ec1b2b303bd16f6
ExpectedHash: SHA256:9daf23b84605ff833d1d280f837bd87fcbc3c7e0ca9403590985f970ee561f61

100% [1 Packages bzip2 0 B] [Waiting for headers] [Connecting to security.ubuntu.com (91.189.91.15)]201 URI Done: bzip2:/var/lib/apt/lists/partial/security.ubuntu.com_ubuntu_dists_vivid-security_main_binary-amd64_Packages.bz2
RecivedHash: SHA256:f10f6ef0486182bc9369e7912ddb9cf536c3049813ffd169b84f34dcda540ace
ExpectedHash: SHA256:9daf23b84605ff833d1d280f837bd87fcbc3c7e0ca9403590985f970ee561f61


http://security.ubuntu.com/ubuntu/dists/vivid-security/main/binary-amd64/Packages: Computed Hash: SHA256:f10f6ef0486182bc9369e7912ddb9cf536c3049813ffd169b84f34dcda540ace  Expected Hash: SHA256:9daf23b84605ff833d1d280f837bd87fcbc3c7e0ca9403590985f970ee561f61
100% [Waiting for headers] [Connecting to security.ubuntu.com (91.189.91.15)]GET /ubuntu/dists/vivid-security/multiverse/binary-amd64/Packages.bz2 HTTP/1.1
Host: security.ubuntu.com
Cache-Control: max-age=0
Range: bytes=5195-
If-Range: Mon, 28 Sep 2015 14:33:00 GMT
User-Agent: Debian APT-HTTP/1.3 (1.0.9.7ubuntu4)

Obviously,the downloaded Packages file was not right. So I downloaded http://security.ubuntu.com/ubuntu/dists/vivid-security/main/binary-amd64/Packages.bz2 and http://security.ubuntu.com/ubuntu/dists/vivid-security/main/binary-amd64/Packages.gz, unzipped them and checked hash sum manually:

$ wget http://security.ubuntu.com/ubuntu/dists/vivid-security/main/binary-amd64/Packages.bz2
$ wget http://security.ubuntu.com/ubuntu/dists/vivid-security/main/binary-amd64/Packages.gz
$ sha256sum Packages*
0460b45fe9ace5ddb1e2080df5f75a6ee5d950fa451733991ec1b2b303bd16f6  Packages.bz2
f10f6ef0486182bc9369e7912ddb9cf536c3049813ffd169b84f34dcda540ace  Packages.from.bz2
9daf23b84605ff833d1d280f837bd87fcbc3c7e0ca9403590985f970ee561f61  Packages.from.gz
b6b70b8f7838d742104904d461677652cf5120f9b8302841cb017c0c5c9dea40  Packages.gz

It turned out that http://security.ubuntu.com/ubuntu/dists/vivid-security/main/binary-amd64/Packages.bz2 contains a wrong Packages file, but the http://security.ubuntu.com/ubuntu/dists/vivid-security/main/binary-amd64/Packages.gz contains the right one which is not downloaded by default.

So edit apt.conf:

Acquire::CompressionTypes::Order:: "gz";

It worked for me. Good luck!

Solution 2

There is debug options that can be set on apt-get as described in man apt.conf, these can be set on command line by using the -o flag.

Especially if one wants to see the actual hashes and the expected hashes one could use the sudo apt-get -o Debug::pkgAcquire::Auth=true update.

As it turns out the hash that is compared for http://192.168.1.11/ubuntu/dists/utopic/main/binary-amd64/Packages in this case is not the hash of the mentioned file. Instead it's the hash of the unpacked Package.bz2 file that is compared to the expected hash for the Package file.

Share:
6,874

Related videos on Youtube

skyking
Author by

skyking

Updated on September 18, 2022

Comments

  • skyking
    skyking almost 2 years

    When I run apt-get update I get in the end

    Fetched 22.4 MB in 4s (4,659 kB/s)                      
    W: Failed to fetch http://192.168.1.11/ubuntu/dists/utopic/main/binary-amd64/Packages  Hash Sum mismatch
    
    W: Failed to fetch http://192.168.1.11/ubuntu/dists/utopic-updates/main/binary-amd64/Packages  Hash Sum mismatch
    
    E: Some index files failed to download. They have been ignored, or old ones used instead.
    

    I've done all rain dancing from this question:

    sudo rm -rf /var/lib/apt/lists
    sudo apt-get clean
    sudo apt-get update
    

    but no luck.

    Focusing on the first error first I tried to pull the files manually and check the sha256:

    > wget http://192.168.1.11/ubuntu/dists/utopic/main/binary-amd64/Packages
    > wget http://192.168.1.11/ubuntu/dists/utopic/main/binary-amd64/Packages.gz
    > wget http://192.168.1.11/ubuntu/dists/utopic/main/binary-amd64 /Packages.bz2
    > wget http://192.168.1.11/ubuntu/dists/utopic/Release
    > sha256sum Package*
    31f1f45c6873c3df36e5aeeee360ed02378f8c4c3c8c9a35e9adeaaf1cb0cf27  Packages
    9650775abec90a24c26dbb03f91a488180309144338f64f7044f7119d60d7182  Packages.bz2
    228df8d823f966152f19bb460c02f3237854000d551d9247bf35eed8088c2d3d  Packages.gz
    
    > grep main/binary-amd64/Package
    6a571ce0ef1d641ddc70536d6d5f549e07a89c93          8116687 main/binary-amd64/Packages
    7144392ea4463fb14ac32f2571001075c072e181          1708299 main/binary-amd64/Packages.gz
    3e69d6803d7ec76cd7fc28675078b7307d1f68a1          1330583 main/binary-amd64/Packages.bz2
    31f1f45c6873c3df36e5aeeee360ed02378f8c4c3c8c9a35e9adeaaf1cb0cf27          8116687 main/binary-amd64/Packages
    228df8d823f966152f19bb460c02f3237854000d551d9247bf35eed8088c2d3d          1708299 main/binary-amd64/Packages.gz
    9650775abec90a24c26dbb03f91a488180309144338f64f7044f7119d60d7182          1330583 main/binary-amd64/Packages.bz2
    c39f5e994e08eda7ada6744c4e830611          8116687 main/binary-amd64/Packages
    8a0c176a456a83fa4f327ea0e8f897d6          1708299 main/binary-amd64/Packages.gz
    8160d18474db0b9e36af68aacb62605b          1330583 main/binary-amd64/Packages.bz2
    

    I've also looked into /var/lib/apt/lists/partial and found

    192.168.1.11_ubuntu_dists_utopic_main_binary-amd64_Packages.bz2                  192.168.1.11_ubuntu_dists_utopic-updates_main_binary-amd64_Packages.bz2
    192.168.1.11_ubuntu_dists_utopic_main_binary-amd64_Packages.bz2.decomp.FAILED    192.168.1.11_ubuntu_dists_utopic-updates_main_binary-amd64_Packages.bz2.decomp.FAILED
    

    The .bz2 files seem to be tha same as I pulled manually and also the Release file found there.

    Where can I go further? Can I get out the file apt-get checks for hash sum, which hash sum it got and what it expected (and why it would expect that value)?

    Also note that I'm restricted to use command line for the final solution.

    • skyking
      skyking almost 9 years
      I have similar problem with vivid...
    • steeldriver
      steeldriver almost 9 years
      It looks like you are trying to use a mirror or proxy on your LAN (192.168.1.11 is in a private address range) - perhaps it is that that is misconfigured or out-of-date?
    • skyking
      skyking almost 9 years
      As pointed out it looks like the received Package files are OK (the hashes fx seem to match those of the Release file - which is what apt-get explains about), if you have an idea how to prove otherwise you're welcome.
  • L.H
    L.H over 8 years
    I have updated the answer.