如何解决 apt-get update 哈希值不匹配的问题

如何解决 apt-get update 哈希值不匹配的问题

当我奔跑时apt-get update我最终

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.

我已经跳了所有的祈雨舞这个问题

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

但没有运气。

首先关注第一个错误,我尝试手动提取文件并检查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

我也调查过/var/lib/apt/lists/partial并发现

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

这些.bz2文件似乎与我手动拉取的文件以及Release在那里找到的文件相同。

我可以在哪里进一步了解?我可以取出文件apt-get检查的哈希值、它得到的哈希值以及它的预期值(以及为什么它会期望该值)吗?

另请注意,我只能使用命令行来获得最终的解决方案。

答案1

我也遇到过同样的情况。

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.

首先,我编辑了 apt.conf

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

然后,http://security.ubuntu.com/ubuntu/dists/vivid-security/main/binary-amd64/Packages在命令输出中搜索apt-get update,发现了以下内容:

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)

显然,下载的Packages文件不对。于是我下载了http://security.ubuntu.com/ubuntu/dists/vivid-security/main/binary-amd64/Packages.bz2http://security.ubuntu.com/ubuntu/dists/vivid-security/main/binary-amd64/Packages.gz,解压后手动检查了hash值:

$ 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

事实证明,http://security.ubuntu.com/ubuntu/dists/vivid-security/main/binary-amd64/Packages.bz2包含错误的 Packages 文件,但http://security.ubuntu.com/ubuntu/dists/vivid-security/main/binary-amd64/Packages.gz包含正确的文件(默认情况下未下载)。

因此编辑 apt.conf:

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

对我来说很管用。祝你好运!

答案2

apt-get有可按照中所述设置的调试选项man apt.conf,这些选项可以在命令行上使用-o标志进行设置。

特别是如果想要查看实际哈希值和预期哈希值,可以使用sudo apt-get -o Debug::pkgAcquire::Auth=true update

事实证明,http://192.168.1.11/ubuntu/dists/utopic/main/binary-amd64/Packages在这种情况下比较的哈希值是不是所提及文件的哈希值。相反,它是将解包Package.bz2文件的哈希值与文件的预期哈希值进行比较Package

答案3

您是否使用了代理?如果是,请尝试以下步骤:

sudo apt update

sudo apt upgrade --fix-missing --fix-broken

当有许多待处理的更新时,我发现需要运行此序列两次才能更新所有包。

希望这可以帮助。

注意:我的系统是 Ubuntu 20.04 LTS 控制台版,运行在私有安全网络段的工业 PC 上。它只能访问公司网络中的一台机器,该机器为这台机器运行代理。

相关内容